Search in sources :

Example 6 with RequestData

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

the class SimbaGatewayTest method login_WithUsernameAndPassword.

@Test
public void login_WithUsernameAndPassword() throws Exception {
    String username = "appUser";
    String password = "appPassword";
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    SSOToken ssoToken = new SSOToken("token");
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.MAKE_COOKIE).withSsoToken(ssoToken).build();
    when(simbaCredentialsFactoryMock.createForLogin(username, password)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    when(authenticationServicemock.processRequest(requestData, LOGIN_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<String> actual = simbaGateway.login(username, password);
    assertThat(actual.get()).isEqualTo(ssoToken.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) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 7 with RequestData

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

the class SimbaGatewayTest method authenticate_WhenPrincipalWasNotSet_ReturnsAbsentPrincipal.

@Test
public void authenticate_WhenPrincipalWasNotSet_ReturnsAbsentPrincipal() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    when(credentials.asRequestData()).thenReturn(requestData);
    Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
    String principal = "simbaUsername";
    String ssoToken = "ssotoken";
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.ADD_PARAMETER_TO_TARGET).withPrincipal(principal).withSsoToken(new SSOToken(ssoToken)).build();
    when(authenticationServiceMock.processRequest(requestData, SimbaGateway.SESSION_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<SimbaPrincipal> simbaPrincipal = simbaGateway.authenticate(credentials);
    assertThat(simbaPrincipal.isPresent()).isFalse();
}
Also used : SimbaPrincipal(org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal) ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 8 with RequestData

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

the class SimbaGatewayTest method authenticate_WhenPrincipalWasSet_ReturnPrincipal.

@Test
public void authenticate_WhenPrincipalWasSet_ReturnPrincipal() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    when(credentials.asRequestData()).thenReturn(requestData);
    Client authenticationServiceMock = setupSimbaServiceToReturnASimbaAuthenticationService();
    String principal = "simbaUsername";
    String token = "token";
    ActionDescriptor actionDescriptor = new ActionDescriptorBuilderForTests().withActionTypes(ActionType.DO_FILTER_AND_SET_PRINCIPAL).withPrincipal(principal).withSsoToken(new SSOToken(token)).build();
    when(authenticationServiceMock.processRequest(requestData, SESSION_AUTHENTICATE_CHAIN)).thenReturn(actionDescriptor);
    Optional<SimbaPrincipal> simbaPrincipal = simbaGateway.authenticate(credentials);
    assertThat(simbaPrincipal.get()).isEqualTo(new SimbaPrincipal(principal, token));
}
Also used : SimbaPrincipal(org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal) ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) SSOToken(org.simbasecurity.api.service.thrift.SSOToken) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 9 with RequestData

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

the class SimbaCredentialsTest method asRequestData_ReturnsRequestDataFromInternals.

@Test
public void asRequestData_ReturnsRequestDataFromInternals() throws Exception {
    Map<String, String> requestHeaders = Maps.newHashMap();
    requestHeaders.put(HttpHeaders.WWW_AUTHENTICATE, "auth-string");
    Map<String, String> requestParameters = Maps.newHashMap();
    requestParameters.put("format", "timeseries");
    SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().withRequestUrl(SimbaCredentialsBuilderForTests.REQUESTURL + "?format=timeseries").withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsotoken("123456").withIsLoginRequest(true).build();
    RequestData expected = new RequestDataBuilderForTests().withHostServerName(HOSTSERVERNAME).withRequestMethod(HTTP_METHOD).withRequestUrl(REQUESTURL + "?format=timeseries").withSimbaWebURL(SIMBAWEBURL).withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsoToken(new SSOToken("123456")).withLoginRequest(true).build();
    RequestData actual = simbaCredentials.asRequestData();
    assertThat(actual).isEqualTo(expected);
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) RequestDataBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) RequestData(org.simbasecurity.api.service.thrift.RequestData) Test(org.junit.Test)

Example 10 with RequestData

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

the class SimbaCredentialsTest method asRequestData_IfNoSSOTokenOnCredentials_ReturnsRequestDataWithSSOTokenNull.

@Test
public void asRequestData_IfNoSSOTokenOnCredentials_ReturnsRequestDataWithSSOTokenNull() throws Exception {
    Map<String, String> requestHeaders = Maps.newHashMap();
    requestHeaders.put(HttpHeaders.WWW_AUTHENTICATE, "auth-string");
    Map<String, String> requestParameters = Maps.newHashMap();
    requestParameters.put("format", "timeseries");
    SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().withRequestUrl(SimbaCredentialsBuilderForTests.REQUESTURL + "?format=timeseries").withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsotoken(null).build();
    RequestData expected = new RequestDataBuilderForTests().withHostServerName(HOSTSERVERNAME).withRequestMethod(HTTP_METHOD).withRequestUrl(REQUESTURL + "?format=timeseries").withSimbaWebURL(SIMBAWEBURL).withRequestHeaders(requestHeaders).withRequestParameters(requestParameters).withSsoToken(null).build();
    RequestData actual = simbaCredentials.asRequestData();
    assertThat(actual).isEqualTo(expected);
}
Also used : RequestDataBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) RequestData(org.simbasecurity.api.service.thrift.RequestData) 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