Search in sources :

Example 11 with State

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

the class ChangePasswordCommandTest method testPasswordReset_passwordNotValid.

@Test
public void testPasswordReset_passwordNotValid() throws Exception {
    String simbaURL = "simbaURL";
    String requestURL = "requestURL";
    when(chainContextMock.getSimbaWebURL()).thenReturn(simbaURL);
    when(chainContextMock.getRequestURL()).thenReturn(requestURL);
    when(chainContextMock.getClientIpAddress()).thenReturn(IP_ADDRESS);
    when(chainContextMock.getUserName()).thenReturn(USERNAME);
    when(chainContextMock.getRequestParameter(AuthenticationConstants.NEW_PASSWORD)).thenReturn(NEW_PASSWORD);
    when(chainContextMock.getRequestParameter(AuthenticationConstants.NEW_PASSWORD_CONFIRMATION)).thenReturn(NEW_PASSWORD);
    doThrow(new SimbaException(PASSWORD_INVALID_LENGTH)).when(credentialServiceMock).changePassword(USERNAME, NEW_PASSWORD, NEW_PASSWORD);
    when(chainContextMock.isChangePasswordRequest()).thenReturn(Boolean.TRUE);
    State state = command.execute(chainContextMock);
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.SESSION, resultAuditLogEvent.getCategory());
    assertEquals(AuditMessages.FAILURE + AuditMessages.PASSWORD_NOT_VALID, resultAuditLogEvent.getMessage());
    verify(chainContextMock).redirectWithCredentialError(PASSWORD_INVALID_LENGTH);
    assertEquals(State.FINISH, state);
}
Also used : SimbaException(org.simbasecurity.core.exception.SimbaException) State(org.simbasecurity.core.chain.Command.State) Test(org.junit.Test)

Example 12 with State

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

the class ChangePasswordCommandTest method testPasswordReset_notPasswordResetRequest.

@Test
public void testPasswordReset_notPasswordResetRequest() throws Exception {
    when(chainContextMock.isChangePasswordRequest()).thenReturn(Boolean.FALSE);
    State state = command.execute(chainContextMock);
    assertEquals(State.CONTINUE, state);
}
Also used : State(org.simbasecurity.core.chain.Command.State) Test(org.junit.Test)

Example 13 with State

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

the class CheckClientIPCommandTest method redirectIfClientIpDifferentFromIpStoredInSession.

@Test
public void redirectIfClientIpDifferentFromIpStoredInSession() throws Exception {
    when(sessionMock.getClientIpAddress()).thenReturn(OTHER_IP_ADDRESS);
    Command.State state = command.execute(chainContextMock);
    assertEquals(State.FINISH, state);
    verify(chainContextMock).redirectToLogin();
}
Also used : State(org.simbasecurity.core.chain.Command.State) Command(org.simbasecurity.core.chain.Command) Test(org.junit.Test)

Example 14 with State

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

the class CheckShowChangePasswordCommandTest method redirectToChangePasswordPageWhenIsShowChangePassword.

@Test
public void redirectToChangePasswordPageWhenIsShowChangePassword() throws Exception {
    when(chainContextMock.isShowChangePasswordRequest()).thenReturn(true);
    State state = command.execute(chainContextMock);
    verify(chainContextMock).redirectToChangePasswordDirect();
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.AUTHENTICATION, resultAuditLogEvent.getCategory());
    assertEquals(REDIRECT_TO_CHANGE_PASSWORD, resultAuditLogEvent.getMessage());
    assertEquals(FINISH, state);
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) State(org.simbasecurity.core.chain.Command.State) Test(org.junit.Test)

Example 15 with State

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

the class EnterApplicationCommandTest method doFilterAndFinishOnExecute.

@Test
public void doFilterAndFinishOnExecute() throws Exception {
    SSOToken ssoToken = new SSOToken();
    when(chainContextMock.getRequestSSOToken()).thenReturn(ssoToken);
    State state = enterApplicationCommand.execute(chainContextMock);
    assertThat(state).isEqualTo(State.FINISH);
    verify(chainContextMock).activateAction(ActionType.DO_FILTER_AND_SET_PRINCIPAL);
    verify(auditLogEventFactory).createEventForAuthenticationForSuccess(chainContextMock, AuditMessages.ENTER_APPLICATION);
    verify(auditMock).log(any(AuditLogEvent.class));
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) 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