Search in sources :

Example 46 with ReviewMgr

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

the class FortressAntLoadTest method checkPermissions.

/**
 * @param msg
 * @param permissions
 */
private void checkPermissions(String msg, List<UserAnt> users, List<PermAnt> permissions) {
    String DATE_FORMAT = "E yyyy.MM.dd 'at' hh:mm:ss a zzz";
    SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
    Date now = new Date();
    String szTimestamp = format.format(now);
    AccessMgr accessMgr = null;
    CSVWriter writer = null;
    LogUtil.logIt(msg);
    try {
        accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        writer = new CSVWriter(new FileWriter(fileName + ".csv"), '\t');
        String[] entries = "user#resource#operation#result#assigned roles#activated roles#timestamp#warnings".split("#");
        writer.writeNext(entries);
    } catch (SecurityException ex) {
        LOG.error("checkPermissions caught SecurityException creating AccessMgr rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage() + ex);
        // Can't continue without AccessMgr
        fail(ex.getMessage());
    } catch (IOException ioe) {
        String error = "File IO Exception=" + ioe;
        LOG.warn(error);
        // Can't continue without output file to write the results in
        fail(ioe.getMessage());
    }
    for (UserAnt user : users) {
        try {
            List<String> warnings = null;
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            if (session.getWarnings() != null) {
                warnings = new ArrayList();
                for (Warning warning : session.getWarnings()) {
                    warnings.add(warning.getMsg());
                }
            }
            ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
            List<UserRole> assignedRoles = reviewMgr.assignedRoles(user);
            for (PermAnt permAnt : permissions) {
                Boolean result = accessMgr.checkAccess(session, permAnt);
                // TODO: send this message as CSV output file:
                LOG.info("User: " + user.getUserId() + " Perm Obj: " + permAnt.getObjName() + " Perm " + "Operation: " + permAnt.getOpName() + " RESULT: " + result);
                String[] entries = (user.getUserId() + "#" + permAnt.getObjName() + "#" + permAnt.getOpName() + "#" + result + "#" + assignedRoles + "#" + session.getUser().getRoles() + "#" + szTimestamp + "#" + warnings).split("#");
                writer.writeNext(entries);
            }
        } catch (SecurityException ex) {
            // Log but don't fail test so entire permission matrix can be evaluated.
            LOG.error("checkPermissions caught SecurityException rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage() + ex);
        }
    }
    try {
        writer.close();
    } catch (IOException ioe) {
    // ignore
    }
}
Also used : Warning(org.apache.directory.fortress.core.model.Warning) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) CSVWriter(au.com.bytecode.opencsv.CSVWriter) SecurityException(org.apache.directory.fortress.core.SecurityException) IOException(java.io.IOException) Date(java.util.Date) UserAnt(org.apache.directory.fortress.core.ant.UserAnt) PermAnt(org.apache.directory.fortress.core.ant.PermAnt) AccessMgr(org.apache.directory.fortress.core.AccessMgr) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SimpleDateFormat(java.text.SimpleDateFormat) Session(org.apache.directory.fortress.core.model.Session)

Example 47 with ReviewMgr

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

the class FortressAntLoadTest method readPermissionObjs.

private static void readPermissionObjs(String msg, List<PermObj> permObjs) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (PermObj permObj : permObjs) {
            PermObj entity = reviewMgr.readPermObj(permObj);
            assertNotNull(entity);
            assertTrue("Failed objName value compare", entity.getObjName().equals(permObj.getObjName()));
        }
    } catch (SecurityException ex) {
        LOG.error("readPermissionOps 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)

Example 48 with ReviewMgr

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

the class FortressAntLoadTest method readRoles.

private static void readRoles(String msg, List<Role> roles) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (Role role : roles) {
            Role entity = reviewMgr.readRole(role);
            assertNotNull(entity);
            assertTrue("Failed role name", entity.getName().equals(role.getName()));
            TestUtils.assertTemporal(CLS_NM + ".assertEquals", role, entity);
        }
    } catch (SecurityException ex) {
        LOG.error("readRoles caught SecurityException=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : 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)

Example 49 with ReviewMgr

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

the class ReviewMgrImplTest method authorizedPermissionUsers.

/**
 * @param msg
 * @param pObjArray
 * @param pOpArray
 * @param uArray
 */
public static void authorizedPermissionUsers(String msg, String[][] pObjArray, String[][] pOpArray, String[][] uArray) {
    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> users = reviewMgr.authorizedPermissionUsers(pOp);
                assertNotNull(users);
                int expectedAuthZedUsers = i + 1;
                assertTrue(CLS_NM + "authorizedPermissionUsers permission object [" + pOp.getObjName() + "] operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", expectedAuthZedUsers == users.size());
                int j = 1;
                for (String[] usr : uArray) {
                    String userId = UserTestData.getUserId(usr);
                    if (j++ <= expectedAuthZedUsers) {
                        assertTrue(CLS_NM + "authorizedPermissionUsers userId [" + userId + "] should be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", users.contains(userId));
                    } else {
                        assertTrue(CLS_NM + "authorizedPermissionUsers userId [" + userId + "] should not be authorized for operationName [" + pOp.getOpName() + "] objectId [" + pOp.getObjId() + "]", !users.contains(userId));
                    }
                }
                i++;
            }
        }
    } catch (SecurityException ex) {
        LOG.error("authorizedPermissionUsers 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 50 with ReviewMgr

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

the class ReviewMgrImplTest method searchUsers.

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