Search in sources :

Example 11 with AccelMgr

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

the class TestAccelerator method testDeleteSession.

@Test
public void testDeleteSession() {
    LOG.info("testDeleteSession...");
    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.deleteSession(session);
    } catch (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)

Example 12 with AccelMgr

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

the class TestAccelerator method testCombinedCalls.

@Test
public void testCombinedCalls() {
    LOG.info("testCombinedCalls...");
    try {
        AccelMgr accelMgr = AccelMgrFactory.createInstance(TestUtils.getContext());
        Session session;
        User user = new User();
        // positive test case:
        user.setUserId("rbacuser1");
        user.setPassword("secret");
        session = accelMgr.createSession(user, false);
        // positive test case:
        Permission perm = new Permission();
        perm.setObjName("/impl/cal2.jsp");
        perm.setOpName("8am");
        boolean result = accelMgr.checkAccess(session, perm);
        assertTrue(result);
        // drop role1:
        UserRole userRole = new UserRole(user.getUserId(), "rbacrole1");
        accelMgr.dropActiveRole(session, userRole);
        // this should return false:
        result = accelMgr.checkAccess(session, perm);
        assertTrue(!result);
        // now add role1 back again:
        userRole = new UserRole(user.getUserId(), "rbacrole1");
        accelMgr.addActiveRole(session, userRole);
        // this should return true:
        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) UserRole(org.apache.directory.fortress.core.model.UserRole) 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)

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