use of javax.ws.rs.Priorities.AUTHENTICATION in project trino by trinodb.
the class AuthenticationFilter method filter.
@Override
public void filter(ContainerRequestContext request) {
if (InternalAuthenticationManager.isInternalRequest(request)) {
internalAuthenticationManager.handleInternalRequest(request);
return;
}
List<Authenticator> authenticators;
if (request.getSecurityContext().isSecure()) {
authenticators = this.authenticators;
} else if (insecureAuthenticationOverHttpAllowed) {
authenticators = ImmutableList.of(insecureAuthenticator);
} else {
throw new ForbiddenException("Authentication over HTTP is not enabled");
}
// try to authenticate, collecting errors and authentication headers
Set<String> messages = new LinkedHashSet<>();
Set<String> authenticateHeaders = new LinkedHashSet<>();
for (Authenticator authenticator : authenticators) {
Identity authenticatedIdentity;
try {
authenticatedIdentity = authenticator.authenticate(request);
} catch (AuthenticationException e) {
// Some authenticators (e.g. password) nest multiple internal authenticators.
// Exceptions from additional failed login attempts are suppressed in the first exception
Stream.concat(Stream.of(e), Arrays.stream(e.getSuppressed())).filter(ex -> ex instanceof AuthenticationException).map(AuthenticationException.class::cast).forEach(ex -> {
if (ex.getMessage() != null) {
messages.add(ex.getMessage());
}
ex.getAuthenticateHeader().ifPresent(authenticateHeaders::add);
});
continue;
}
// authentication succeeded
setAuthenticatedIdentity(request, authenticatedIdentity);
return;
}
// authentication failed
if (messages.isEmpty()) {
messages.add("Unauthorized");
}
// The error string is used by clients for exception messages and
// is presented to the end user, thus it should be a single line.
String error = Joiner.on(" | ").join(messages);
sendWwwAuthenticate(request, error, authenticateHeaders);
}
Aggregations