Search in sources :

Example 56 with Permission

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

the class AdminMgrImplTest method addRoleGrantsHB.

/**
 * @param msg
 * @param rArray
 * @param objArray
 * @param opArray
 */
public static void addRoleGrantsHB(String msg, String[][] uArray, String[][] rArray, String[][] objArray, String[][] opArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] obj : objArray) {
            int i = 0;
            for (String[] rle : rArray) {
                // Get Role[i] from test data:
                Role role = RoleTestData.getRole(rle);
                // Get Permission[i] from test data:
                String[] op = opArray[i];
                // Load the Permission entity with data:
                Permission pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                // Grant Permission[i] to Role[i]:
                adminMgr.grantPermission(pOp, role);
                // Get User[i] from test data:
                String[] usr = uArray[i];
                // Load the User entity with data:
                User user = UserTestData.getUser(usr);
                // Grant Permission[i] to User[i]:
                adminMgr.grantPermission(pOp, user);
                i++;
                LOG.debug("addRoleGrantsHB userId [" + user.getUserId() + "] role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        LOG.error("addRoleGrantsHB 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) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 57 with Permission

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

the class AdminMgrImplTest method delRoleGrants.

/**
 * @param rArray
 * @param objArray
 * @param opArray
 */
public static void delRoleGrants(String msg, String[][] rArray, String[][] objArray, String[][] opArray, boolean isAdmin) {
    LogUtil.logIt(msg);
    Permission pOp = new Permission();
    Role role = new Role();
    try {
        AdminMgr adminMgr;
        if (isAdmin) {
            adminMgr = getManagedAdminMgr();
        } else {
            adminMgr = AdminMgrFactory.createInstance(TestUtils.getContext());
        }
        for (String[] rle : rArray) {
            for (String[] obj : objArray) {
                for (String[] op : opArray) {
                    role = new Role(RoleTestData.getName(rle));
                    pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                    adminMgr.revokePermission(pOp, role);
                    LOG.debug("delRoleGrants role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("delRoleGrants role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] 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) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 58 with Permission

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

the class AdminMgrImplTest method delPermOps.

/**
 * @param objArray
 * @param opArray
 */
public static void delPermOps(String msg, String[][] objArray, String[][] opArray, boolean isAdmin, boolean canFail) {
    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.deletePermission(pOp);
                LOG.debug("delPermOps objName [" + pOp.getObjName() + "] opName [" + pOp.getOpName() + "]  objectId [" + pOp.getObjId() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        if (!canFail) {
            LOG.error("delPermOps 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)

Example 59 with Permission

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

the class AdminMgrImplTest method delRoleGrantsHB.

/**
 * @param msg
 * @param rArray
 * @param objArray
 * @param opArray
 */
private void delRoleGrantsHB(String msg, String[][] uArray, String[][] rArray, String[][] objArray, String[][] opArray) {
    LogUtil.logIt(msg);
    try {
        AdminMgr adminMgr = getManagedAdminMgr();
        for (String[] obj : objArray) {
            int i = 0;
            for (String[] rle : rArray) {
                // Get Role[i] from test data:
                Role role = RoleTestData.getRole(rle);
                // Get Permission[i] from test data:
                String[] op = opArray[i];
                // Load the permission entity with data:
                Permission pOp = PermTestData.getOp(PermTestData.getName(obj), op);
                // Grant Permission[i] to Role[i]:
                adminMgr.revokePermission(pOp, role);
                // Get User[i] from test data:
                String[] usr = uArray[i];
                // Load the User entity with data:
                User user = UserTestData.getUser(usr);
                // Grant Permission[i] to User[i]:
                adminMgr.revokePermission(pOp, user);
                i++;
                LOG.debug("delRoleGrantsHB userId [" + user.getUserId() + "] role name [" + role.getName() + "] objName [" + pOp.getObjName() + "] objectId [" + pOp.getObjId() + "] operation name [" + pOp.getOpName() + "] successful");
            }
        }
    } catch (SecurityException ex) {
        LOG.error("delRoleGrantsHB 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) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint) AdminMgr(org.apache.directory.fortress.core.AdminMgr)

Example 60 with Permission

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

the class DelegatedMgrImplTest method checkAccess.

public static void checkAccess(String msg, String[][] uArray, String[][] oArray, String[][] opArray, String[][] oArrayBad, String[][] opArrayBad) {
    LogUtil.logIt(msg);
    try {
        DelAccessMgr dAccessMgr = DelAccessMgrFactory.createInstance(TestUtils.getContext());
        AccessMgr accessMgr = (AccessMgr) dAccessMgr;
        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) {
                    // Call checkAccess method
                    assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "]", dAccessMgr.checkAccess(session, new Permission(PermTestData.getName(obj), PermTestData.getName(op))));
                    j++;
                }
                i++;
            }
            i = 0;
            for (String[] obj : oArrayBad) {
                int j = 0;
                for (String[] op : opArrayBad) {
                    // Call checkAccess method (this should fail):
                    try {
                        boolean result = dAccessMgr.checkAccess(session, new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j])));
                        assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(oArrayBad[i]) + "] operationName [" + PermTestData.getName(opArrayBad[j]) + "]", !result);
                    } catch (SecurityException se) {
                        // The expected condition is security exception perm not exist:
                        assertTrue(CLS_NM + ".checkAccess failed userId [" + user.getUserId() + "] Perm objName [" + PermTestData.getName(oArrayBad[i]) + "] operationName [" + PermTestData.getName(opArrayBad[j]) + "], negative use case, incorrect exception id=" + se.getErrorId(), se.getErrorId() == GlobalErrIds.PERM_NOT_EXIST);
                    }
                    j++;
                }
                i++;
            }
        }
        LOG.debug("checkAccess successful");
    } catch (SecurityException ex) {
        LOG.error("checkAccess: caught SecurityException rc=" + ex.getErrorId() + ", msg: " + ex.getMessage(), ex);
        fail(ex.getMessage());
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) DelAccessMgr(org.apache.directory.fortress.core.DelAccessMgr) AccessMgr(org.apache.directory.fortress.core.AccessMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) DelAccessMgr(org.apache.directory.fortress.core.DelAccessMgr) Session(org.apache.directory.fortress.core.model.Session)

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