// using the authorization manager, check if the identities have the expected permissions.
JBossAuthorizationManager jam = new JBossAuthorizationManager("test-acl");
// check that Administrator has all permissions on both resources.
Identity identity = IdentityFactory.createIdentity("Administrator");
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource1, identity, new CompositeACLPermission(
BasicACLPermission.values())));
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, new CompositeACLPermission(
BasicACLPermission.values())));
// check that Guest has only READ permission on resource1.
identity = IdentityFactory.createIdentity("Guest");
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource1, identity, BasicACLPermission.READ));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource1, identity, BasicACLPermission.CREATE));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource1, identity, BasicACLPermission.UPDATE));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource1, identity, BasicACLPermission.DELETE));
// check that Guest has READ and UPDATE permissions on resource2.
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, BasicACLPermission.READ));
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, BasicACLPermission.UPDATE));
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, new CompositeACLPermission(
BasicACLPermission.READ, BasicACLPermission.UPDATE)));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource2, identity, BasicACLPermission.CREATE));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource2, identity, BasicACLPermission.DELETE));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource2, identity, new CompositeACLPermission(
BasicACLPermission.values())));
// check that Regular_User doesn't have any permissions on resource1.
identity = IdentityFactory.createIdentity("Regular_User");
for(BasicACLPermission permission : BasicACLPermission.values())
assertEquals(AuthorizationContext.DENY, jam.authorize(resource1, identity, permission));
// check that Regular_User has READ and UPDATE permissions on resource2.
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, BasicACLPermission.READ));
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, BasicACLPermission.UPDATE));
assertEquals(AuthorizationContext.PERMIT, jam.authorize(resource2, identity, new CompositeACLPermission(
BasicACLPermission.READ, BasicACLPermission.UPDATE)));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource2, identity, BasicACLPermission.CREATE));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource2, identity, BasicACLPermission.DELETE));
assertEquals(AuthorizationContext.DENY, jam.authorize(resource2, identity, new CompositeACLPermission(
BasicACLPermission.values())));
}