use of org.graylog.security.authservice.AuthServiceCredentials in project graylog2-server by Graylog2.
the class HTTPHeaderAuthenticationRealm method doAuthenticate.
private AuthenticationInfo doAuthenticate(String username, HTTPHeaderAuthConfig config, String remoteAddr) {
LOG.debug("Attempting authentication for username <{}>", username);
try {
// Create already authenticated credentials to make sure the auth service backend doesn't try to
// authenticate the user again
final AuthServiceCredentials credentials = AuthServiceCredentials.createAuthenticated(username);
final AuthServiceResult result = authServiceAuthenticator.authenticate(credentials);
if (result.isSuccess()) {
LOG.debug("Successfully authenticated username <{}> for user profile <{}> with backend <{}/{}/{}>", result.username(), result.userProfileId(), result.backendTitle(), result.backendType(), result.backendId());
// Setting this, will let the SessionResource know, that when a non-existing session is validated, it
// should in fact create a session.
ShiroSecurityContext.requestSessionCreation(true);
return toAuthenticationInfo(result);
} else {
LOG.warn("Failed to authenticate username <{}> from trusted HTTP header <{}> via proxy <{}>", result.username(), config.usernameHeader(), remoteAddr);
return null;
}
} catch (AuthServiceException e) {
LOG.error("Authentication service error", e);
return null;
} catch (Exception e) {
LOG.error("Unhandled authentication error", e);
return null;
}
}
Aggregations