Search in sources :

Example 36 with Session

use of org.apache.directory.fortress.core.model.Session 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 37 with Session

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

Example 38 with Session

use of org.apache.directory.fortress.core.model.Session 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 39 with Session

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

the class AccelCreateSession method runTest.

/**
 * Description of the Method
 *
 * @param samplerContext Description of the Parameter
 * @return Description of the Return Value
 */
public SampleResult runTest(JavaSamplerContext samplerContext) {
    SampleResult sampleResult = new SampleResult();
    try {
        sampleResult.sampleStart();
        // String message = "FT CreateSession TID: " + getThreadId() + " UID:" + userId + " CTR:" + ctr++;
        // LOG.info( message );
        // System.out.println( message );
        assertNotNull(accelMgr);
        Session session;
        User user = new User();
        // positive test case:
        user.setUserId(userId);
        user.setPassword("secret");
        session = accelMgr.createSession(user, false);
        assertNotNull(session);
        assertTrue(session.isAuthenticated());
        sampleResult.sampleEnd();
        sampleResult.setBytes(1);
        sampleResult.setResponseMessage("AC test completed TID: " + getThreadId() + " UID: " + userId);
        sampleResult.setSuccessful(true);
    } catch (org.apache.directory.fortress.core.SecurityException se) {
        System.out.println("ThreadId:" + getThreadId() + "Error running test: " + se);
        se.printStackTrace();
        sampleResult.setSuccessful(false);
    }
    return sampleResult;
}
Also used : org.apache.directory.fortress.core(org.apache.directory.fortress.core) User(org.apache.directory.fortress.core.model.User) SampleResult(org.apache.jmeter.samplers.SampleResult) SecurityException(org.apache.directory.fortress.core.SecurityException) Session(org.apache.directory.fortress.core.model.Session)

Example 40 with Session

use of org.apache.directory.fortress.core.model.Session in project cas by apereo.

the class FortressAuthenticationHandlerTests method verifyAuthenticateSuccessfully.

@Test
public void verifyAuthenticateSuccessfully() throws Exception {
    val sessionId = UUID.randomUUID();
    val session = new Session(new User(CoreAuthenticationTestUtils.CONST_USERNAME), sessionId.toString());
    session.setAuthenticated(true);
    when(accessManager.createSession(ArgumentMatchers.any(User.class), ArgumentMatchers.anyBoolean())).thenReturn(session);
    val handlerResult = fortressAuthenticationHandler.authenticateUsernamePasswordInternal(CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword(), null);
    assertEquals(CoreAuthenticationTestUtils.CONST_USERNAME, handlerResult.getPrincipal().getId());
    val jaxbContext = JAXBContext.newInstance(Session.class);
    val marshaller = jaxbContext.createMarshaller();
    val writer = new StringWriter();
    marshaller.marshal(session, writer);
    assertEquals(writer.toString(), handlerResult.getPrincipal().getAttributes().get(FortressAuthenticationHandler.FORTRESS_SESSION_KEY).get(0));
}
Also used : lombok.val(lombok.val) User(org.apache.directory.fortress.core.model.User) StringWriter(java.io.StringWriter) Session(org.apache.directory.fortress.core.model.Session) Test(org.junit.jupiter.api.Test)

Aggregations

Session (org.apache.directory.fortress.core.model.Session)70 SecurityException (org.apache.directory.fortress.core.SecurityException)62 User (org.apache.directory.fortress.core.model.User)51 AccessMgr (org.apache.directory.fortress.core.AccessMgr)32 UserRole (org.apache.directory.fortress.core.model.UserRole)28 AccelMgr (org.apache.directory.fortress.core.AccelMgr)12 Permission (org.apache.directory.fortress.core.model.Permission)12 FortRequest (org.apache.directory.fortress.core.model.FortRequest)10 FortResponse (org.apache.directory.fortress.core.model.FortResponse)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 DelAccessMgr (org.apache.directory.fortress.core.DelAccessMgr)4 UserAdminRole (org.apache.directory.fortress.core.model.UserAdminRole)4 PasswordException (org.apache.directory.fortress.core.PasswordException)3 lombok.val (lombok.val)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 org.apache.directory.fortress.core (org.apache.directory.fortress.core)2 AdminRole (org.apache.directory.fortress.core.model.AdminRole)2 ObjectFactory (org.apache.directory.fortress.core.model.ObjectFactory)2 Role (org.apache.directory.fortress.core.model.Role)2