Search in sources :

Example 61 with AdminMgr

use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.

the class AdminMgrImplTest method addRoleGrantsHB.

/**
 * @param msg
 * @param rArray
 * @param objArray
 * @param opArray
 */
public static void addRoleGrantsHB(String msg, String[][] uArray, String[][] rArray, String[][] objArray, String[][] opArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] obj : objArray) {
            int i = 0;
            for (String[] rle : rArray) {
                // Get Role[i] from test data:
                Role role = RoleTestData.getRole(rle);
                // Get Permission[i] from test data:
                String[] op = opArray[i];
                // Load the Permission entity with data:
                Permission pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                // Grant Permission[i] to Role[i]:
                adminMgr.grantPermission(pOp, role);
                // Get User[i] from test data:
                String[] usr = uArray[i];
                // Load the User entity with data:
                User user = UserTestData.getUser(usr);
                // Grant Permission[i] to User[i]:
                adminMgr.grantPermission(pOp, user);
                i++;
                LOG.debug("addRoleGrantsHB userId [" + user.getUserId() + "] role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        LOG.error("addRoleGrantsHB caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) User(org.apache.directory.fortress.core.model.User) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 62 with AdminMgr

use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.

the class AdminMgrImplTest method assignUserRoleConstraint.

public static RoleConstraint assignUserRoleConstraint(String msg, String[] usr, String[] rle, RoleConstraint rc) throws SecurityException {
    LogUtil.logIt(msg);
    AdminMgr adminMgr = getManagedAdminMgr();
    ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
    User user = UserTestData.getUser(usr);
    Role role = RoleTestData.getRole(rle);
    RoleConstraint createdRoleConstraint = adminMgr.addRoleConstraint(new UserRole(user.getUserId(), role.getName()), rc);
    LOG.debug("assignUserRoleConstraint user [" + user.getUserId() + "] role [" + role.getName() + "] " + " rcvalue [" + rc.getValue() + "]");
    // get user with consratint filter
    List<User> usersWithRc = reviewMgr.assignedUsers(role, rc);
    assertTrue(usersWithRc.size() == 1);
    assertEquals(user.getUserId(), usersWithRc.get(0).getUserId());
    return createdRoleConstraint;
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 63 with AdminMgr

use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.

the class AdminMgrImplTest method addInheritedRoles.

/**
 * @param rArray
 */
public static void addInheritedRoles(String msg, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] rle : rArray) {
            Role role = RoleTestData.getRole(rle);
            Set<String> parents = RoleTestData.getRelationships(rle);
            if (parents != null) {
                for (String pRole : parents) {
                    adminMgr.addInheritance(new Role(pRole), role);
                    LOG.debug("addInheritedRoles child role [" + role.getName() + "] parent role [" + pRole + "] successful");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("addInheritedRoles caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 64 with AdminMgr

use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.

the class AdminMgrImplTest method delRoleGrants.

/**
 * @param rArray
 * @param objArray
 * @param opArray
 */
public static void delRoleGrants(String msg, String[][] rArray, String[][] objArray, String[][] opArray, boolean isAdmin) {
    LogUtil.logIt(msg);
    Permission pOp = new Permission();
    Role role = new Role();
    try {
        AdminMgr adminMgr;
        if (isAdmin) {
            adminMgr = getManagedAdminMgr();
        } else {
            adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
        }
        for (String[] rle : rArray) {
            for (String[] obj : objArray) {
                for (String[] op : opArray) {
                    role = new Role(RoleTestData.getName(rle));
                    pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                    adminMgr.revokePermission(pOp, role);
                    LOG.debug("delRoleGrants role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("delRoleGrants role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 65 with AdminMgr

use of org.apache.directory.fortress.core.AdminMgr in project directory-fortress-core by apache.

the class AdminMgrImplTest method updateRoles.

/**
 * @param msg
 * @param rArray
 */
public static void updateRoles(String msg, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] rle : rArray) {
            Role role = RoleTestData.getRole(rle);
            Role entity = adminMgr.updateRole(role);
            LOG.debug("updateRoles role [" + entity.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("updateRoles caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Aggregations

AdminMgr (org.apache.directory.fortress.core.AdminMgr)104 SecurityException (org.apache.directory.fortress.core.SecurityException)89 Role (org.apache.directory.fortress.core.model.Role)40 User (org.apache.directory.fortress.core.model.User)39 UserRole (org.apache.directory.fortress.core.model.UserRole)35 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)27 Permission (org.apache.directory.fortress.core.model.Permission)18 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)16 SDSet (org.apache.directory.fortress.core.model.SDSet)12 DelAdminMgr (org.apache.directory.fortress.core.DelAdminMgr)11 PwPolicyMgr (org.apache.directory.fortress.core.PwPolicyMgr)7 PermObj (org.apache.directory.fortress.core.model.PermObj)7 AccessMgr (org.apache.directory.fortress.core.AccessMgr)6 PermissionAttributeSet (org.apache.directory.fortress.core.model.PermissionAttributeSet)3 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)1 FinderException (org.apache.directory.fortress.core.FinderException)1 AdminRole (org.apache.directory.fortress.core.model.AdminRole)1 Session (org.apache.directory.fortress.core.model.Session)1 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)1