Search in sources :

Example 1 with AccelMgr

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

the class AccelMgrImplTest method createSessions.

/**
 * @param msg
 * @param uArray
 * @param rArray
 */
public static void createSessions(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);
            accelMgr.deleteSession(session);
            // now try negative test case:
            try {
                User userBad = new User(user.getUserId(), "badpw");
                accelMgr.createSession(userBad, false);
                fail(CLS_NM + ".createSessions failed negative test");
            } catch (SecurityException se) {
                assertTrue(CLS_NM + "createSessions excep id check", se.getErrorId() == GlobalErrIds.USER_PW_INVLD);
            // pass
            }
        }
        LOG.debug("createSessions successful");
    } catch (SecurityException ex) {
        LOG.error("createSessions: 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) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 2 with AccelMgr

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

the class AccelMgrImplTest method addActiveRoles.

/**
 * @param msg
 * @param uArray
 * @param rPosArray
 * @param rNegArray
 */
public static void addActiveRoles(String msg, String[][] uArray, String[][] rPosArray, String[][] rNegArray) {
    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);
            // Attempt to activate roles that aren't assigned to user:
            for (String[] badRle : rNegArray) {
                try {
                    // Add Role (this better fail):
                    accelMgr.addActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(badRle)));
                    String error = "addActiveRoles failed negative test 1 User [" + user.getUserId() + "] Role [" + RoleTestData.getName(badRle) + "]";
                    LOG.info(error);
                    fail(error);
                } catch (SecurityException se) {
                    assertTrue(CLS_NM + "addActiveRoles excep id check", se.getErrorId() == GlobalErrIds.URLE_ACTIVATE_FAILED);
                // pass
                }
            }
            // remove all roles from the user's session:
            int ctr = rPosArray.length;
            for (String[] rle : rPosArray) {
                // 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 = "addActiveRoles failed negative test 2 User [" + user.getUserId() + "] Role [" + RoleTestData.getName(rle) + "]";
                    LOG.info(error);
                    fail(error);
                } catch (SecurityException se) {
                    assertTrue(CLS_NM + "addActiveRoles excep id check", se.getErrorId() == GlobalErrIds.URLE_NOT_ACTIVE);
                }
            }
            // Now activate the list of assigned roles:
            ctr = 0;
            for (String[] rle : rPosArray) {
                // Activate Role(s):
                accelMgr.addActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(rle)));
                // TODO: this does not work with RAO - fix me.
                try {
                    // Activate Role again (this should throw SecurityException):
                    accelMgr.addActiveRole(session, new UserRole(user.getUserId(), RoleTestData.getName(rle)));
                    String error = "addActiveRoles failed test 3 User [" + user.getUserId() + "] Role [" + RoleTestData.getName(rle) + "]";
                    LOG.info(error);
                    fail(error);
                } catch (SecurityException se) {
                    assertTrue(CLS_NM + "addActiveRoles excep id check", se.getErrorId() == GlobalErrIds.URLE_ALREADY_ACTIVE);
                // this is good
                }
            }
            accelMgr.deleteSession(session);
        }
    } catch (SecurityException ex) {
        LOG.error("addActiveRoles: 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 3 with AccelMgr

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

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

the class TestAccelerator method testAddActiveRole.

// @Test
public void testAddActiveRole() {
    LOG.info("testAddActiveRole...");
    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.setRole( "rbacrole2" );
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        assertTrue(session.isAuthenticated());
        UserRole userRole = new UserRole(user.getUserId(), "rbacrole2");
        accelMgr.addActiveRole(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)

Example 5 with AccelMgr

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

the class TestAccelerator method testSessionRoles.

@Test
public void testSessionRoles() {
    LOG.info("testSessionRoles...");
    User user = new User();
    user.setUserId("rbacuser1");
    user.setPassword("secret");
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        Session session;
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        accelMgr.sessionRoles(session);
    } catch (org.apache.directory.fortress.core.SecurityException se) {
        se.printStackTrace();
    }
}
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