Search in sources :

Example 6 with AuditLogEvent

use of org.simbasecurity.core.audit.AuditLogEvent 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 7 with AuditLogEvent

use of org.simbasecurity.core.audit.AuditLogEvent in project simba-os by cegeka.

the class JaasLoginCommandTest method failedLogin_IncreasesInvalidLoginCount.

@Test
public void failedLogin_IncreasesInvalidLoginCount() throws Exception {
    TestLoginModule.setValues(false, true, false, false);
    when(credentialServiceMock.checkUserStatus(USER_NAME, Status.ACTIVE)).thenReturn(true);
    assertEquals(State.FINISH, jaasLoginCommand.execute(contextMock));
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.AUTHENTICATION, resultAuditLogEvent.getCategory());
    verify(contextMock).redirectWithCredentialError(SimbaMessageKey.LOGIN_FAILED);
    verify(credentialServiceMock).increaseInvalidLoginCountAndBlockAccount(USER_NAME);
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Test(org.junit.Test)

Example 8 with AuditLogEvent

use of org.simbasecurity.core.audit.AuditLogEvent in project simba-os by cegeka.

the class ValidateRequestParametersCommandTest method testExecute_EMPTY_PASSWORD.

@Test
public void testExecute_EMPTY_PASSWORD() throws Exception {
    when(contextMock.getRequestParameter(AuthenticationConstants.PASSWORD)).thenReturn(null);
    assertEquals(State.FINISH, command.execute(contextMock));
    verify(contextMock).redirectWithCredentialError(SimbaMessageKey.EMPTY_PASSWORD);
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.AUTHENTICATION, resultAuditLogEvent.getCategory());
    assertEquals(FAILURE + EMPTY_PASSWORD, resultAuditLogEvent.getMessage());
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Test(org.junit.Test)

Example 9 with AuditLogEvent

use of org.simbasecurity.core.audit.AuditLogEvent in project simba-os by cegeka.

the class ValidateRequestParametersCommandTest method testExecute.

@Test
public void testExecute() throws Exception {
    assertEquals(State.CONTINUE, command.execute(contextMock));
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.AUTHENTICATION, resultAuditLogEvent.getCategory());
    assertEquals(SUCCESS + VALID_REQUEST_PARAM, resultAuditLogEvent.getMessage());
}
Also used : AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Test(org.junit.Test)

Example 10 with AuditLogEvent

use of org.simbasecurity.core.audit.AuditLogEvent in project simba-os by cegeka.

the class URLRuleCheckCommandTest method redirectWhenAccessIsDisallowed.

@Test
public void redirectWhenAccessIsDisallowed() throws Exception {
    when(authorizationServiceMock.isURLRuleAllowed(USERNAME, REQUEST_URL, REQUEST_METHOD)).thenReturn(new PolicyDecision(false, Long.MAX_VALUE));
    assertEquals(State.FINISH, command.execute(contextMock));
    verify(auditMock).log(captor.capture());
    AuditLogEvent resultAuditLogEvent = captor.getValue();
    assertEquals(AuditLogEventCategory.AUTHOR, resultAuditLogEvent.getCategory());
    assertEquals(AuditMessages.FAILURE + AuditMessages.ACCESS_DENIED + REQUEST_URL, resultAuditLogEvent.getMessage());
    verify(contextMock).redirectToAccessDenied();
}
Also used : PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) AuditLogEvent(org.simbasecurity.core.audit.AuditLogEvent) Test(org.junit.Test)

Aggregations

AuditLogEvent (org.simbasecurity.core.audit.AuditLogEvent)36 Test (org.junit.Test)32 Command (org.simbasecurity.core.chain.Command)9 User (org.simbasecurity.core.domain.User)8 State (org.simbasecurity.core.chain.Command.State)6 UserTestBuilder.aDefaultUser (org.simbasecurity.core.domain.UserTestBuilder.aDefaultUser)6 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)4 Token (org.simbasecurity.core.domain.communication.token.Token)3 URL (java.net.URL)2 PolicyDecision (org.simbasecurity.api.service.thrift.PolicyDecision)2 Session (org.simbasecurity.core.domain.Session)2 EmailAddress (org.simbasecurity.core.domain.user.EmailAddress)2 TemplateWithLinks (org.simbasecurity.core.service.communication.mail.template.TemplateWithLinks)2 Optional (java.util.Optional)1 Audit (org.simbasecurity.core.audit.Audit)1 AuditLogEventFactory (org.simbasecurity.core.audit.AuditLogEventFactory)1 ChainContext (org.simbasecurity.core.chain.ChainContext)1 CONTINUE (org.simbasecurity.core.chain.Command.State.CONTINUE)1 FINISH (org.simbasecurity.core.chain.Command.State.FINISH)1 UserTestBuilder.aUser (org.simbasecurity.core.domain.UserTestBuilder.aUser)1