Search in sources :

Example 51 with Permission

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

the class AccessMgrImplTest method checkAccess.

public static void checkAccess(String msg, String[][] uArray, String[][] oArray, String[][] opArray, String[][] oArrayBad, String[][] opArrayBad) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            int i = 0;
            for (String[] obj : oArray) {
                int j = 0;
                for (String[] op : opArray) {
                    Permission goodPerm;
                    if (StringUtils.isNotEmpty(PermTestData.getObjId(opArray[j]))) {
                        // with an objectId:
                        goodPerm = new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(opArray[j]));
                    } else {
                        // without an objectId:
                        goodPerm = new Permission(PermTestData.getName(obj), PermTestData.getName(op));
                    }
                    // Positive test case, call checkAccess method, should return 'true':
                    assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "]", accessMgr.checkAccess(session, goodPerm));
                    Permission badPerm;
                    if (StringUtils.isNotEmpty(PermTestData.getObjId(opArrayBad[j]))) {
                        // with an objectId:
                        badPerm = new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j]), PermTestData.getObjId(opArrayBad[j]));
                    } else {
                        // without an objectId:
                        badPerm = new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j]));
                    }
                    // LOG.warn("Assert False userId [" + user.getUserId() + "], perm: " + badPerm);
                    // Negative test case, call checkAccess method again, should return 'false':
                    assertFalse(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(oArrayBad[i]) + "] operationName [" + PermTestData.getName(opArrayBad[j]) + "]", accessMgr.checkAccess(session, badPerm));
                    j++;
                }
                i++;
            }
        }
        LOG.debug("checkAccess successful");
    } catch (SecurityException ex) {
        LOG.error("checkAccess: failed with SecurityException rc=" + ex.getErrorId() + ", " + "msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 52 with Permission

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

the class AccessMgrImplTest method sessionPermissionsH.

/**
 * @param msg
 * @param uArray
 * @param oArray
 * @param opArray
 */
public static void sessionPermissionsH(String msg, String[][] uArray, String[][] oArray, String[][] opArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        int i = 0;
        for (String[] usr : uArray) {
            i++;
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            List<Permission> pOps = accessMgr.sessionPermissions(session);
            assertNotNull(pOps);
            // LOG.warn("sessionPermissionsH list size user [" + user.getUserId() + "] expected len=" +
            // (11 - i) * opArray.length + " actual len=" + pOps.size());
            assertEquals(CLS_NM + ".sessionPermissionsH failed list size user[" + user.getUserId() + "]", (11 - i) * opArray.length, pOps.size());
            // Iterate over objs x ops, see if every expected valid permission is contained within the returned list:
            int j = 0;
            for (String[] obj : oArray) {
                j++;
                // positive tests:
                if (i == j || i < j) {
                    int k = 0;
                    for (String[] op : opArray) {
                        k++;
                        Permission validPOp = PermTestData.getOp(PermTestData.getName(obj), op);
                        assertTrue(CLS_NM + ".sessionPermissionsH failed perm list compare USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", pOps.contains(validPOp));
                        boolean result = accessMgr.checkAccess(session, new Permission(PermTestData.getName(obj), PermTestData.getName(op)));
                        assertTrue(CLS_NM + ".sessionPermissionsH failed checkAccess USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", result);
                    }
                } else // negative tests:
                {
                    int k = 0;
                    for (String[] op : opArray) {
                        k++;
                        Permission validPOp = PermTestData.getOp(PermTestData.getName(obj), op);
                        assertTrue(CLS_NM + ".sessionPermissionsH failed negative perm list compare USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", !pOps.contains(validPOp));
                        boolean result = accessMgr.checkAccess(session, new Permission(PermTestData.getName(obj), PermTestData.getName(op)));
                        assertTrue(CLS_NM + ".sessionPermissionsH failed negative checkAccess USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", !result);
                    }
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("sessionPermissionsH: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 53 with Permission

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

the class AccessMgrImplTest method sessionPermissions.

/**
 * @param msg
 * @param uArray
 * @param oArray
 * @param opArray
 */
public static void sessionPermissions(String msg, String[][] uArray, String[][] oArray, String[][] opArray) {
    LogUtil.logIt(msg);
    try {
        AccessMgr accessMgr = AccessMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accessMgr.createSession(user, false);
            assertNotNull(session);
            List<Permission> pOps = accessMgr.sessionPermissions(session);
            assertNotNull(pOps);
            // There should be objs * ops number of perms in the list returned from sessionPermissions method:
            assertEquals(CLS_NM + ".sessionPermissions failed list size user[" + user.getUserId() + "]", oArray.length * opArray.length, pOps.size());
            // Iterate over objs x ops, see if every expected valid permission is contained within the returned list:
            for (String[] obj : oArray) {
                for (String[] op : opArray) {
                    Permission validPOp = PermTestData.getOp(PermTestData.getName(obj), op);
                    assertTrue(CLS_NM + ".sessionPermissions failed perm list compare USER [" + user.getUserId() + "] PERM Obj [" + PermTestData.getName(obj) + "] " + "OPER [" + PermTestData.getName(op) + "]", pOps.contains(validPOp));
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("sessionPermissions: failed with SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccessMgr(org.apache.directory.fortress.core.AccessMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 54 with Permission

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

the class AdminMgrImplTest method delUserGrants.

/**
 * @param uArray
 * @param objArray
 * @param opArray
 */
private void delUserGrants(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.revokePermission(pOp, user);
                    LOG.debug("delUserGrants userId [" + user.getUserId() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("delUserGrants 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)

Example 55 with Permission

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

the class AdminMgrImplTest method updatePermOps.

/**
 * @param objArray
 * @param opArray
 */
public static void updatePermOps(String msg, String[][] objArray, String[][] opArray, boolean isAdmin) {
    LogUtil.logIt(msg);
    Permission pOp = new Permission();
    try {
        AdminMgr adminMgr;
        if (isAdmin) {
            adminMgr = getManagedAdminMgr();
        } else {
            adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
        }
        for (String[] obj : objArray) {
            for (String[] op : opArray) {
                pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                adminMgr.updatePermission(pOp);
                LOG.debug("updatePermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "]  objectId [" + pOp.getObjId() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        LOG.error("updatePermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "]  objectId [" + pOp.getObjId() + "] caught SecurityException rc=" + ex.getErrorId() + ", msg=" + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Aggregations

Permission (org.apache.directory.fortress.core.model.Permission)99 SecurityException (org.apache.directory.fortress.core.SecurityException)58 Role (org.apache.directory.fortress.core.model.Role)24 User (org.apache.directory.fortress.core.model.User)24 AdminMgr (org.apache.directory.fortress.core.AdminMgr)18 UserRole (org.apache.directory.fortress.core.model.UserRole)17 ReviewMgr (org.apache.directory.fortress.core.ReviewMgr)16 Session (org.apache.directory.fortress.core.model.Session)12 FortRequest (org.apache.directory.fortress.core.model.FortRequest)11 FortResponse (org.apache.directory.fortress.core.model.FortResponse)11 RoleConstraint (org.apache.directory.fortress.core.model.RoleConstraint)11 ArrayList (java.util.ArrayList)10 FinderException (org.apache.directory.fortress.core.FinderException)10 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)9 AdminRole (org.apache.directory.fortress.core.model.AdminRole)9 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)9 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)9 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)7 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)7 AccessMgr (org.apache.directory.fortress.core.AccessMgr)7