Search in sources :

Example 61 with ReviewMgr

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

the class ReviewMgrImplTest method assignedRoles.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void assignedRoles(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] usr : uArray) {
            User user = reviewMgr.readUser(new User(UserTestData.getUserId(usr)));
            assertNotNull(user);
            List<UserRole> uRoles = reviewMgr.assignedRoles(user);
            assertTrue(CLS_NM + "assignedRoles list size check", rArray.length == uRoles.size());
            for (String[] url : rArray) {
                int indx = uRoles.indexOf(RoleTestData.getUserRole(UserTestData.getUserId(usr), url));
                if (indx != -1) {
                    UserRole uRole = uRoles.get(indx);
                    assertNotNull(uRole);
                    RoleTestData.assertEquals(UserTestData.getUserId(usr), uRole, url);
                    LOG.debug("assignedRoles userId [" + uRole.getUserId() + "] role [" + uRole.getName() + "] successful");
                } else {
                    msg = "assignedRoles userId [" + user.getUserId() + "] role [" + RoleTestData.getName(url) + "] failed list search";
                    LogUtil.logIt(msg);
                    fail(msg);
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("assignedRoles 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)

Example 62 with ReviewMgr

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

the class ReviewMgrImplTest method searchPermissionOps.

/**
 * @param msg
 * @param srchValue
 * @param pObjArray
 */
public static void searchPermissionOps(String msg, String srchValue, String[][] pObjArray, String[][] pOpArray) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] obj : pObjArray) {
            for (String[] op : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(obj));
                pOp.setOpName(srchValue);
                List<Permission> ops = reviewMgr.findPermissions(pOp);
                assertNotNull(ops);
                assertTrue(CLS_NM + "searchPermissionOps srchValue [" + srchValue + "] list size check", pOpArray.length == ops.size());
                int indx = ops.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
                if (indx != -1) {
                    Permission entity = ops.get(indx);
                    assertNotNull(entity);
                    PermTestData.assertEquals(PermTestData.getName(obj), entity, op);
                    LOG.debug("searchPermissionOps objName [" + entity.getObjName() + "] operation name [" + entity.getOpName() + "] successful");
                } else {
                    msg = "searchPermissionOps srchValue [" + srchValue + "] failed list search";
                    LogUtil.logIt(msg);
                    fail(msg);
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("searchPermissionOps srchValue [" + srchValue + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : 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 63 with ReviewMgr

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

the class ReviewMgrImplTest method permissionRoles.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 * @param rArray
 */
public static void permissionRoles(String msg, String[][] pObjArray, String[][] pOpArray, String[][] rArray) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] obj : pObjArray) {
            for (String[] op : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(obj));
                pOp.setOpName(PermTestData.getName(op));
                pOp.setObjId(PermTestData.getObjId(op));
                List<String> roles = reviewMgr.permissionRoles(pOp);
                assertNotNull(roles);
                assertTrue(CLS_NM + "permissionRoles permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", rArray.length == roles.size());
                for (String[] rle : rArray) {
                    int indx = roles.indexOf(RoleTestData.getName(rle));
                    if (indx != -1) {
                        String roleNm = roles.get(indx);
                        assertEquals(CLS_NM + ".permissionRoles failed compare role name", RoleTestData.getName(rle), roleNm);
                        LOG.debug(".permissionRoles permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] roleNm [" + roleNm + "] successful");
                    } else {
                        msg = "permissionRoles permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "]  objectId [" + pOp.getObjId() + "] role [" + RoleTestData.getName(rle) + "] failed list search";
                        LogUtil.logIt(msg);
                        fail(msg);
                    }
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("permissionRoles caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : 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 64 with ReviewMgr

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

the class ReviewMgrImplTest method authorizedUsersHier.

/**
 * @param msg
 * @param roleMap
 */
public static void authorizedUsersHier(String msg, Map roleMap) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        // iterate over every role entry found in map:
        for (Object o : roleMap.entrySet()) {
            Map.Entry pairs = (Map.Entry) o;
            String roleName = (String) pairs.getKey();
            String szValidUsers = (String) pairs.getValue();
            Set<String> userSet = TestUtils.getSets(szValidUsers);
            assertNotNull(userSet);
            assertTrue(userSet.size() > 0);
            List<User> actualUsers = reviewMgr.authorizedUsers(new Role(roleName));
            assertNotNull(actualUsers);
            assertTrue(actualUsers.size() > 0);
            // Ensure the two list sizes match or fail the test case.
            assertTrue(CLS_NM + "authorizedUsersHier failed list size test case", userSet.size() == actualUsers.size());
            // for each valid user expected, ensure it actually pulled from API:
            for (String userId : userSet) {
                User validUser = new User(userId);
                assertTrue(CLS_NM + ".authorizedUsersHier failed authorizedUsers test, role [" + roleName + "] does not have user [" + validUser.getUserId() + "] as authorized", actualUsers.contains(validUser));
            }
        }
    } catch (SecurityException ex) {
        LOG.error("authorizedUsersHier 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) SecurityException(org.apache.directory.fortress.core.SecurityException) Map(java.util.Map)

Example 65 with ReviewMgr

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

the class ReviewMgrImplTest method permissionUsers.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 * @param uArray
 */
public static void permissionUsers(String msg, String[][] pObjArray, String[][] pOpArray, String[][] uArray) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] obj : pObjArray) {
            for (String[] op : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(obj));
                pOp.setOpName(PermTestData.getName(op));
                pOp.setObjId(PermTestData.getObjId(op));
                List<String> users = reviewMgr.permissionUsers(pOp);
                assertNotNull(users);
                assertTrue(CLS_NM + "permissionUsers permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", uArray.length == users.size());
                for (String[] usr : uArray) {
                    int indx = users.indexOf(RoleTestData.getName(usr));
                    if (indx != -1) {
                        String userId = users.get(indx);
                        assertEquals(CLS_NM + ".permissionUsers failed compare userId", UserTestData.getUserId(usr), userId);
                        LOG.debug("permissionUsers permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "] userId [" + userId + "] successful");
                    } else {
                        msg = "permissionUsers permission objName [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "]  objectId [" + pOp.getObjId() + "] userId [" + UserTestData.getUserId(usr) + "] failed list search";
                        LogUtil.logIt(msg);
                        fail(msg);
                    }
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("permissionUsers caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : 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)

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