SecurityService ss = TurbineSecurity.getService();
Role admin = ss.getRoleByName("Admin");
assertNotNull(admin);
Permission app = ss.getPermissionByName("Application");
assertNotNull(app);
PermissionSet ps = admin.getPermissions();
assertFalse(ps.contains(app));
ss.grant(admin, app);
Role admin2 = ss.getRoleByName("Admin");
assertNotNull(admin2);
PermissionSet ps2 = admin2.getPermissions();
assertTrue(ps2.contains(app));
// Get existing PermissionSet modified?
assertFalse(ps.contains(app));
try
{
ss.grant(admin2, app);
fail("Permission could be granted twice!");
}
catch (Exception e)
{
//
// Ugh. DataBackendError? This means that our query actually hit the database and only the "unique key"
// prevented us from a double entry. This seems to be a bug
//
assertEquals("Wrong Exception thrown: " + e.getClass().getName(), DataBackendException.class, e.getClass());
}
try
{
Permission unknown = ss.getPermissionInstance("unknown");
ss.grant(admin, unknown);
fail("Nonexisting Permission could be granted!");
}
catch (Exception e)