+ "NullPointerException was expected.");
} catch (NullPointerException npe) {
// PASS
logger.fine("NullPointerException was thrown as expected.");
}
final TestPrivilegedAction pa = new TestPrivilegedAction(perm);
obj = callDoPrivileged(pa);
if (pa.getCombiner() != null) {
// FAIL
throw new TestException(
"DomainCombiner inside 'doPrivileged' method of "
+ pa + " was " + pa.getCombiner()
+ " while null was expected.");
}
// PASS
logger.fine("DomainCombiner inside 'doPrivileged' method of "
+ pa + " was null as expected.");
if (!pa.isGrantedPerm()) {
// FAIL
throw new TestException(
"Privileges are not enabled inside 'doPrivileged' "
+ "method.");
}
// PASS
logger.fine("Privileges are enabled inside 'doPrivileged' "
+ "method as expected.");
if (pa.getObject() != obj) {
// FAIL
throw new TestException(
"'doPrivileged' method returned " + obj + " while "
+ pa.getObject() + " was expected.");
}
// PASS
logger.fine("'doPrivileged' method returned " + obj
+ " as expected.");
final TestPrivilegedAction pa1 = new TestPrivilegedAction(perm1);
Subject subj = new Subject();
Principal prin = new FakePrincipal("DoPrivilegedTest");
subj.getPrincipals().add(prin);
SubjectDomainCombiner comb = new SubjectDomainCombiner(subj);
AccessControlContext acc = new AccessControlContext(
AccessController.getContext(), comb);
obj = AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return callDoPrivileged(pa1);
}
}, acc);
if (pa1.getCombiner() != comb) {
// FAIL
throw new TestException(
"DomainCombiner inside 'doPrivileged' method of "
+ pa1 + " was " + pa1.getCombiner()
+ " while " + comb + " was expected.");
}
// PASS
logger.fine("DomainCombiner inside 'doPrivileged' method of "
+ pa1 + " was " + comb + " as expected.");
if (!pa1.isGrantedPerm()) {
// FAIL
throw new TestException(
"Privileges are not enabled inside 'doPrivileged' "
+ "method.");
}
// PASS
logger.fine("Privileges are enabled inside 'doPrivileged' "
+ "method as expected.");
if (pa1.getObject() != obj) {
// FAIL
throw new TestException(
"'doPrivileged' method returned " + obj + " while "
+ pa1.getObject() + " was expected.");
}
// PASS
logger.fine("'doPrivileged' method returned " + obj
+ " as expected.");