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;
}
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);
}
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));
}
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());
}
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();
}
Aggregations