Search in sources :

Example 26 with User

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

the class ReviewMgrImplTest method readUserRoleConstraint.

public static void readUserRoleConstraint(String msg, String[] usr, String[] rle, RoleConstraint rc) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        User user = UserTestData.getUser(usr);
        Role role = RoleTestData.getRole(rle);
        List<UserRole> urs = reviewMgr.assignedRoles(user);
        boolean uraFound = false;
        boolean urcFound = false;
        for (UserRole ur : urs) {
            if (ur.getName().equals(role.getName())) {
                uraFound = true;
                List<RoleConstraint> rcs = ur.getRoleConstraints();
                for (RoleConstraint r : rcs) {
                    if (r.getKey().equals(rc.getKey())) {
                        urcFound = true;
                        assertEquals(rc.getType(), r.getType());
                        assertEquals(rc.getValue(), r.getValue());
                        assertNotNull(r.getId());
                    }
                }
            }
        }
        if (!uraFound) {
            fail("User Role Assignment Not Found");
        }
        if (!urcFound) {
            fail("User Role Constraint Not Found");
        }
        LOG.debug("readUserRoleConstraint value [" + rc.getValue() + "] successful");
    } catch (SecurityException ex) {
        LOG.error("readUserRoleConstraint value [" + rc.getValue() + "] 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)

Example 27 with User

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

the class ReviewMgrImplTest method assignUserRoleConstraints.

private void assignUserRoleConstraints(String msg, String[][] urArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (String[] urConstraint : urArray) {
            UserRole uRole = RoleTestData.getUserRoleConstraintAbac(urConstraint);
            RoleConstraint constraint = uRole.getConstraints().get(0);
            List<User> users = reviewMgr.assignedUsers(new Role(uRole.getName()), constraint);
            assertTrue(users.size() > 0);
        }
    } catch (SecurityException ex) {
        LOG.error("assignUserRoleConstraints 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)

Example 28 with User

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

the class ReviewMgrImplTest method userPermissions.

/**
 * @param msg
 * @param uArray
 * @param pObjArray
 * @param pOpArray
 */
public static void userPermissions(String msg, String[][] uArray, String[][] pObjArray, String[][] pOpArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            List<Permission> perms = reviewMgr.userPermissions(user);
            assertNotNull(perms);
            assertTrue(CLS_NM + "userPermissions list size check", pOpArray.length * pObjArray.length == perms.size());
            for (String[] obj : pObjArray) {
                for (String[] op : pOpArray) {
                    int indx = perms.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
                    if (indx != -1) {
                        Permission pOp = perms.get(indx);
                        assertNotNull(pOp);
                        PermTestData.assertEquals(PermTestData.getName(obj), pOp, op);
                        LOG.debug("userPermissions userId [" + user.getUserId() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] successful");
                    } else {
                        msg = "userPermissions userId [" + user.getUserId() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] failed list search";
                        LogUtil.logIt(msg);
                        fail(msg);
                    }
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("userPermissions 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) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 29 with User

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

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

the class AdminMgrImplTest method addUserGrants.

/**
 * @param uArray
 * @param objArray
 * @param opArray
 */
public static void addUserGrants(String msg, String[][] uArray, String[][] objArray, String[][] opArray) {
    LogUtil.logIt(msg);
    Permission pOp = new Permission();
    User user = new User();
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] usr : uArray) {
            for (String[] obj : objArray) {
                for (String[] op : opArray) {
                    user = new User(UserTestData.getUserId(usr));
                    pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                    adminMgr.grantPermission(pOp, user);
                    LOG.debug("addUserGrants userId [" + user.getUserId() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("addUserGrants userId [" + user.getUserId() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Aggregations

User (org.apache.directory.fortress.core.model.User)203 SecurityException (org.apache.directory.fortress.core.SecurityException)135 UserRole (org.apache.directory.fortress.core.model.UserRole)72 Session (org.apache.directory.fortress.core.model.Session)55 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)44 AdminMgr (org.apache.directory.fortress.core.AdminMgr)41 AccessMgr (org.apache.directory.fortress.core.AccessMgr)34 Role (org.apache.directory.fortress.core.model.Role)33 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)32 Permission (org.apache.directory.fortress.core.model.Permission)27 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)27 AdminPermissionOperation (org.apache.directory.fortress.annotation.AdminPermissionOperation)18 AdminRole (org.apache.directory.fortress.core.model.AdminRole)17 ArrayList (java.util.ArrayList)13 AccelMgr (org.apache.directory.fortress.core.AccelMgr)12 PwPolicyMgr (org.apache.directory.fortress.core.PwPolicyMgr)10 Constraint (org.apache.directory.fortress.core.model.Constraint)9 FortRequest (org.apache.directory.fortress.core.model.FortRequest)9 FortResponse (org.apache.directory.fortress.core.model.FortResponse)9 Enumeration (java.util.Enumeration)6