Search in sources :

Example 46 with Permission

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

the class ReviewMgrImplTest method userPermissions.

/**
 * @param msg
 * @param uArray
 * @param pObjArray
 * @param pOpArray
 */
public static void userPermissions(String msg, String[][] uArray, String[][] pObjArray, String[][] pOpArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            List<Permission> perms = reviewMgr.userPermissions(user);
            assertNotNull(perms);
            assertTrue(CLS_NM + "userPermissions list size check", pOpArray.length * pObjArray.length == perms.size());
            for (String[] obj : pObjArray) {
                for (String[] op : pOpArray) {
                    int indx = perms.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
                    if (indx != -1) {
                        Permission pOp = perms.get(indx);
                        assertNotNull(pOp);
                        PermTestData.assertEquals(PermTestData.getName(obj), pOp, op);
                        LOG.debug("userPermissions userId [" + user.getUserId() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] successful");
                    } else {
                        msg = "userPermissions userId [" + user.getUserId() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] failed list search";
                        LogUtil.logIt(msg);
                        fail(msg);
                    }
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("userPermissions 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) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) RoleConstraint(org.apache.directory.fortress.core.model.RoleConstraint)

Example 47 with Permission

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

the class ReviewMgrImplTest method rolePermissions.

/**
 * @param msg
 * @param rArray
 * @param pObjArray
 * @param pOpArray
 */
public static void rolePermissions(String msg, String[][] rArray, String[][] pObjArray, String[][] pOpArray) {
    LogUtil.logIt(msg);
    try {
        ReviewMgr reviewMgr = getManagedReviewMgr();
        for (String[] rle : rArray) {
            Role role = RoleTestData.getRole(rle);
            List<Permission> perms = reviewMgr.rolePermissions(role);
            assertNotNull(perms);
            assertTrue(CLS_NM + "rolePermissions list size check", pOpArray.length * pObjArray.length == perms.size());
            for (String[] obj : pObjArray) {
                for (String[] op : pOpArray) {
                    int indx = perms.indexOf(new Permission(PermTestData.getName(obj), PermTestData.getName(op), PermTestData.getObjId(op)));
                    if (indx != -1) {
                        Permission pOp = perms.get(indx);
                        assertNotNull(pOp);
                        PermTestData.assertEquals(PermTestData.getName(obj), pOp, op);
                        LOG.debug("rolePermissions role name [" + role.getName() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] successful");
                    } else {
                        msg = "rolePermissions role name [" + role.getName() + "] perm objName [" + PermTestData.getName(obj) + "] operationName [" + PermTestData.getName(op) + "] failed list search";
                        LogUtil.logIt(msg);
                        fail(msg);
                    }
                }
            }
        }
    } catch (SecurityException ex) {
        LOG.error("rolePermissions 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) 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 48 with Permission

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

the class TestAccelerator method testCheckAccess.

@Test
public void testCheckAccess() {
    AccelMgr accelMgr = null;
    LOG.info("testCheckAccess...");
    User user = new User();
    user.setUserId("rbacuser1");
    user.setPassword("secret");
    // user.setRole( "rbacrole1" );
    // user.setRole( "rbacrole2" );
    Session session = null;
    try {
        accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
    } catch (SecurityException se) {
        se.printStackTrace();
        fail();
    }
    try {
        // positive test case:
        Permission perm = new Permission();
        perm.setObjName("/impl/cal2.jsp");
        // perm.setObjId( "123456" );
        perm.setOpName("8am");
        boolean result = accelMgr.checkAccess(session, perm);
        assertTrue(result);
        // negative test case:
        perm.setOpName("9am");
        result = accelMgr.checkAccess(session, perm);
        assertTrue(!result);
    } catch (SecurityException se) {
        se.printStackTrace();
        fail();
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccelMgr(org.apache.directory.fortress.core.AccelMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session) Test(org.junit.Test)

Example 49 with Permission

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

the class Options method getPermission.

public Permission getPermission() {
    Permission perm = new Permission();
    perm.setObjName(getName());
    perm.setOpName(getOpName());
    updateRoleAssigns(perm);
    updateProperties(perm);
    perm.setType(getType());
    return perm;
}
Also used : Permission(org.apache.directory.fortress.core.model.Permission)

Example 50 with Permission

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

the class AccelMgrImplTest method checkAccess.

/**
 * @param msg
 * @param uArray
 * @param oArray
 * @param opArray
 * @param oArrayBad
 * @param opArrayBad
 */
public static void checkAccess(String msg, String[][] uArray, String[][] oArray, String[][] opArray, String[][] oArrayBad, String[][] opArrayBad) {
    LogUtil.logIt(msg);
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            Session session = accelMgr.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) + "]", accelMgr.checkAccess(session, goodPerm));
                    Permission badPerm = new Permission(PermTestData.getName(oArrayBad[i]), PermTestData.getName(opArrayBad[j]), PermTestData.getObjId(opArrayBad[j]));
                    // 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]) + "]", accelMgr.checkAccess(session, badPerm));
                    j++;
                }
                i++;
            }
            accelMgr.deleteSession(session);
        }
        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) AccelMgr(org.apache.directory.fortress.core.AccelMgr) Permission(org.apache.directory.fortress.core.model.Permission) SecurityException(org.apache.directory.fortress.core.SecurityException) 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