Search in sources :

Example 51 with ReviewMgr

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

the class ReviewMgrImplTest method authorizedRoles.

/**
 * @param msg
 * @param uArray
 */
public static void authorizedRoles(String msg, String[][] uArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] usr : uArray) {
            User user = reviewMgr.readUser(new User(UserTestData.getUserId(usr)));
            assertNotNull(user);
            // Get the authorized roles for this user:
            Collection<String> authZRoles = UserTestData.getAuthorizedRoles(usr);
            // If there are any assigned roles, add them to list of authorized.
            Set<String> asgnRoles = UserTestData.getAssignedRoles(usr);
            assertNotNull(asgnRoles);
            assertTrue(asgnRoles.size() > 0);
            for (String asgnRole : asgnRoles) {
                authZRoles.add(asgnRole);
            }
            // Retrieve actual roles authorized to User according to LDAP:
            Set<String> actualRoles = reviewMgr.authorizedRoles(user);
            assertNotNull(actualRoles);
            assertTrue(actualRoles.size() > 0);
            // The two list sizes better match or fail the test case.
            assertTrue(CLS_NM + "authorizedRoles list size test case", authZRoles.size() == actualRoles.size());
            // For each authorized role found in User test data, check to see if it was found in LDAP for User.  If not fail the test case.
            for (String roleName : authZRoles) {
                assertTrue(CLS_NM + ".authorizedRoles userId [" + user.getUserId() + "] role [" + roleName + "] not found", actualRoles.contains(roleName));
            }
        }
    } 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) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 52 with ReviewMgr

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

the class ReviewMgrImplTest method findRoleConstraints.

public static void findRoleConstraints(String msg, String usr, Permission permission, RoleConstraint.RCType rcType) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        List<RoleConstraint> rcs = reviewMgr.findRoleConstraints(new User(usr), permission, rcType);
        assertTrue(rcs.size() > 0);
        assertTrue(rcs.get(0).getType().equals(rcType));
        LOG.debug("findRoleConstraints permission [" + permission.getObjName() + "." + permission.getOpName() + "] successful");
    } catch (SecurityException ex) {
        LOG.error("findRoleConstraints permission [" + permission.getObjName() + "." + permission.getOpName() + "] 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) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 53 with ReviewMgr

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

the class ReviewMgrImplTest method authorizedPermissionRoles.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 * @param rArray
 */
public static void authorizedPermissionRoles(String msg, String[][] pObjArray, String[][] pOpArray, String[][] rArray) {
    LogUtil.logIt(msg);
    Permission pOp;
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] obj : pObjArray) {
            int i = 0;
            for (String[] op : pOpArray) {
                pOp = new Permission();
                pOp.setObjName(PermTestData.getName(obj));
                pOp.setOpName(PermTestData.getName(op));
                pOp.setObjId(PermTestData.getObjId(op));
                Set<String> roles = reviewMgr.authorizedPermissionRoles(pOp);
                assertNotNull(roles);
                int expectedAuthZedRoles = i + 1;
                assertTrue(CLS_NM + "authorizedPermissionRoles permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", expectedAuthZedRoles == roles.size());
                int j = 1;
                for (String[] rle : rArray) {
                    String roleName = RoleTestData.getName(rle);
                    if (j++ <= expectedAuthZedRoles) {
                        assertTrue(CLS_NM + "authorizedPermissionRoles roleName [" + roleName + "] should be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", roles.contains(roleName));
                    } else {
                        assertTrue(CLS_NM + "authorizedPermissionRoles roleName [" + roleName + "] should not be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", !roles.contains(roleName));
                    }
                }
                i++;
            }
        }
    } catch (SecurityException ex) {
        LOG.error("authorizedPermissionRoles 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 54 with ReviewMgr

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

the class ReviewMgrImplTest method searchPermissionObjs.

/**
 * @param msg
 * @param srchValue
 * @param pArray
 */
public static void searchPermissionObjs(String msg, String srchValue, String[][] pArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        List<PermObj> objs = reviewMgr.findPermObjs(new PermObj(srchValue));
        assertNotNull(objs);
        assertTrue(CLS_NM + "searchPermissionObjs srchValue [" + srchValue + "] list size check", pArray.length == objs.size());
        for (String[] obj : pArray) {
            int indx = objs.indexOf(new PermObj(PermTestData.getName(obj)));
            if (indx != -1) {
                PermObj entity = objs.get(indx);
                assertNotNull(entity);
                PermTestData.assertEquals(entity, obj);
                LOG.debug("searchPermissionObjs [" + entity.getObjName() + "] successful");
            } else {
                msg = "searchPermissionObjs srchValue [" + srchValue + "] failed list search";
                LogUtil.logIt(msg);
                fail(msg);
            }
        }
    } catch (SecurityException ex) {
        LOG.error("searchPermissionObjs srchValue [" + srchValue + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : PermObj(org.apache.directory.fortress.core.model.PermObj) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 55 with ReviewMgr

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

the class ReviewMgrImplTest method searchUserIds.

/**
 * @param msg
 * @param srchValue
 * @param uArray
 */
public static void searchUserIds(String msg, String srchValue, String[][] uArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        List<String> users = reviewMgr.findUsers(new User(srchValue), uArray.length);
        assertNotNull(users);
        assertTrue(CLS_NM + "searchUserIds list size check", uArray.length == users.size());
        for (String[] usr : uArray) {
            int indx = users.indexOf(UserTestData.getUserId(usr));
            if (indx != -1) {
                String userId = users.get(indx);
                assertNotNull(userId);
                assertEquals(CLS_NM + ".searchUserIds failed compare user userId", UserTestData.getUserId(usr).toUpperCase(), userId.toUpperCase());
            } else {
                msg = "searchUserIds srchValue [" + srchValue + "] failed list search";
                LogUtil.logIt(msg);
                fail(msg);
            }
        }
    } catch (SecurityException ex) {
        LOG.error("searchUserIds srchValue [" + srchValue + "] 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) 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