try {
// Get the Authorization header
final Map<String,Cookie> cookieMap = httpContext.getRequest().getCookies();
if (!cookieMap.containsKey(SiteConfiguration.SESSION_TOKEN_NAME)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
UUID sessionToken = UUID.fromString(cookieMap.get(SiteConfiguration.SESSION_TOKEN_NAME).getValue());
if (sessionToken != null) {
final OpenIDCredentials credentials = new OpenIDCredentials(sessionToken, requiredAuthorities);
final Optional<User> result = authenticator.authenticate(credentials);
if (result.isPresent()) {
return result.get();
}
}
} catch (IllegalArgumentException e) {
log.warn("Error decoding credentials",e);
} catch (AuthenticationException e) {
log.warn("Error authenticating credentials",e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
// Must have failed to be here
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}