use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class CreateRoleHierarchySample method testCreateAscendantRoles.
/**
* Demonstrate a child to parent Role structure of one-to-many. To use this API, the child Role must be created before
* the call to addAscendant which will Add a new Role node and set a Role relationship with child node.
* <p>
* <img src="./doc-files/HierRoleAscendants.png" alt="">
*/
public static void testCreateAscendantRoles() {
String szLocation = ".testCreateAscendantRoles";
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// Instantiate the Role entity.
Role childRole = new Role(TEST_HIER_ASC_ROLE_PREFIX + 1);
// This child will have many parents:
adminMgr.addRole(childRole);
// Create roles, sampleHierRoleA2 - sampleHierRoleA10
for (int i = 1; i < TEST_NUMBER; i++) {
// Now add Role relationship to the directory between parent and child Roles.
Role parentRole = new Role(TEST_HIER_ASC_ROLE_PREFIX + (i + 1));
adminMgr.addAscendant(childRole, parentRole);
}
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class CreateRoleHierarchySample method testCreateDescendantRoles.
/**
* Demonstrate a parent to child Role structure of one-to-many. The parent Role must be created before
* the call to addDescendant which will Add a new Role node and set a Role relationship with parent node.
* <p>
* <img src="./doc-files/HierRoleDescendants.png" alt="">
*/
public static void testCreateDescendantRoles() {
String szLocation = ".testCreateDescendantRoles";
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// Instantiate the Role entity.
Role parentRole = new Role(TEST_HIER_DESC_ROLE_PREFIX + 1);
// This parent will have many children:
adminMgr.addRole(parentRole);
// Create roles, sampleHierRoleD2 - sampleHierRoleD10
for (int i = 1; i < TEST_NUMBER; i++) {
// Now add Role relationship to the directory between parent and child Roles.
Role childRole = new Role(TEST_HIER_DESC_ROLE_PREFIX + (i + 1));
adminMgr.addDescendant(parentRole, childRole);
}
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class CreateRoleHierarchySample method testDeleteDescendantRoles.
/**
* Demonstrate teardown of a parent to child relationship of one-to-many. Each child must first remove the inheritance
* relationship with parent before being removed from ldap. The parent Role will be removed from ldap last.
* Role removal will trigger automatic deassignment from all Users or revocation of Permission as well.
* <p>
* <img src="./doc-files/HierRoleDescendants.png" alt="">
*/
public static void testDeleteDescendantRoles() {
String szLocation = ".testDeleteDescendantRoles";
if (AllSamplesJUnitTest.isFirstRun()) {
return;
}
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// This parent has many children. They must be deleted before parent itself can.
Role parentRole = new Role(TEST_HIER_DESC_ROLE_PREFIX + 1);
// There are 10 Roles to process:
for (int i = 2; i < TEST_NUMBER + 1; i++) {
Role childRole = new Role(TEST_HIER_DESC_ROLE_PREFIX + i);
adminMgr.deleteInheritance(parentRole, childRole);
// Remove the child Role from directory along with associated assignments:
adminMgr.deleteRole(childRole);
LOG.info(szLocation + " role [" + childRole.getName() + "] success");
}
// Remove the parent Role from directory along with associated assignments:
adminMgr.deleteRole(parentRole);
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class CreateRoleSample method testDeleteRoles.
/**
* Remove the Role from the directory. Role removal will trigger automatic deassignment from all Users or revocation of Permission as well.
*/
public static void testDeleteRoles() {
String szLocation = ".testDeleteRoles";
if (AllSamplesJUnitTest.isFirstRun()) {
return;
}
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
for (int i = 1; i < 11; i++) {
// The key that must be set to locate any Role is simply the name.
Role inRole = new Role(TEST_ROLE_PREFIX + i);
// Remove the Role from directory along with associated assignments:
adminMgr.deleteRole(inRole);
// Instantiate the ReviewMgr implementation which is used to interrogate RBAC policy information.
ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
try {
// this should fail because the Role was deleted above:
reviewMgr.readRole(inRole);
fail(szLocation + " role [" + inRole.getName() + "] delete failed");
} catch (FinderException se) {
assertTrue(szLocation + " excep id check", se.getErrorId() == GlobalErrIds.ROLE_NOT_FOUND);
// pass
}
LOG.info(szLocation + " role [" + inRole.getName() + "] success");
}
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.model.Role in project directory-fortress-core by apache.
the class CreateRoleSample method testDeleteSimpleRole.
public static void testDeleteSimpleRole() {
if (AllSamplesJUnitTest.isFirstRun()) {
return;
}
String szLocation = ".testDeleteSimpleRole";
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// At its simplest a Role contains only a name.
Role inRole = new Role(TEST_SIMPLE_ROLE);
// Call the API to remove the Role from ldap.
adminMgr.deleteRole(inRole);
} catch (SecurityException ex) {
LOG.error(szLocation + " caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
Aggregations