use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.
the class CreatePermSample method testRevokePermissionRole.
/**
* This test will remove the RBAC Role name associated with a particular Permission Operation node in ldap.
*/
public static void testRevokePermissionRole() {
String szLocation = ".testRevokePermissionRole";
if (AllSamplesJUnitTest.isFirstRun()) {
return;
}
try {
// Instantiate the AdminMgr implementation which is used to provision RBAC policies.
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
// Instantiate the ReviewMgr implementation which is used to interrogate policy information.
ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
// Iterate over roles...
for (int i = 1; i < 11; i++) {
Role inRole = new Role(CreateRoleSample.TEST_ROLE_PREFIX + i);
List<Permission> perms = reviewMgr.rolePermissions(inRole);
for (Permission perm : perms) {
// This API removes the 'oamRoles' attribute associated with Role from the 'oamOperation' ldap object class:
adminMgr.revokePermission(perm, inRole);
}
}
// Iterate to ensure all Operation entities no longer contain Role assignments (for test purposes only):
for (int j = 1; j < 6; j++) {
// Permissions contain Object to Operation mapping and once created can then be targeted for assignment to Role entities in ldap:
Permission inPerm = new Permission(TEST_PERM_OBJECT, TEST_PERM_OPERATION_PREFIX + j);
// now retrieve the list of Roles that are still assigned to perm. This should be a null list because of revocation performed above:
List<String> assignedRoles = reviewMgr.permissionRoles(inPerm);
assertTrue(assignedRoles.size() == 0);
LOG.info(szLocation + " permission roles revocation check for object [" + inPerm.getObjName() + "] operation name [" + inPerm.getOpName() + "] revocation 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.AdminMgr in project directory-fortress-core by apache.
the class CreatePermSample method testAddPermOperations.
/**
* The Permission entity contains operation name along with any assigned Role and User entities. The Permission
* ldap node is located as child node of Permission Object node.
*/
public static void testAddPermOperations() {
String szLocation = ".testAddPermOperations";
try {
AdminMgr adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
for (int i = 1; i < 6; i++) {
// The Permission entity is associated with PermObj (name) entity and is uniquely identified by Operation name:
Permission inPerm = new Permission(TEST_PERM_OBJECT, TEST_PERM_OPERATION_PREFIX + i);
// The Permission entity will be a child node of specified PermObject entity.
adminMgr.addPermission(inPerm);
// Instantiate the ReviewMgr implementation which is used to interrogate policy information.
ReviewMgr reviewMgr = ReviewMgrFactory.createInstance(TestUtils.getContext());
// now read the newly created Permission entity back.
Permission outPerm = reviewMgr.readPermission(inPerm);
// Do some validations.
assertNotNull(outPerm);
assertTrue(szLocation + " failed permission check", outPerm.equals(inPerm));
LOG.info(szLocation + " permission object [" + outPerm.getObjName() + "] operation name [" + outPerm.getOpName() + "] 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.AdminMgr in project directory-fortress-core by apache.
the class AdminManagerTest method addUsers.
/**
* @param uArray
*/
private void addUsers(String msg, String[][] uArray, boolean isAdmin) {
LogUtil.logIt(msg);
try {
AdminMgr adminMgr;
if (isAdmin) {
adminMgr = getManagedAdminMgr();
} else {
adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
}
for (String[] usr : uArray) {
User user = UserTestData.getUser(usr);
adminMgr.addUser(user);
LOG.debug("addUsers user [" + user.getUserId() + "] successful");
// Does User have Role assignments?
Set<String> asgnRoles = UserTestData.getAssignedRoles(usr);
if (asgnRoles != null) {
for (String name : asgnRoles) {
adminMgr.assignUser(new UserRole(user.getUserId(), name));
}
}
}
} catch (SecurityException ex) {
ex.printStackTrace();
LOG.error("addUsers: caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
fail(ex.getMessage());
}
}
use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.
the class DelAdminMgrImpl method revokePermission.
/**
* {@inheritDoc}
*/
@Override
public void revokePermission(Permission perm, User user) throws SecurityException {
final AdminMgr adminMgr = AdminMgrFactory.createInstance(this.contextId);
perm.setAdmin(true);
adminMgr.revokePermission(perm, user);
}
use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.
the class DelAdminMgrImpl method revokePermission.
/**
* {@inheritDoc}
*/
@Override
public void revokePermission(Permission perm, AdminRole role) throws SecurityException {
final AdminMgr adminMgr = AdminMgrFactory.createInstance(this.contextId);
perm.setAdmin(true);
adminMgr.revokePermission(perm, role);
}
Aggregations