Search in sources :

Example 11 with RequestData

use of org.simbasecurity.api.service.thrift.RequestData in project simba-os by cegeka.

the class SimbaGatewayTest method login_WhenActionDescriptorActionTypesIsEmpty_ThenReturnsEmptySSOToken.

@Test
public void login_WhenActionDescriptorActionTypesIsEmpty_ThenReturnsEmptySSOToken() 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().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 12 with RequestData

use of org.simbasecurity.api.service.thrift.RequestData in project simba-os by cegeka.

the class SimbaGatewayTest method login_WhenActionDescriptorActionTypesIsNull_ThenReturnsEmptySSOToken.

@Test
public void login_WhenActionDescriptorActionTypesIsNull_ThenReturnsEmptySSOToken() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().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 RequestData

use of org.simbasecurity.api.service.thrift.RequestData 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 14 with RequestData

use of org.simbasecurity.api.service.thrift.RequestData 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 15 with RequestData

use of org.simbasecurity.api.service.thrift.RequestData 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)

Aggregations

RequestData (org.simbasecurity.api.service.thrift.RequestData)22 Test (org.junit.Test)15 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)14 THttpClient (org.apache.thrift.transport.THttpClient)12 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)9 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)9 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)8 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)7 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)5 AuthenticationFilterService (org.simbasecurity.api.service.thrift.AuthenticationFilterService)4 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)3 TProtocol (org.apache.thrift.protocol.TProtocol)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3 RequestDataBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests)3 IOException (java.io.IOException)2 RequestActionFactory (org.simbasecurity.common.filter.action.RequestActionFactory)2 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)2 UserPrincipal (com.sun.security.auth.UserPrincipal)1 Principal (java.security.Principal)1 ServletContext (javax.servlet.ServletContext)1