Search in sources :

Example 36 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr 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 37 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr 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 38 with ReviewMgr

use of org.apache.directory.fortress.core.ReviewMgr 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 39 with ReviewMgr

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

the class AdminMgrImplTest method setDsdCardinality.

/**
 * @param msg
 * @param sArray
 * @param rArray
 */
public static void setDsdCardinality(String msg, String[][] sArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (String[] dsdle : sArray) {
            SDSet dsd = RoleTestData.getSDSet(dsdle);
            SDSet entity = adminMgr.createDsdSet(dsd);
            LOG.debug("setDsdCardinality DSD [" + entity.getName() + "] successful");
            int cardinality = 1;
            for (String[] rle : rArray) {
                Role role = RoleTestData.getRole(rle);
                adminMgr.addDsdRoleMember(dsd, role);
                adminMgr.setDsdSetCardinality(dsd, cardinality);
                int currentCardinality = reviewMgr.dsdRoleSetCardinality(dsd);
                assertTrue(CLS_NM + "setDsdCardinality cardinality check", currentCardinality == cardinality++);
            }
        }
    } catch (SecurityException ex) {
        LOG.error("setDsdCardinality 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 40 with ReviewMgr

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

the class AdminMgrImplTest method assertRoleConstraintSize.

private void assertRoleConstraintSize(String userId, String roleName, int size) throws SecurityException {
    boolean roleFound = false;
    ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
    List<UserRole> userRoles = reviewMgr.readUser(new User(userId)).getRoles();
    for (UserRole ur : userRoles) {
        if (ur.getName().equals(roleName)) {
            assertEquals(size, ur.getRoleConstraints().size());
            roleFound = true;
        }
    }
    if (!roleFound) {
        fail("Role with name " + roleName + " not found");
    }
}
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)

Aggregations

ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)75 SecurityException (org.apache.directory.fortress.core.SecurityException)65 UserRole (org.apache.directory.fortress.core.model.UserRole)32 User (org.apache.directory.fortress.core.model.User)31 Role (org.apache.directory.fortress.core.model.Role)30 AdminMgr (org.apache.directory.fortress.core.AdminMgr)27 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)22 Permission (org.apache.directory.fortress.core.model.Permission)16 SDSet (org.apache.directory.fortress.core.model.SDSet)8 PermObj (org.apache.directory.fortress.core.model.PermObj)5 ArrayList (java.util.ArrayList)3 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)3 PermAnt (org.apache.directory.fortress.core.ant.PermAnt)2 CSVWriter (au.com.bytecode.opencsv.CSVWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Map (java.util.Map)1 AccessMgr (org.apache.directory.fortress.core.AccessMgr)1