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());
}
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);
}
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;
}
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();
}
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();
}
Aggregations