Search in sources :

Example 1 with RequestData

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

the class AuthenticationFilterServiceImplTest method testGetCurrentSession_TokenMappingProvided.

@Test
public void testGetCurrentSession_TokenMappingProvided() {
    SSOToken ssoToken = mock(SSOToken.class);
    String tokenKey = UUID.randomUUID().toString();
    RequestData requestData = new RequestData(Collections.singletonMap(RequestConstants.SIMBA_SSO_TOKEN, tokenKey), null, null, null, null, null, false, false, true, false, false, null, null, null, null);
    when(ssoTokenMappingService.getSSOToken(tokenKey)).thenReturn(ssoToken);
    serviceImpl.getCurrentSession(requestData);
    verify(sessionServiceMock).getSession(same(ssoToken));
    verify(ssoTokenMappingService).destroyMapping(tokenKey);
}
Also used : SSOToken(org.simbasecurity.api.service.thrift.SSOToken) RequestData(org.simbasecurity.api.service.thrift.RequestData) Test(org.junit.Test)

Example 2 with RequestData

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

the class SimbaFilter method doFilter.

private void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException {
    if (isUrlExcluded(request)) {
        chain.doFilter(request, response);
        return;
    }
    RequestData requestData = RequestUtil.createRequestData(request, simbaWebURL, simbeEidSuccessUrl);
    FilterActionFactory actionFactory = new FilterActionFactory(request, response, chain);
    THttpClient tHttpClient = null;
    try {
        tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL());
        TProtocol tProtocol = new TJSONProtocol(tHttpClient);
        AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
        ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, authenticationChainName);
        actionFactory.execute(actionDescriptor);
    } catch (Exception e) {
        throw new ServletException(e);
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : FilterActionFactory(org.simbasecurity.client.filter.action.FilterActionFactory) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) TProtocol(org.apache.thrift.protocol.TProtocol) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException)

Example 3 with RequestData

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

Aggregations

RequestData (org.simbasecurity.api.service.thrift.RequestData)24 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)16 Test (org.junit.Test)15 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 RequestActionFactory (org.simbasecurity.common.filter.action.RequestActionFactory)4 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)3 TProtocol (org.apache.thrift.protocol.TProtocol)3 AuthenticationFilterService (org.simbasecurity.api.service.thrift.AuthenticationFilterService)3 ChainContextImpl (org.simbasecurity.core.chain.ChainContextImpl)3 SimbaCredentialsBuilderForTests (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentialsBuilderForTests)3 RequestDataBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.RequestDataBuilderForTests)3 IOException (java.io.IOException)2 SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)2 UserPrincipal (com.sun.security.auth.UserPrincipal)1 Principal (java.security.Principal)1