Search in sources :

Example 6 with SimbaCredentialsBuilderForTests

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

the class SimbaAuthRule method before.

protected void before(ResourceTest currentTest) throws AuthenticationException {
    SimbaAuthenticator authenticatorMock = mock(SimbaAuthenticator.class);
    SimbaCredentialsFactory simbaCredentialsFactoryMock = mock(SimbaCredentialsFactory.class);
    SimbaAuthenticatedProvider simbaAuthenticatedProvider = new SimbaAuthenticatedProvider(authenticatorMock, simbaCredentialsFactoryMock, domainProvider);
    SimbaCredentials simbaCredentials = new SimbaCredentialsBuilderForTests().build();
    when(simbaCredentialsFactoryMock.create(any(ContainerRequest.class))).thenReturn(simbaCredentials);
    when(authenticatorMock.authenticate(simbaCredentials)).thenReturn(Optional.fromNullable(new SimbaPrincipal("user", "ssoToken")));
    currentTest.addProvider(simbaAuthenticatedProvider);
}
Also used : SimbaPrincipal(org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal) SimbaAuthenticator(org.simbasecurity.dwclient.dropwizard.authenticator.SimbaAuthenticator) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) SimbaAuthenticatedProvider(org.simbasecurity.dwclient.dropwizard.provider.SimbaAuthenticatedProvider) SimbaCredentialsFactory(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsFactory) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest)

Example 7 with SimbaCredentialsBuilderForTests

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

the class SimbaGatewayTest method authenticate_THttpClientAlwaysGetsClosed.

@Test
public void authenticate_THttpClientAlwaysGetsClosed() throws Exception {
    Client expectedClient = mock(Client.class);
    THttpClient tHttpClientMock = mock(THttpClient.class);
    when(simbaServiceFactoryMock.createTHttpClient(SIMBA_WEB_URL + "/" + SIMBA_AUTHENTICATION_SERVICE)).thenReturn(tHttpClientMock);
    when(simbaServiceFactoryMock.createJSONAuthenticationFilterService(tHttpClientMock)).thenReturn(expectedClient);
    Client authenticationServiceMock = expectedClient;
    when(authenticationServiceMock.processRequest(any(RequestData.class), eq(SimbaGateway.SESSION_AUTHENTICATE_CHAIN))).thenReturn(new ActionDescriptorBuilderForTests().withActionTypes().build());
    simbaGateway.authenticate(new SimbaCredentialsBuilderForTests().build());
    verify(tHttpClientMock, times(1)).close();
}
Also used : ActionDescriptorBuilderForTests(org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests) RequestData(org.simbasecurity.api.service.thrift.RequestData) SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) THttpClient(org.apache.thrift.transport.THttpClient) Client(org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client) THttpClient(org.apache.thrift.transport.THttpClient) Test(org.junit.Test)

Example 8 with SimbaCredentialsBuilderForTests

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

the class SimbaCredentialsFactoryTest method create_BasicAuthentication_DecodesAndCreatesCredentials.

@Test
public void create_BasicAuthentication_DecodesAndCreatesCredentials() throws Exception {
    String username = "emanresu";
    String password = "drowssap";
    String digest = username + ":" + password;
    byte[] encodedDigest = Base64.encode(digest);
    String basicAuthString = "basic " + new String(encodedDigest);
    ContainerRequest containerRequest = new ContainerRequestBuilderForTests().addHeader(AUTHORIZATION, basicAuthString).withRequestUri(URI.create("http://rest.wayneindustries.com/v1/bats?format=timeseries")).withHttpMethod(HttpMethods.GET).build();
    SimbaCredentials expected = new SimbaCredentialsBuilderForTests().withHttpMethod(HttpMethods.GET).addHeader(AUTHORIZATION, basicAuthString).addParameter(AuthenticationConstants.USERNAME, username).addParameter(AuthenticationConstants.PASSWORD, password).addParameter("format", "timeseries").withRequestUrl("http://rest.wayneindustries.com/v1/bats/").withSimbaWebURL(SIMBA_WEB_URL).withHostServerName(RequestUtil.HOST_SERVER_NAME).withIsLoginRequest(true).build();
    SimbaCredentials simbaCredentials = factory.create(containerRequest);
    assertThat(simbaCredentials).isEqualTo(expected);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 9 with SimbaCredentialsBuilderForTests

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

the class SimbaCredentialsFactoryTest method create_SSOTokenIsMappedProperly.

@Test
public void create_SSOTokenIsMappedProperly() throws Exception {
    String token = "55687";
    ContainerRequest containerRequest = new ContainerRequestBuilderForTests().withRequestUri(URI.create(REQUESTURL)).addHeader(X_SSO_TOKEN, token).withHttpMethod(HttpMethods.GET).build();
    Map<String, String> requestParameters = Maps.newHashMap();
    SimbaCredentials expected = new SimbaCredentialsBuilderForTests().withRequestUrl(REQUESTURL).addHeader(X_SSO_TOKEN, token).withRequestParameters(requestParameters).withHostServerName(RequestUtil.HOST_SERVER_NAME).withSsotoken(token).build();
    SimbaCredentials actual = factory.create(containerRequest);
    assertThat(actual).isEqualTo(expected);
}
Also used : SimbaCredentialsBuilderForTests(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests) ContainerRequestBuilderForTests(org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest) Test(org.junit.Test)

Example 10 with SimbaCredentialsBuilderForTests

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

the class SimbaCredentialsTest method asRequestData_IfEmptySSOTokenOnCredentials_ReturnsRequestDataWithSSOTokenNull.

@Test
public void asRequestData_IfEmptySSOTokenOnCredentials_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("").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

SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)10 Test (org.junit.Test)8 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)4 ContainerRequestBuilderForTests (org.simbasecurity.dwclient.test.dropwizard.matchers.ContainerRequestBuilderForTests)3 RequestDataBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests)3 THttpClient (org.apache.thrift.transport.THttpClient)2 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)2 TException (org.apache.thrift.TException)1 Before (org.junit.Before)1 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)1 SimbaAuthenticator (org.simbasecurity.dwclient.dropwizard.authenticator.SimbaAuthenticator)1 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)1 SimbaCredentialsFactory (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsFactory)1 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)1 SimbaAuthenticatedProvider (org.simbasecurity.dwclient.dropwizard.provider.SimbaAuthenticatedProvider)1 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)1