use of com.yammer.dropwizard.auth.AuthenticationException 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 com.yammer.dropwizard.auth.AuthenticationException in project simba-os by cegeka.
the class SimbaAuthenticatedInjectableTest method getValue_WhenAuthenticatorThrowsAuthenticationException_ThenThrowsWebAppException.
@Test
public void getValue_WhenAuthenticatorThrowsAuthenticationException_ThenThrowsWebAppException() throws Exception {
when(authenticatorMock.authenticate(simbaCredentials)).thenThrow(new AuthenticationException(""));
expectedException.expect(WebApplicationExceptionMatcher.webApplicationException(Response.Status.UNAUTHORIZED));
injectable.getValue(dummyHttpContext);
}
Aggregations