...
| Code Block | ||
|---|---|---|
| ||
package trusted;
import untrusted.RetValue;
public class MixMatch {
private void privilegedMethod() throws IOException {
FileInputStreamtry fis;{
try {
final FileInputStream fis = (FileInputStream) AccessController.doPrivileged(
new PrivilegedExceptionActionPrivilegedExceptionAction<FileInputStream>() {
public FileInputStream run() throws FileNotFoundException {
return new FileInputStream("file.txt");
}
}
);
try {
RetValue rt = new RetValue();
if(rt.getValue() == 1) {
// do something with sensitive file
}
} catch (PrivilegedActionException} e)finally {
// forward to handler and log fis.close();
}
} finally catch (PrivilegedActionException e) {
// forward to handler fis.close();and log
}
}
public static void main(String[] args) throws IOException {
MixMatch mm = new MixMatch();
mm.privilegedMethod();
}
}
package untrusted;
class RetValue {
public int getValue() {
return 1;
}
}
|
...