Search in sources :

Example 66 with Role

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

the class AdminMgrImplTest method deleteSsdRoleMember.

/**
 * @param sArray
 */
private void deleteSsdRoleMember(String msg, String[][] sArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (String[] ssdle : sArray) {
            SDSet ssd = RoleTestData.getSDSet(ssdle);
            // first add all of the roles as members of SSD entity:
            for (String[] rle : rArray) {
                Role role = RoleTestData.getRole(rle);
                ssd.addMember(role.getName());
            }
            // now iterate over roles and remove from SSD set one at a time.
            for (String[] rle : rArray) {
                Role role = RoleTestData.getRole(rle);
                adminMgr.deleteSsdRoleMember(ssd, role);
                List<SDSet> ssdSets = reviewMgr.ssdRoleSets(role);
                assertTrue(CLS_NM + "deleteSsdRoleMember list size check ssdSets size [" + ssdSets.size() + "]", ssdSets.size() == 0);
            }
            adminMgr.deleteSsdSet(ssd);
            LOG.debug("deleteSsdRoleMember SSD [" + ssd.getName() + "] successful");
        }
    } catch (SecurityException ex) {
        LOG.error("deleteSsdRoleMember caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 67 with Role

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

the class AdminMgrImplTest method setSsdCardinality.

/**
 * @param msg
 * @param sArray
 * @param rArray
 */
public static void setSsdCardinality(String msg, String[][] sArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (String[] ssdle : sArray) {
            SDSet ssd = RoleTestData.getSDSet(ssdle);
            SDSet entity = adminMgr.createSsdSet(ssd);
            LOG.debug("setSsdCardinality SSD [" + entity.getName() + "] successful");
            int cardinality = 1;
            for (String[] rle : rArray) {
                Role role = RoleTestData.getRole(rle);
                adminMgr.addSsdRoleMember(ssd, role);
                adminMgr.setSsdSetCardinality(ssd, cardinality);
                int currentCardinality = reviewMgr.ssdRoleSetCardinality(ssd);
                assertTrue(CLS_NM + "setSsdCardinality cardinality check", currentCardinality == cardinality++);
            }
        }
    } catch (SecurityException ex) {
        LOG.error("setSsdCardinality caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) Role(org.apache.directory.fortress.core.model.Role) UserRole(org.apache.directory.fortress.core.model.UserRole) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 68 with Role

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

the class AdminMgrImplTest method assignUsers.

/**
 * @param msg
 * @param uArray
 * @param rArray
 * @param setTemporal
 */
public static void assignUsers(String msg, String[][] uArray, String[][] rArray, boolean setTemporal) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        int i = 0;
        for (String[] usr : uArray) {
            i++;
            for (String[] rle : rArray) {
                User user = UserTestData.getUser(usr);
                Role role = RoleTestData.getRole(rle);
                UserRole uRole = new UserRole();
                ConstraintUtil.copy(role, uRole);
                if (!setTemporal) {
                    // test the default constraints for role
                    uRole = new UserRole(role.getName());
                }
                uRole.setUserId(user.getUserId());
                adminMgr.assignUser(uRole);
                LOG.debug("assignUsers user [" + user.getUserId() + "] role [" + uRole.getName() + "] successful");
                // Let's double check the number of users not 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);
                assertTrue(CLS_NM + ".assignUsers list size check", i == users.size());
                assertTrue(CLS_NM + ".assignUsers list2 size check", i == users2.size());
            }
        }
    } catch (SecurityException ex) {
        LOG.error("assignUsers user 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) 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 69 with Role

use of org.apache.directory.fortress.core.model.Role 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 70 with Role

use of org.apache.directory.fortress.core.model.Role 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)

Aggregations

Role (org.apache.directory.fortress.core.model.Role)117 UserRole (org.apache.directory.fortress.core.model.UserRole)83 SecurityException (org.apache.directory.fortress.core.SecurityException)66 AdminMgr (org.apache.directory.fortress.core.AdminMgr)40 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)30 User (org.apache.directory.fortress.core.model.User)30 AdminRole (org.apache.directory.fortress.core.model.AdminRole)25 Permission (org.apache.directory.fortress.core.model.Permission)24 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)17 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)15 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)15 Relationship (org.apache.directory.fortress.core.model.Relationship)7 SDSet (org.apache.directory.fortress.core.model.SDSet)7 FinderException (org.apache.directory.fortress.core.FinderException)6 PermObj (org.apache.directory.fortress.core.model.PermObj)6 ArrayList (java.util.ArrayList)5 Group (org.apache.directory.fortress.core.model.Group)5 Constraint (org.apache.directory.fortress.core.model.Constraint)4 FortRequest (org.apache.directory.fortress.core.model.FortRequest)4 FortResponse (org.apache.directory.fortress.core.model.FortResponse)4