Search in sources :

Example 11 with Session

use of org.simbasecurity.core.domain.Session in project simba-os by cegeka.

the class SessionServiceImplTest method testPurgeExpiredSessions.

@Test
public void testPurgeExpiredSessions() {
    Session expiredSession = createSessionMock(true);
    Session unexpiredSession = createSessionMock(false);
    when(sessionRepository.findAll()).thenReturn(Arrays.asList(expiredSession, unexpiredSession));
    service.purgeExpiredSessions();
    verify(sessionRepository).remove(expiredSession);
    verify(sessionRepository, never()).remove(unexpiredSession);
    verify(audit).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.SESSION, resultAuditLogEvent.getCategory());
    assertEquals("Purged expired session", resultAuditLogEvent.getMessage());
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Session(org.simbasecurity.core.domain.Session) Test(org.junit.Test)

Example 12 with Session

use of org.simbasecurity.core.domain.Session in project simba-os by cegeka.

the class UserServiceTest method setup.

@Before
public void setup() {
    changePasswordDTO = new ChangePasswordDTO();
    changePasswordDTO.setUserName(userName);
    changePasswordDTO.setNewPassword(newPassword);
    changePasswordDTO.setNewPasswordConfirmation(newPasswordConfirmation);
    Session aSession = mock(Session.class);
    when(sessionRepository.findBySSOToken(ssoToken)).thenReturn(aSession);
    correspondingUser = mock(User.class);
    when(aSession.getUser()).thenReturn(correspondingUser);
    when(userRepository.findByName(userName)).thenReturn(correspondingUser);
    when(correspondingUser.getUserName()).thenReturn(userName);
    responseMock = mock(HttpServletResponse.class);
}
Also used : User(org.simbasecurity.core.domain.User) HttpServletResponse(javax.servlet.http.HttpServletResponse) ChangePasswordDTO(org.simbasecurity.core.service.manager.dto.ChangePasswordDTO) Session(org.simbasecurity.core.domain.Session) Before(org.junit.Before)

Example 13 with Session

use of org.simbasecurity.core.domain.Session in project simba-os by cegeka.

the class CreateSessionCommand method execute.

@Override
public State execute(ChainContext context) throws Exception {
    String targetURL;
    if (context.isLoginUsingJSP()) {
        LoginMapping mapping = context.getLoginMapping();
        if (mapping != null) {
            targetURL = mapping.getTargetURL();
        } else {
            String successURL = credentialService.getSuccessURL(context.getUserName());
            if (StringUtils.isBlank(successURL)) {
                audit.log(auditLogFactory.createEventForAuthenticationForFailure(context, AuditMessages.EMPTY_SUCCESS_URL));
                context.redirectWithCredentialError(SimbaMessageKey.EMPTY_SUCCESS_URL);
                return State.FINISH;
            }
            targetURL = successURL;
        }
    } else if (context.isLoginUsingEID()) {
        targetURL = context.getSimbaEidSuccessUrl();
    } else {
        targetURL = context.getRequestURL();
    }
    Session session = sessionService.createSession(context.getUserName(), context.getClientIpAddress(), context.getHostServerName(), context.getUserAgent(), context.getRequestURL());
    SSOTokenMapping ssoMappingToken = ssoTokenMappingService.createMapping(session.getSSOToken());
    targetURL = RequestUtil.addParametersToUrlAndFilterInternalParameters(targetURL, context.getRequestParameters());
    if (!context.isLoginUsingJSP()) {
        context.activateAction(ActionType.MAKE_COOKIE);
        context.setSSOTokenForActions(session.getSSOToken());
        context.setMappingTokenForActions(ssoMappingToken.getToken());
    } else {
        targetURL = RequestUtil.addParameterToUrl(targetURL, RequestConstants.SIMBA_SSO_TOKEN, ssoMappingToken.getToken());
    }
    context.activateAction(ActionType.REDIRECT);
    context.setRedirectURL(targetURL);
    context.setNewSession(session);
    audit.log(auditLogFactory.createEventForSessionForSuccess(context, AuditMessages.SESSION_CREATED + ": SSOToken=" + session.getSSOToken().getToken()));
    return State.FINISH;
}
Also used : SSOTokenMapping(org.simbasecurity.core.domain.SSOTokenMapping) LoginMapping(org.simbasecurity.core.domain.LoginMapping) Session(org.simbasecurity.core.domain.Session)

Example 14 with Session

use of org.simbasecurity.core.domain.Session in project simba-os by cegeka.

the class CheckSessionCommandTest method redirectWhenInvalidSession.

@Test
public void redirectWhenInvalidSession() throws Exception {
    when(contextMock.getRequestSSOToken()).thenReturn(SSO_TOKEN);
    when(contextMock.getClientIpAddress()).thenReturn(CLIENT_IP);
    Session sessionMock = mock(Session.class);
    when(sessionMock.isExpired()).thenReturn(true);
    when(contextMock.getCurrentSession()).thenReturn(sessionMock);
    assertEquals(State.FINISH, command.execute(contextMock));
    verify(contextMock).redirectToLogin();
}
Also used : Session(org.simbasecurity.core.domain.Session) Test(org.junit.Test)

Example 15 with Session

use of org.simbasecurity.core.domain.Session in project simba-os by cegeka.

the class CheckSessionCommandTest method tokenIsTakenFromCurrentSession_IfMappingProvidedAndSessionExists.

@Test
public void tokenIsTakenFromCurrentSession_IfMappingProvidedAndSessionExists() throws Exception {
    Session sessionMock = mock(Session.class);
    when(contextMock.isSsoTokenMappingKeyProvided()).thenReturn(true);
    when(contextMock.getCurrentSession()).thenReturn(sessionMock);
    command.execute(contextMock);
    verify(sessionMock).getSSOToken();
}
Also used : Session(org.simbasecurity.core.domain.Session) Test(org.junit.Test)

Aggregations

Session (org.simbasecurity.core.domain.Session)17 Test (org.junit.Test)7 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)5 User (org.simbasecurity.core.domain.User)4 TSession (org.simbasecurity.api.service.thrift.TSession)2 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)2 ChainContext (org.simbasecurity.core.chain.ChainContext)2 State (org.simbasecurity.core.chain.Command.State)2 Query (javax.persistence.Query)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 TException (org.apache.thrift.TException)1 Before (org.junit.Before)1 RequestData (org.simbasecurity.api.service.thrift.RequestData)1 TUser (org.simbasecurity.api.service.thrift.TUser)1 ChainImpl (org.simbasecurity.core.chain.ChainImpl)1 Command (org.simbasecurity.core.chain.Command)1 LoginMapping (org.simbasecurity.core.domain.LoginMapping)1 SSOTokenMapping (org.simbasecurity.core.domain.SSOTokenMapping)1 SessionEntity (org.simbasecurity.core.domain.SessionEntity)1 SimbaException (org.simbasecurity.core.exception.SimbaException)1