Search in sources :

Example 6 with AccelMgr

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

the class TestAccelerator method testDropActiveRole.

@Test
public void testDropActiveRole() {
    LOG.info("testDropActiveRole...");
    // AcceleratorDAO aDao = new org.apache.directory.fortress.core.impl.AcceleratorDAO();
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        Session session;
        User user = new User();
        // positive test case:
        user.setUserId("rbacuser1");
        user.setPassword("secret");
        // user.setRole( "rbacrole1" );
        // user.setRole( "rbacrole2" );
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        assertTrue(session.isAuthenticated());
        UserRole userRole = new UserRole(user.getUserId(), "rbacrole2");
        accelMgr.dropActiveRole(session, userRole);
    } catch (SecurityException se) {
        se.printStackTrace();
        fail();
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccelMgr(org.apache.directory.fortress.core.AccelMgr) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session) Test(org.junit.Test)

Example 7 with AccelMgr

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

the class AccelMgrImplTest method dropActiveRoles.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void dropActiveRoles(String msg, String[][] uArray, String[][] rArray) {
    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);
            // remove all roles from the user's session:
            for (String[] rle : rArray) {
                // Drop Role:
                accelMgr.dropActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(rle)));
                // session)
                try {
                    // Drop Role3 (this better fail):
                    accelMgr.dropActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(rle)));
                    String error = "dropActiveRoles failed negative test 2 User [" + user.getUserId() + "] Role [" + RoleTestData.getName(rle) + "]";
                    LOG.info(error);
                    fail(error);
                } catch (SecurityException se) {
                    assertTrue("dropActiveRoles excep id check", se.getErrorId() == GlobalErrIds.URLE_NOT_ACTIVE);
                }
            }
            accelMgr.deleteSession(session);
        }
    } catch (SecurityException ex) {
        LOG.error("dropActiveRoles: 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) UserRole(org.apache.directory.fortress.core.model.UserRole) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 8 with AccelMgr

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

the class AccelMgrImplTest method createSessionsWithRoles.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessionsWithRoles(String msg, String[][] uArray, String[][] rArray) {
    LogUtil.logIt(msg);
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        for (String[] usr : uArray) {
            User user = UserTestData.getUser(usr);
            List<UserRole> rlsRequested = new ArrayList<>();
            int cnt = 0;
            for (String[] rle : rArray) {
                rlsRequested.add(RoleTestData.getUserRole(user.getUserId(), rle));
                user.setRoles(rlsRequested);
                Session session = accelMgr.createSession(user, false);
                assertTrue(CLS_NM + ".createSessionsWithRoles failed role search USER [" + user.getUserId() + "]" + " CNT [" + ++cnt + "] size [" + session.getRoles().size() + "]", cnt == session.getRoles().size());
                accelMgr.deleteSession(session);
            }
        }
        LOG.debug("createSessionsWithRoles successful");
    } catch (SecurityException ex) {
        LOG.error("createSessionsWithRoles: 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) UserRole(org.apache.directory.fortress.core.model.UserRole) ArrayList(java.util.ArrayList) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 9 with AccelMgr

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

Example 10 with AccelMgr

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

the class TestAccelerator method testCreateSession.

@Test
public void testCreateSession() {
    LOG.info("testCreateSession...");
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        Session session;
        User user = new User();
        // positive test case:
        user.setUserId("rbacuser1");
        user.setPassword("secret");
        user.setRoleName("rbacrole1");
        user.setRoleName("rbacrole2");
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        assertTrue(session.isAuthenticated());
        try {
            // negative test case:
            user.setUserId("rbacuser1");
            user.setPassword("secretx");
            session = null;
            session = accelMgr.createSession(user, false);
            fail("failed negative createSession for rbacuser1");
        } catch (SecurityException se) {
        // sucess
        }
        // negative case should leave the session null.
        assertNull(session);
    } catch (SecurityException se) {
        se.printStackTrace();
        fail();
    }
}
Also used : User(org.apache.directory.fortress.core.model.User) AccelMgr(org.apache.directory.fortress.core.AccelMgr) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session) Test(org.junit.Test)

Aggregations

AccelMgr (org.apache.directory.fortress.core.AccelMgr)12 SecurityException (org.apache.directory.fortress.core.SecurityException)12 Session (org.apache.directory.fortress.core.model.Session)12 User (org.apache.directory.fortress.core.model.User)12 UserRole (org.apache.directory.fortress.core.model.UserRole)6 Test (org.junit.Test)6 Permission (org.apache.directory.fortress.core.model.Permission)3 ArrayList (java.util.ArrayList)1