Search in sources :

Example 11 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials in project simba-os by cegeka.

the class SimbaGatewayTest method authenticate_WhenAuthenticationCallWentWrong_ThrowsSimbaUnavailableException.

@Test
public void authenticate_WhenAuthenticationCallWentWrong_ThrowsSimbaUnavailableException() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    when(credentials.asRequestData()).thenReturn(requestData);
    Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
    when(authenticationServiceMock.processRequest(requestData, SESSION_AUTHENTICATE_CHAIN)).thenThrow(new TException());
    expectedException.expect(SimbaUnavailableException.class);
    simbaGateway.authenticate(credentials);
}
Also used : TException(org.apache.thrift.TException) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 12 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials in project simba-os by cegeka.

the class SimbaGatewayTest method login_WhenActionDescriptorMissesMAKECOOKIE_ReturnsEmptySSOToken.

@Test
public void login_WhenActionDescriptorMissesMAKECOOKIE_ReturnsEmptySSOToken() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.REDIRECT).build();
    when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> ssoToken = simbaGateway.login(containerRequestMock);
    assertThat(ssoToken.isPresent()).isFalse();
}
Also used : ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 13 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials in project simba-os by cegeka.

the class SimbaAuthenticatorTest method authenticate_WhenConnectionToSimbaFails_ThrowAuthenticationException.

@Test
public void authenticate_WhenConnectionToSimbaFails_ThrowAuthenticationException() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    when(simbaGatewayMock.authenticate(credentials)).thenThrow(new SimbaUnavailableException());
    expectedException.expect(AuthenticationException.class);
    authenticator.authenticate(credentials);
}
Also used : SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) SimbaUnavailableException(org.simbasecurity.dwclient.exception.SimbaUnavailableException) Test(org.junit.Test)

Example 14 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials in project simba-os by cegeka.

the class SimbaGatewayTest method login.

@Test
public void login() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    SSOToken expectedSSOToken = new SSOToken("token");
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(expectedSSOToken).build();
    when(simbaCredentialsFactoryMock.create(containerRequestMock, false)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> actualSSOToken = simbaGateway.login(containerRequestMock);
    assertThat(actualSSOToken.isPresent()).isTrue();
    assertThat(actualSSOToken.get()).isEqualTo(expectedSSOToken.getToken());
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 15 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials in project simba-os by cegeka.

the class SimbaGatewayTest method authenticate_WhenClientIsABrowser_ExecuteBrowserLoginChain.

@Test
public void authenticate_WhenClientIsABrowser_ExecuteBrowserLoginChain() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    when(credentials.isClientABrowser()).thenReturn(true);
    Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
    simbaGateway.authenticate(credentials);
    verify(authenticationServiceMock).processRequest(any(RequestData.class), eq(SimbaGateway.SESSION_AUTHENTICATE_CHAIN));
}
Also used : SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Aggregations

SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)16 Test (org.junit.Test)13 THttpClient (org.apache.thrift.transport.THttpClient)11 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)11 RequestData (org.simbasecurity.api.service.thrift.RequestData)11 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)7 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)7 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)7 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)5 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)4 AuthenticationException (com.yammer.dropwizard.auth.AuthenticationException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 TException (org.apache.thrift.TException)1 SimbaAuthenticator (org.simbasecurity.dwclient.dropwizard.authenticator.SimbaAuthenticator)1 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)1 SimbaCredentialsFactory (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsFactory)1 SimbaAuthenticatedProvider (org.simbasecurity.dwclient.dropwizard.provider.SimbaAuthenticatedProvider)1 SimbaUnavailableException (org.simbasecurity.dwclient.exception.SimbaUnavailableException)1