Search in sources :

Example 1 with PermAnt

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

the class FortressAntLoadTest method testReadPermissionOp.

@Test
public void testReadPermissionOp() {
    // gather permission operation input data:
    List<AddpermOp> addpermOps = fortressAntTask.getAddpermOps();
    for (AddpermOp addpermOp : addpermOps) {
        List<PermAnt> permissions = addpermOp.getPermOps();
        readPermissionOps("RD-PRM-OPS", permissions);
    }
}
Also used : PermAnt(org.apache.directory.fortress.core.ant.PermAnt) AddpermOp(org.apache.directory.fortress.core.ant.AddpermOp) Test(org.junit.Test)

Example 2 with PermAnt

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

the class FortressAntLoadTest method readPermissionOps.

/**
 * @param msg
 * @param permissions
 */
private static void readPermissionOps(String msg, List<PermAnt> permissions) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = ReviewMgrImplTest.getManagedReviewMgr();
        for (PermAnt permAnt : permissions) {
            Permission entity = reviewMgr.readPermission(permAnt);
            assertNotNull(entity);
            assertTrue("Failed objName value compare", entity.getObjName().equals(permAnt.getObjName()));
            assertTrue("Failed opName value compare", entity.getOpName().equals(permAnt.getOpName()));
        }
    } catch (SecurityException ex) {
        LOG.error("readPermissionOps caught SecurityException rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage() + ex);
        fail(ex.getMessage());
    }
}
Also used : PermAnt(org.apache.directory.fortress.core.ant.PermAnt) ReviewMgr(org.apache.directory.fortress.core.ReviewMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException)

Example 3 with PermAnt

use of org.apache.directory.fortress.core.ant.PermAnt 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)

Aggregations

PermAnt (org.apache.directory.fortress.core.ant.PermAnt)3 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)2 SecurityException (org.apache.directory.fortress.core.SecurityException)2 CSVWriter (au.com.bytecode.opencsv.CSVWriter)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 AccessMgr (org.apache.directory.fortress.core.AccessMgr)1 AddpermOp (org.apache.directory.fortress.core.ant.AddpermOp)1 UserAnt (org.apache.directory.fortress.core.ant.UserAnt)1 Permission (org.apache.directory.fortress.core.model.Permission)1 Session (org.apache.directory.fortress.core.model.Session)1 UserRole (org.apache.directory.fortress.core.model.UserRole)1 Warning (org.apache.directory.fortress.core.model.Warning)1 Test (org.junit.Test)1