throws Exception
{
// delete the security conf first, start clean
new File(SECURITY_CONFIG_FILE_PATH).delete();
SecuritySystem securitySystem = this.lookup(SecuritySystem.class);
Map<String, String> properties = new HashMap<String, String>();
properties.put(ApplicationPrivilegeMethodPropertyDescriptor.ID, "read");
properties.put(ApplicationPrivilegePermissionPropertyDescriptor.ID, "permissionOne");
securitySystem.getAuthorizationManager("default").addPrivilege(new Privilege(
"randomId",
"permissionOne",
"permissionOne",
ApplicationPrivilegeDescriptor.TYPE,
properties, false));
securitySystem.getAuthorizationManager("default").addRole(new Role("mockrole1", "mockrole1", "mockrole1",
"default", false, null,
Collections.singleton("randomId")));
// add MockRealm to config
List<String> realms = new ArrayList<String>();
realms.add("Mock");
realms.add(XmlAuthorizingRealm.ROLE);
securitySystem.setRealms(realms);
// jcohen has the role mockrole1, there is also xml role with the same ID, which means jcohen automaticly has
// this xml role
PrincipalCollection jcohen = new SimplePrincipalCollection("jcohen", MockRealm.NAME);
try {
securitySystem.checkPermission(jcohen, "permissionOne:invalid");
Assert.fail("Expected AuthorizationException");
}
catch (AuthorizationException e) {
// expected
}
securitySystem.checkPermission(jcohen, "permissionOne:read"); // throws on error, so this is all we need to do
}