Search in sources :

Example 6 with State

use of org.simbasecurity.core.chain.Command.State in project simba-os by cegeka.

the class CheckPasswordExpiredCommandTest method testExecute_mustChangePasswordAndRequestIsDirectlyToSimba_redirectToChangePasswordWithSuccesURLAsTarget.

@Test
public void testExecute_mustChangePasswordAndRequestIsDirectlyToSimba_redirectToChangePasswordWithSuccesURLAsTarget() throws Exception {
    when(credentialServiceMock.mustChangePasswordOnNextLogon(USER_NAME)).thenReturn(Boolean.TRUE);
    when(credentialServiceMock.getSuccessURL(USER_NAME)).thenReturn("successURL");
    when(contextMock.getRequestURL()).thenReturn("requestURL");
    when(contextMock.getSimbaWebURL()).thenReturn("simbaWebURL");
    State state = command.execute(contextMock);
    assertEquals(State.FINISH, state);
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.AUTHENTICATION, resultAuditLogEvent.getCategory());
    assertEquals(MUST_CHANGE_PASSWORD, resultAuditLogEvent.getMessage());
    verify(contextMock).redirectToChangePasswordWithFilter();
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) State(org.simbasecurity.core.chain.Command.State) Test(org.junit.Test)

Example 7 with State

use of org.simbasecurity.core.chain.Command.State in project simba-os by cegeka.

the class LogoutCommandTest method onLogoutRequestRemoveSessionAndRedirectAndDeleteCookie.

@Test
public void onLogoutRequestRemoveSessionAndRedirectAndDeleteCookie() throws Exception {
    SSOToken sSOToken = new SSOToken("token");
    when(chainContext.getUserName()).thenReturn(USERNAME);
    when(chainContext.getClientIpAddress()).thenReturn(CLIENT_IP);
    when(chainContext.isLogoutRequest()).thenReturn(true);
    Session sessionMock = mock(Session.class);
    when(chainContext.getCurrentSession()).thenReturn(sessionMock);
    when(chainContext.getRequestSSOToken()).thenReturn(sSOToken);
    State state = logoutCommand.execute(chainContext);
    assertEquals(State.FINISH, state);
    verify(sessionService).removeSession(isA(Session.class));
    verify(chainContext).activateAction(ActionType.DELETE_COOKIE);
    verify(chainContext).redirectToLogout();
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.SESSION, resultAuditLogEvent.getCategory());
    assertEquals(AuditMessages.SUCCESS + AuditMessages.LOGGED_OUT + ": SSOToken=" + sSOToken, resultAuditLogEvent.getMessage());
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) State(org.simbasecurity.core.chain.Command.State) Session(org.simbasecurity.core.domain.Session) Test(org.junit.Test)

Example 8 with State

use of org.simbasecurity.core.chain.Command.State in project simba-os by cegeka.

the class CreateEIDUserCommandTest method execute_UpdateExistingUser.

@Test
public void execute_UpdateExistingUser() throws Exception {
    User user = new UserEntity(INSZ);
    when(chainContextMock.getSAMLUser()).thenReturn(samlUser);
    when(userServiceMock.findByName(INSZ)).thenReturn(user);
    State state = createEIDUserCommand.execute(chainContextMock);
    assertEquals(State.CONTINUE, state);
    verify(chainContextMock).setUserPrincipal(INSZ);
    assertEquals(INSZ, user.getUserName());
    assertEquals(FIRSTNAME, user.getFirstName());
    assertEquals(LASTNAME, user.getName());
    assertEquals(Language.fromISO639Code(NL), user.getLanguage());
}
Also used : User(org.simbasecurity.core.domain.User) State(org.simbasecurity.core.chain.Command.State) UserEntity(org.simbasecurity.core.domain.UserEntity) Test(org.junit.Test)

Example 9 with State

use of org.simbasecurity.core.chain.Command.State in project simba-os by cegeka.

the class ChangePasswordCommandTest method testPasswordChangeDuringSessionRedirectToPasswordChanged.

@Test
public void testPasswordChangeDuringSessionRedirectToPasswordChanged() throws Exception {
    Session sessionMock = mock(Session.class);
    when(chainContextMock.getCurrentSession()).thenReturn(sessionMock);
    when(chainContextMock.isChangePasswordRequest()).thenReturn(Boolean.TRUE);
    when(chainContextMock.getUserName()).thenReturn(USERNAME);
    when(chainContextMock.getClientIpAddress()).thenReturn(IP_ADDRESS);
    when(chainContextMock.getRequestParameter(AuthenticationConstants.PASSWORD)).thenReturn(OLD_PASSWORD);
    when(chainContextMock.getRequestParameter(AuthenticationConstants.NEW_PASSWORD)).thenReturn(NEW_PASSWORD);
    State state = command.execute(chainContextMock);
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.SESSION, resultAuditLogEvent.getCategory());
    assertEquals(AuditMessages.SUCCESS + AuditMessages.PASSWORD_CHANGED, resultAuditLogEvent.getMessage());
    verify(chainContextMock).redirectToPasswordChanged();
    assertEquals(State.FINISH, state);
}
Also used : State(org.simbasecurity.core.chain.Command.State) Session(org.simbasecurity.core.domain.Session) Test(org.junit.Test)

Example 10 with State

use of org.simbasecurity.core.chain.Command.State in project simba-os by cegeka.

the class CheckClientIPCommandTest method continueWithoutActionsIfClientIpEqualsIpStoredInSession.

@Test
public void continueWithoutActionsIfClientIpEqualsIpStoredInSession() throws Exception {
    when(sessionMock.getClientIpAddress()).thenReturn(IP_ADDRESS);
    State state = command.execute(chainContextMock);
    verify(chainContextMock, times(0)).activateAction(isA(ActionType.class));
    assertEquals(State.CONTINUE, state);
}
Also used : ActionType(org.simbasecurity.api.service.thrift.ActionType) State(org.simbasecurity.core.chain.Command.State) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)20 State (org.simbasecurity.core.chain.Command.State)20 AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)7 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)2 Session (org.simbasecurity.core.domain.Session)2 User (org.simbasecurity.core.domain.User)2 ActionType (org.simbasecurity.api.service.thrift.ActionType)1 Command (org.simbasecurity.core.chain.Command)1 UserEntity (org.simbasecurity.core.domain.UserEntity)1 SimbaException (org.simbasecurity.core.exception.SimbaException)1