Search in sources :

Example 1 with SimbaCredentials

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

the class SimbaAuthenticatedInjectable method getValue.

@Override
public P getValue(HttpContext httpContext) {
    SimbaCredentials credentials;
    try {
        final ContainerRequest containerRequest = (ContainerRequest) httpContext.getRequest();
        credentials = simbaCredentialsFactory.create(containerRequest);
        final Optional<SimbaPrincipal> result = authenticator.authenticate(credentials);
        if (result.isPresent()) {
            return domainProvider.lookUp(result.get());
        }
    } catch (AuthenticationException e) {
        log.error("Something went wrong in the authentication process", e);
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("Something went wrong in the authentication process").type(MediaType.APPLICATION_JSON).build());
    }
    if (required) {
        log.warn("Error authenticating credentials: {}", credentials.getSsoToken());
        throw new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED).entity("You are not allowed to access this resource").type(MediaType.APPLICATION_JSON).build());
    }
    return null;
}
Also used : SimbaPrincipal(org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal) WebApplicationException(javax.ws.rs.WebApplicationException) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) AuthenticationException(com.yammer.dropwizard.auth.AuthenticationException) ContainerRequest(com.sun.jersey.spi.container.ContainerRequest)

Example 2 with SimbaCredentials

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

the class SimbaGatewayTest method logout.

@Test
public void logout() throws Exception {
    Client authenticationServicemock = setupSimbaServiceToReturnASimbaAuthenticationService();
    ContainerRequest containerRequestMock = mock(ContainerRequest.class);
    SimbaCredentials simbaCredentials = mock(SimbaCredentials.class);
    RequestData requestData = mock(RequestData.class);
    when(simbaCredentialsFactoryMock.create(containerRequestMock, true)).thenReturn(simbaCredentials);
    when(simbaCredentials.asRequestData()).thenReturn(requestData);
    simbaGateway.logout(containerRequestMock);
    verify(authenticationServicemock).processRequest(requestData, LOGOUT_CHAIN);
}
Also used : SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) RequestData(org.simbasecurity.api.service.thrift.RequestData) 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 3 with SimbaCredentials

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

the class SimbaGatewayTest method authenticate_WhenClientIsNotABrowser_ExecuteWsLoginChain.

@Test
public void authenticate_WhenClientIsNotABrowser_ExecuteWsLoginChain() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    when(credentials.isClientABrowser()).thenReturn(false);
    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)

Example 4 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials 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 5 with SimbaCredentials

use of org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials 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)

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