Search in sources :

Example 51 with UserRole

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

the class AdminMgrImplTest method assignUsersH.

/**
 * @param msg
 * @param uArray
 * @param rArray
 * @param setTemporal
 */
public static void assignUsersH(String msg, String[][] uArray, String[][] rArray, boolean setTemporal) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        int i = 0;
        for (String[] usr : uArray) {
            Role role = RoleTestData.getRole(rArray[i]);
            UserRole uRole = new UserRole();
            uRole.setUserId(UserTestData.getUserId(usr));
            ConstraintUtil.copy(role, uRole);
            adminMgr.assignUser(uRole);
            i++;
        }
    } catch (SecurityException ex) {
        LOG.error("assignUsersH 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) 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 52 with UserRole

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

the class AdminMgrImplTest method assignUsersSSD.

/**
 * @param msg
 * @param uArray
 * @param sArray
 */
public static void assignUsersSSD(String msg, String[][] uArray, String[][] sArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        int i = 0;
        for (String[] usr : uArray) {
            SDSet ssd = RoleTestData.getSDSet(sArray[i++]);
            // Set<String> roles = ssd.getMembers().keySet();
            Set<String> roles = ssd.getMembers();
            User user = UserTestData.getUser(usr);
            int j = 0;
            for (String role : roles) {
                j++;
                try {
                    UserRole uRole = new UserRole(user.getUserId(), role);
                    adminMgr.assignUser(uRole);
                    if (j >= ssd.getCardinality()) {
                        fail(CLS_NM + ".assignUsersSSD user [" + user.getUserId() + "] role [" + role + "] ssd [" + ssd.getName() + "] cardinality [" + ssd.getCardinality() + "] count [" + j + "] failed");
                    }
                } catch (SecurityException ex) {
                    assertTrue(CLS_NM + ".assignUsersSSD cardinality test failed user [" + user.getUserId() + "] role [" + role + "] ssd [" + ssd.getName() + "] cardinality [" + ssd.getCardinality() + "] count [" + j + "]", j >= (ssd.getCardinality()));
                    assertTrue(CLS_NM + ".assignUsersSSD cardinality test failed [" + UserTestData.getUserId(usr) + "]", ex.getErrorId() == GlobalErrIds.SSD_VALIDATION_FAILED);
                    // still good, break from loop, we're done here
                    break;
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("assignUsersSSD 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 53 with UserRole

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

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

the class AdminMgrImplTest method addUsers.

/**
 * @param uArray
 */
public static 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());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 55 with UserRole

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

UserRole (org.apache.directory.fortress.core.model.UserRole)89 User (org.apache.directory.fortress.core.model.User)55 SecurityException (org.apache.directory.fortress.core.SecurityException)48 Session (org.apache.directory.fortress.core.model.Session)28 AccessMgr (org.apache.directory.fortress.core.AccessMgr)17 ArrayList (java.util.ArrayList)16 Role (org.apache.directory.fortress.core.model.Role)16 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)16 AdminMgr (org.apache.directory.fortress.core.AdminMgr)14 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)12 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)11 Constraint (org.apache.directory.fortress.core.model.Constraint)10 AdminRole (org.apache.directory.fortress.core.model.AdminRole)9 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)7 AccelMgr (org.apache.directory.fortress.core.AccelMgr)6 FinderException (org.apache.directory.fortress.core.FinderException)6 SDSet (org.apache.directory.fortress.core.model.SDSet)6 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)6 Enumeration (java.util.Enumeration)5