user = ums.getUser("test");
Subject subject = user.getSubject();
assertNotNull("subject is null", subject);
Collection principals = getPrincipals(subject, RolePrincipal.class);
assertEquals("should have 3 principals;", 3, principals.size());
assertTrue("should contain rootrole", principals.contains(new RolePrincipalImpl("rootrole")));
assertTrue("should contain rootrole.childrole1", principals.contains(new RolePrincipalImpl(
"rootrole.childrole1")));
assertTrue("should contain rootrole.childrole2", principals.contains(new RolePrincipalImpl(
"rootrole.childrole2")));
rms.removeRoleFromUser("test", "rootrole");
user = ums.getUser("test");
principals = getPrincipals(user.getSubject(), RolePrincipal.class);
assertEquals("should not have any principals;", 0, principals.size());
}
catch (SecurityException sex)
{
assertTrue("test with parent role " + sex.getMessage(), false);
}
try
{
rms.addRoleToUser("test", "rootrole.childrole1");
user = ums.getUser("test");
Subject subject = user.getSubject();
assertNotNull("subject is null", subject);
Collection principals = getPrincipals(subject, RolePrincipal.class);
assertEquals("shoud have 1 principal;", 1, principals.size());
assertTrue("should contain rootrole.childrole1", principals.contains(new RolePrincipalImpl(
"rootrole.childrole1")));
rms.removeRoleFromUser("test", "rootrole.childrole1");
user = ums.getUser("test");