use of java.security.DomainCombiner in project jdk8u_jdk by JetBrains.
the class PreserveCombinerTest method main.
public static void main(String[] args) throws Exception {
final DomainCombiner dc = new DomainCombiner() {
@Override
public ProtectionDomain[] combine(ProtectionDomain[] currentDomains, ProtectionDomain[] assignedDomains) {
// basically a no-op
return currentDomains;
}
};
// Get an instance of the saved ACC
AccessControlContext saved = AccessController.getContext();
// Simulate the stack ACC with a DomainCombiner attached
AccessControlContext stack = new AccessControlContext(AccessController.getContext(), dc);
// Now try to run JavaSecurityAccess.doIntersectionPrivilege() and assert
// whether the DomainCombiner from the stack ACC is preserved
boolean ret = SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return dc == AccessController.getContext().getDomainCombiner();
}
}, stack, saved);
if (!ret) {
System.exit(1);
}
}
use of java.security.DomainCombiner in project robovm by robovm.
the class AccessControllerTest method testDoPrivilegedWithCombiner.
public void testDoPrivilegedWithCombiner() {
final Permission permission = new RuntimePermission("do stuff");
final DomainCombiner union = new DomainCombiner() {
public ProtectionDomain[] combine(ProtectionDomain[] a, ProtectionDomain[] b) {
throw new AssertionFailedError("Expected combiner to be unused");
}
};
ProtectionDomain protectionDomain = new ProtectionDomain(null, new Permissions());
AccessControlContext accessControlContext = new AccessControlContext(new AccessControlContext(new ProtectionDomain[] { protectionDomain }), union);
final AtomicInteger actionCount = new AtomicInteger();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
assertEquals(null, AccessController.getContext().getDomainCombiner());
AccessController.getContext().checkPermission(permission);
// Calling doPrivileged again would have exercised the combiner
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
actionCount.incrementAndGet();
assertEquals(null, AccessController.getContext().getDomainCombiner());
AccessController.getContext().checkPermission(permission);
return null;
}
});
return null;
}
}, accessControlContext);
assertEquals(1, actionCount.get());
}
use of java.security.DomainCombiner in project openj9 by eclipse.
the class Test_AccessController method test_doPrivilegedWithCombiner2.
/**
* java.security.AccessController#doPrivilegedWithCombiner(java.security
* .PrivilegedExceptionAction)
*/
@Test
public void test_doPrivilegedWithCombiner2() {
class MyDomainCombiner implements DomainCombiner {
public ProtectionDomain[] combine(ProtectionDomain[] executionDomains, ProtectionDomain[] parentDomains) {
Permissions perms = new Permissions();
perms.add(new RuntimePermission("checking"));
return new ProtectionDomain[] { new ProtectionDomain(null, perms) };
}
}
AccessControlContext acc1 = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });
AccessControlContext acc = new AccessControlContext(acc1, new MyDomainCombiner());
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
AccessController.doPrivilegedWithCombiner(new PrivilegedExceptionAction() {
public Object run() {
AccessController.checkPermission(new RuntimePermission("checking"));
return null;
}
});
} catch (PrivilegedActionException e) {
Assert.fail("Unexpected1: " + e);
}
try {
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() {
AccessController.checkPermission(new RuntimePermission("checking"));
return null;
}
});
Assert.fail("Expected SecurityException");
} catch (SecurityException e) {
// expected
} catch (PrivilegedActionException e) {
Assert.fail("Unexpected2: " + e);
}
return null;
}
}, acc);
}
use of java.security.DomainCombiner in project AsmackService by rtreffer.
the class Subject method getSubject.
/**
* Returns the {@code Subject} that was last associated with the {@code
* context} provided as argument.
*
* @param context
* the {@code context} that was associated with the
* {@code Subject}.
* @return the {@code Subject} that was last associated with the {@code
* context} provided as argument.
*/
public static Subject getSubject(final AccessControlContext context) {
checkPermission(_SUBJECT);
if (context == null) {
// $NON-NLS-1$
throw new NullPointerException("auth.09");
}
PrivilegedAction<DomainCombiner> action = new PrivilegedAction<DomainCombiner>() {
public DomainCombiner run() {
return context.getDomainCombiner();
}
};
DomainCombiner combiner = AccessController.doPrivileged(action);
if ((combiner == null) || !(combiner instanceof SubjectDomainCombiner)) {
return null;
}
return ((SubjectDomainCombiner) combiner).getSubject();
}
use of java.security.DomainCombiner in project robovm by robovm.
the class Subject method getSubject.
/**
* Returns the {@code Subject} that was last associated with the {@code
* context} provided as argument.
*
* @param context
* the {@code context} that was associated with the
* {@code Subject}.
* @return the {@code Subject} that was last associated with the {@code
* context} provided as argument.
*/
public static Subject getSubject(final AccessControlContext context) {
if (context == null) {
throw new NullPointerException("context == null");
}
PrivilegedAction<DomainCombiner> action = new PrivilegedAction<DomainCombiner>() {
public DomainCombiner run() {
return context.getDomainCombiner();
}
};
DomainCombiner combiner = AccessController.doPrivileged(action);
if ((combiner == null) || !(combiner instanceof SubjectDomainCombiner)) {
return null;
}
return ((SubjectDomainCombiner) combiner).getSubject();
}
Aggregations