* p | subject -- role -- group -- resource
*/
try {
/* bootstrap */
Subject testSubject = SessionTestHelper.createNewSubject(em, "testSubject");
Role testRole1 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole1");
ResourceGroup testGroup1 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup1", false);
Resource resource1 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource1");
Resource resource2 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource2");
Resource resource3 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource3");
/* setup permissions */
Set<Permission> allPermissions = EnumSet.allOf(Permission.class);
testRole1.getPermissions().addAll(allPermissions);
em.merge(testRole1);
em.flush();
/* verify getResourcePermissions test */
Set<Permission> allPermissionsResults = authorizationManager.getExplicitResourcePermissions(testSubject,
resource1.getId());
assert SessionTestHelper.samePermissions(allPermissions, allPermissionsResults) : "Failed to get all 1-role, 1-group, 1-resource permissions";
/* verify hasResourcePermission test */
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, resource1.getId())) : "Failed to get single 1-role, 1-group, 1-resource permission";
}
/* verify hasResourcePermission(collection) test */
Collection<Integer> allResources = SessionTestHelper.getResourceList(resource1, resource2, resource3);
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, allResources)) : "Failed to get every positive 1-role, 1-group, resource-list permission";
}
} finally {
getTransactionManager().rollback();
}
/*
* p | subject -- role -- group -- resource \ / \- role -/
* | p without redundant permissions
*/
getTransactionManager().begin();
em = getEntityManager();
try {
/* bootstrap */
Subject testSubject = SessionTestHelper.createNewSubject(em, "testSubject");
Role testRole1 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole1");
ResourceGroup testGroup1 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup1", false);
Resource resource1 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource1");
Resource resource2 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource2");
Resource resource3 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource3");
Role testRole2 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole2");
testRole2.getResourceGroups().add(testGroup1);
testGroup1.addRole(testRole2);
em.merge(testRole2);
em.merge(testGroup1);
em.flush();
/* setup permissions */
Set<Permission> somePermissions = EnumSet.of(Permission.CONFIGURE_WRITE);
Set<Permission> otherPermissions = EnumSet.of(Permission.CONTROL);
testRole1.getPermissions().addAll(somePermissions);
testRole2.getPermissions().addAll(otherPermissions);
em.merge(testRole1);
em.merge(testRole2);
em.flush();
/* setup shared object for result testing */
Set<Permission> allPermissions = EnumSet.noneOf(Permission.class);
allPermissions.addAll(somePermissions);
allPermissions.addAll(otherPermissions);
/* verify getResourcePermissions test */
Set<Permission> allPermissionsResults = authorizationManager.getExplicitResourcePermissions(testSubject,
resource1.getId());
assert SessionTestHelper.samePermissions(allPermissions, allPermissionsResults) : "Failed to get all 2-role, 1-group, 1-resource permissions";
/* verify hasResourcePermission test */
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, resource1.getId())) : "Failed to get single 2-role, 1-group, 1-resource permission";
}
/* verify hasResourcePermission(collection) test */
Collection<Integer> allResources = SessionTestHelper.getResourceList(resource1, resource2, resource3);
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, allResources)) : "Failed to get every positive 2-role, 1-group, resource-list permission";
}
} finally {
getTransactionManager().rollback();
}
/*
* p | subject -- role -- group -- resource \ / \- role --
* group -/ | p without redundant permissions
*/
getTransactionManager().begin();
em = getEntityManager();
try {
/* bootstrap */
Subject testSubject = SessionTestHelper.createNewSubject(em, "testSubject");
Role testRole1 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole1");
ResourceGroup testGroup1 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup1", false);
Resource resource1 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource1");
Resource resource2 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource2");
Resource resource3 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource3");
Role testRole2 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole2");
ResourceGroup testGroup2 = SessionTestHelper.createNewMixedGroupForRole(em, testRole2, "testGroup2", false);
testGroup2.addExplicitResource(resource1);
resource1.getExplicitGroups().add(testGroup2);
/*
* Single resource implies the implicit resource list should mirror the explicit one
*/
testGroup2.addImplicitResource(resource1);
resource1.getImplicitGroups().add(testGroup2);
em.merge(testGroup2);
em.merge(resource1);
em.flush();
/* setup permissions */
Set<Permission> sharedPermissions = EnumSet.of(Permission.MANAGE_CONTENT);
Set<Permission> otherPermissions = EnumSet.of(Permission.MANAGE_SECURITY);
testRole1.getPermissions().addAll(sharedPermissions);
testRole2.getPermissions().addAll(otherPermissions);
em.merge(testRole1);
em.merge(testRole2);
em.flush();
/* setup shared object for result testing */
Set<Permission> allPermissions = EnumSet.noneOf(Permission.class);
allPermissions.addAll(sharedPermissions);
allPermissions.addAll(otherPermissions);
/* verify getResourcePermissions test */
Set<Permission> allPermissionsResults = authorizationManager.getExplicitResourcePermissions(testSubject,
resource1.getId());
assert SessionTestHelper.samePermissions(allPermissions, allPermissionsResults) : "Failed to get all 2-role, 2-group, 1-resource permissions";
/* verify hasResourcePermission test */
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, resource1.getId())) : "Failed to get single 2-role, 2-group, 1-resource permission";
}
/* verify hasResourcePermission(collection) test */
Collection<Integer> allResources = SessionTestHelper.getResourceList(resource1, resource2, resource3);
for (Permission permission : sharedPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, allResources)) : "Failed to get every positive 2-role, 2-group, resource-list permission";
}
for (Permission permission : otherPermissions) {
assert (!authorizationManager.hasResourcePermission(testSubject, permission, allResources)) : "Failed to get every negative 2-role, 2-group, resource-list permission";
}
} finally {
getTransactionManager().rollback();
}
/*
* p | subject -- role -- group -- resource \ / \-
* group -/
*/
getTransactionManager().begin();
em = getEntityManager();
try {
/* bootstrap */
Subject testSubject = SessionTestHelper.createNewSubject(em, "testSubject");
Role testRole1 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole1");
ResourceGroup testGroup1 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup1", false);
Resource resource1 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource1");
Resource resource2 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource2");
Resource resource3 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource3");
ResourceGroup testGroup2 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup2", false);
testGroup2.addExplicitResource(resource1);
resource1.getExplicitGroups().add(testGroup2);
/*
* Single resource implies the implicit resource list should mirror the explicit one
*/
testGroup2.addImplicitResource(resource1);
resource1.getImplicitGroups().add(testGroup2);
em.merge(testGroup2);
em.merge(resource1);
em.flush();
/* setup permissions */
Set<Permission> sharedPermissions = EnumSet.of(Permission.MANAGE_SETTINGS, Permission.MANAGE_ALERTS);
testRole1.getPermissions().addAll(sharedPermissions);
em.merge(testRole1);
em.flush();
/* verify getResourcePermissions test */
Set<Permission> somePermissionsResults = authorizationManager.getExplicitResourcePermissions(testSubject,
resource1.getId());
assert SessionTestHelper.samePermissions(sharedPermissions, somePermissionsResults) : "Failed to get all 1-role, 2-group, 1-resource permissions";
/* verify hasResourcePermission test */
for (Permission permission : sharedPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, resource1.getId())) : "Failed to get single 1-role, 2-group, 1-resource permission";
}
/* verify hasResourcePermission(collection) test */
Collection<Integer> allResources = SessionTestHelper.getResourceList(resource1, resource2, resource3);
for (Permission permission : sharedPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, allResources)) : "Failed to get every positive 1-role, 2-group, resource-list permission";
}
} finally {
getTransactionManager().rollback();
}
/*
* p | subject -- role -- group -- resource \ \/ / \ /\
* / \ role -- group / | p with highly redundant permissions
*/
getTransactionManager().begin();
em = getEntityManager();
try {
/* bootstrap */
Subject testSubject = SessionTestHelper.createNewSubject(em, "testSubject");
Role testRole1 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole1");
ResourceGroup testGroup1 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup1", false);
Resource resource1 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource1");
Resource resource2 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource2");
Resource resource3 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource3");
Role testRole2 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole2");
ResourceGroup testGroup2 = SessionTestHelper.createNewMixedGroupForRole(em, testRole2, "testGroup2", false);
testGroup2.addRole(testRole1);
testRole1.getResourceGroups().add(testGroup2);
testGroup1.addRole(testRole2);
testRole2.getResourceGroups().add(testGroup1);
testGroup2.addExplicitResource(resource1);
resource1.getExplicitGroups().add(testGroup2);
/*
* Single resource implies the implicit resource list should mirror the explicit one
*/
testGroup2.addImplicitResource(resource1);
resource1.getImplicitGroups().add(testGroup2);
em.merge(testGroup1);
em.merge(testGroup2);
em.merge(testRole1);
em.merge(testRole2);
em.merge(resource1);
em.flush();
/* setup permissions */
Set<Permission> somePermissions = EnumSet.of(Permission.CONFIGURE_WRITE, Permission.CONTROL,
Permission.MANAGE_INVENTORY);
Set<Permission> otherPermissions = EnumSet.of(Permission.CONTROL, Permission.MANAGE_SECURITY,
Permission.MANAGE_INVENTORY);
testRole1.getPermissions().addAll(somePermissions);
testRole2.getPermissions().addAll(otherPermissions);
em.merge(testRole1);
em.merge(testRole2);
em.flush();
/* setup shared object for result testing */
Set<Permission> allPermissions = EnumSet.noneOf(Permission.class);
allPermissions.addAll(somePermissions);
allPermissions.addAll(otherPermissions);
/* verify getResourcePermissions test */
Set<Permission> allPermissionsResults = authorizationManager.getExplicitResourcePermissions(testSubject,
resource1.getId());
assert SessionTestHelper.samePermissions(allPermissions, allPermissionsResults) : "Failed to get all 2-role crossed 2-group, 1-resource distinct permissions";
/* verify hasResourcePermission test */
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, resource1.getId())) : "Failed to get single 2-role crossed 2-group, 1-resource distinct permission";
}
/* verify hasResourcePermission(collection) test */
Collection<Integer> allResources = SessionTestHelper.getResourceList(resource1, resource2, resource3);
for (Permission permission : allPermissions) {
assert (authorizationManager.hasResourcePermission(testSubject, permission, allResources)) : "Failed to get every positive 2-role crossed 2-group, resource-list permission";
}
} finally {
getTransactionManager().rollback();
}
/*
* p | subject -- role -- group -- resource \ \- role -- group -- resource
* | p
*/
getTransactionManager().begin();
em = getEntityManager();
try {
/* bootstrap */
Subject testSubject = SessionTestHelper.createNewSubject(em, "testSubject");
Role testRole1 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole1");
Role testRole2 = SessionTestHelper.createNewRoleForSubject(em, testSubject, "testRole2");
ResourceGroup testGroup1 = SessionTestHelper.createNewMixedGroupForRole(em, testRole1, "testGroup1", false);
ResourceGroup testGroup2 = SessionTestHelper.createNewMixedGroupForRole(em, testRole2, "testGroup2", false);
Resource resource1 = SessionTestHelper.createNewResourceForGroup(em, testGroup1, "testResource1");
Resource resource2 = SessionTestHelper.createNewResourceForGroup(em, testGroup2, "testResource2");
/* setup permissions */
Set<Permission> somePermissions = EnumSet.of(Permission.MANAGE_ALERTS, Permission.MANAGE_SETTINGS);
Set<Permission> otherPermissions = EnumSet.of(Permission.MANAGE_ALERTS, Permission.MANAGE_CONTENT);
testRole1.getPermissions().addAll(somePermissions);
testRole2.getPermissions().addAll(otherPermissions);
em.merge(testRole1);
em.merge(testRole2);
em.flush();
/* setup shared object for result testing */