Search in sources :

Example 11 with AdminMgr

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

the class AdminMgrImplTest method assignUsersDSD.

/**
 * @param msg
 * @param uArray
 * @param sArray
 */
public static void assignUsersDSD(String msg, String[][] uArray, String[][] sArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        int i = 0;
        for (String[] usr : uArray) {
            SDSet dsd = RoleTestData.getSDSet(sArray[i++]);
            Set<String> roles = dsd.getMembers();
            User user = UserTestData.getUser(usr);
            int j = 0;
            for (String role : roles) {
                j++;
                UserRole uRole = new UserRole(user.getUserId(), role);
                try {
                    adminMgr.assignUser(uRole);
                } catch (SecurityException ex) {
                    LOG.error("assignUsersDSD caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
                    fail(CLS_NM + "assignUsersDSD user [" + user.getUserId() + "] role [" + role + "] dsd [" + dsd.getName() + "] failed");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("assignUsersDSD caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) User(org.apache.directory.fortress.core.model.User) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 12 with AdminMgr

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

the class AdminMgrImplTest method deassignUsers.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
void deassignUsers(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        int i = 0;
        for (String[] usr : uArray) {
            i++;
            for (String[] rle : rArray) {
                UserRole uRole = new UserRole(UserTestData.getUserId(usr), RoleTestData.getName(rle));
                adminMgr.deassignUser(uRole);
                LOG.debug("deassignUsers user [" + uRole.getUserId() + "] role [" + uRole.getName() + "] successful");
                // Double check the number of users associated with role:
                // This one retrieves the collection of all "roleOccupant" attributes associated with the role node:
                List<String> users = reviewMgr.assignedUsers(RoleTestData.getRole(rle), rArray.length);
                // This one searches across all Users and pull back list of type "User":
                List<User> users2 = reviewMgr.authorizedUsers(RoleTestData.getRole(rle));
                assertNotNull(users);
                assertNotNull(users2);
                // If this is the last user deassigned from role, both lists will be returned empty:
                if (i == uArray.length) {
                    assertTrue(users.size() == 0);
                    assertTrue(users2.size() == 0);
                } else {
                    assertTrue(CLS_NM + "deassignUsers list size check", (rArray.length - i) == users.size());
                    assertTrue(CLS_NM + "deassignUsers list2 size check", (rArray.length - i) == users2.size());
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("deassignUsers caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 13 with AdminMgr

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

the class AdminMgrImplTest method delRoleGrantsH.

/**
 * @param msg
 * @param rArray
 * @param objArray
 * @param opArray
 */
private void delRoleGrantsH(String msg, String[][] rArray, String[][] objArray, String[][] opArray) {
    LogUtil.logIt(msg);
    Permission pOp = new Permission();
    Role role = new Role();
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        int i = 0;
        for (String[] obj : objArray) {
            role = new Role(RoleTestData.getName(rArray[i++]));
            for (String[] op : opArray) {
                pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                adminMgr.revokePermission(pOp, role);
                LOG.debug("delRoleGrantsH role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        LOG.error("delRoleGrantsH 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) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 14 with AdminMgr

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

the class AdminMgrImplTest method addPermOps.

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

Example 15 with AdminMgr

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

the class AdminMgrImplTest method createDsdSet.

/**
 * @param sArray
 */
public static void createDsdSet(String msg, String[][] sArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] dsdle : sArray) {
            SDSet dsd = RoleTestData.getSDSet(dsdle);
            SDSet entity = adminMgr.createDsdSet(dsd);
            LOG.debug("createDsdSet DSD [" + entity.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("createDsdSet caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) 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