//wrong users - must pass because we don't know the external users.
admin.updateUserListOfRole("role2", null, new String[] { "d" });
}
public void doAuthorizationStuff() throws Exception {
AuthorizationManager authMan = realm.getAuthorizationManager();
UserStoreManager usWriter = realm.getUserStoreManager();
usWriter.addRole("rolex", new String[] { "saman", "amara" }, null);
usWriter.addRole("roley", null, null);
authMan.authorizeRole("rolex", "wall", "write");
authMan.authorizeRole("roley", "table", "write");
try {
authMan.authorizeRole(null, "wall", "write");
fail("Exception at authorizing a role with Null role");
} catch (Exception e) {
// caught exception
}
try {
authMan.authorizeRole("rollee", null, "write");
fail("Exception at authorizing a role with Null resourceID");
} catch (Exception e) {
// caught exception
}
try {
authMan.authorizeRole("rollee","wall",null);
fail("Exception at authorizing a role with Null action");
} catch (Exception e) {
// caught exception
}
try {
authMan.authorizeRole("rolleex","wall","run");
fail("Exception at authorizing a role with Invalid action");
} catch (Exception e) {
// caught exception
}
authMan.authorizeUser("sunil", "wall", "read");
try {
authMan.authorizeUser(null, "wall", "read");
fail("Exception at authorizing a user with Null name");
} catch (Exception e) {
//caught exception
}
try {
authMan.authorizeUser("isuru", null, "read");
fail("Exception at authorizing a user with Null resourceID");
} catch (Exception e) {
//caught exception
}
try {
authMan.authorizeUser("isuru","wall",null);
fail("Exception at authorizing a user with Null action");
} catch (Exception e) {
//caught exception
}
try {
authMan.authorizeUser("isuru","wall","run");
fail("Exception at authorizing a user with Invalid action");
} catch (Exception e) {
//caught exception
}
assertTrue(authMan.isUserAuthorized("saman", "wall", "write"));
assertTrue(authMan.isUserAuthorized("sunil", "wall", "read"));
assertTrue(authMan.isRoleAuthorized("roley", "table", "write"));
assertFalse(authMan.isRoleAuthorized("roley", "chair", "write"));
assertFalse(authMan.isUserAuthorized("saman", "wall", "read"));
assertFalse(authMan.isUserAuthorized("sunil", "wall", "write"));
assertFalse(authMan.isUserAuthorized("isuru", "wall", "write"));
try {
boolean b=authMan.isUserAuthorized("isuru", "wall", "run");
fail("Exception at check authorization of a user with Invalid action");
} catch (Exception e) {
//caught exception
}
authMan.clearUserAuthorization("sunil", "wall", "read");
try{
authMan.clearUserAuthorization("isuru", "wall", "run");
fail("Exception at clear user authorization");
}catch(Exception e){
}
try{
authMan.clearUserAuthorization(null, "wall", "read");
fail("Exception at clear user authorization");
}catch(Exception e){
}
try{
authMan.clearUserAuthorization("isuru", null, "read");
fail("Exception at clear user authorization");
}catch(Exception e){
}
try{
authMan.clearUserAuthorization("isuru","wall", null);
fail("Exception at clear user authorization");
}catch(Exception e){
}
authMan.clearRoleAuthorization("roley", "table", "write");
try{
authMan.clearRoleAuthorization(null, "table", "write");
fail("Exception at clear role authorization");
}catch(Exception e){
//caught exception
}
try{
authMan.clearRoleAuthorization("roleee", null, "write");
fail("Exception at clear role authorization");
}catch(Exception e){
//caught exception
}
try{
authMan.clearRoleAuthorization("roleee", "table", null);
fail("Exception at clear role authorization");
}catch(Exception e){
//caught exception
}
//authMan.isRoleAuthorized("roley", "table", "write");
authMan.clearResourceAuthorizations("wall");
try{
authMan.clearResourceAuthorizations(null);
fail("Exception at clear Resource Authorizations");
}catch(Exception e){
}
assertFalse(authMan.isUserAuthorized("saman", "wall", "write"));
assertFalse(authMan.isUserAuthorized("sunil", "wall", "read"));
assertFalse(authMan.isRoleAuthorized("roley", "table", "write"));
}