Search in sources :

Example 6 with SimbaPrincipal

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

the class SimbaAuthenticatorTest method authenticate_WhenAuthenticationIsSuccessful_ReturnPrincipal.

@Test
public void authenticate_WhenAuthenticationIsSuccessful_ReturnPrincipal() throws Exception {
    SimbaCredentials credentials = mock(SimbaCredentials.class);
    Optional<SimbaPrincipal> expected = Optional.of(new SimbaPrincipal("username", "token"));
    when(simbaGatewayMock.authenticate(credentials)).thenReturn(expected);
    Optional<SimbaPrincipal> actual = authenticator.authenticate(credentials);
    assertThat(actual).isEqualTo(expected);
}
Also used : SimbaPrincipal(org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal) SimbaCredentials(org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials) Test(org.junit.Test)

Example 7 with SimbaPrincipal

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

the class SimbaAuthenticatedInjectableTest method getValue_WhenAuthenticatorReturnsPresentPrincipal_ThenDomainProviderIsCalledToLookupDomainPrincipalWithPrincipal.

@Test
public void getValue_WhenAuthenticatorReturnsPresentPrincipal_ThenDomainProviderIsCalledToLookupDomainPrincipalWithPrincipal() throws Exception {
    SimbaPrincipal principal = new SimbaPrincipal("user", "token");
    when(authenticatorMock.authenticate(simbaCredentials)).thenReturn(Optional.of(principal));
    AuthenticatedPrincipal expectedDomainPrincipal = mock(AuthenticatedPrincipal.class);
    when(domainProviderMock.lookUp(principal)).thenReturn(expectedDomainPrincipal);
    AuthenticatedPrincipal actualDomainPrincipal = injectable.getValue(dummyHttpContext);
    assertThat(actualDomainPrincipal).isEqualTo(expectedDomainPrincipal);
}
Also used : SimbaPrincipal(org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal) Test(org.junit.Test)

Example 8 with SimbaPrincipal

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

Aggregations

SimbaPrincipal (org.simbasecurity.dwclient.dropwizard.credentials.SimbaPrincipal)8 Test (org.junit.Test)5 SimbaCredentials (org.simbasecurity.dwclient.dropwizard.credentials.SimbaCredentials)5 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)3 ContainerRequest (com.sun.jersey.spi.container.ContainerRequest)2 THttpClient (org.apache.thrift.transport.THttpClient)2 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)2 RequestData (org.simbasecurity.api.service.thrift.RequestData)2 SSOToken (org.simbasecurity.api.service.thrift.SSOToken)2 ActionDescriptorBuilderForTests (org.simbasecurity.dwclient.test.stub.simba.ActionDescriptorBuilderForTests)2 AuthenticationException (com.yammer.dropwizard.auth.AuthenticationException)1 WebApplicationException (javax.ws.rs.WebApplicationException)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