BundleContext bc = mockConfigAdminBundleContext(c1);
final Object proxy = testCreateProxy(bc, new Class [] {TestServiceAPI.class}, new TestService());
Subject s1 = new Subject();
s1.getPrincipals().add(new RolePrincipal("role1"));
Subject.doAs(s1, new PrivilegedAction<Object>() {
@Override
public Object run() {
try {
((TestServiceAPI) proxy).doit();
fail("Should have prevented this invocation as the custom role is required");
} catch (SecurityException se) {
// good
}
return null;
}
});
Subject s2 = new Subject();
s2.getPrincipals().add(new MyRolePrincipal());
Subject.doAs(s2, new PrivilegedAction<Object>() {
@Override
public Object run() {
((TestServiceAPI) proxy).doit(); // Should work, the custom role is there
return null;
}
});
Subject s3 = new Subject();
s3.getPrincipals().add(new MyRolePrincipal());
s3.getPrincipals().add(new RolePrincipal("role1"));
Subject.doAs(s3, new PrivilegedAction<Object>() {
@Override
public Object run() {
((TestServiceAPI) proxy).doit(); // Should work, the custom role is there
return null;