Search in sources :

Example 1 with AuthServiceCredentials

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;
    }
}
Also used : AuthServiceCredentials(org.graylog.security.authservice.AuthServiceCredentials) AuthServiceException(org.graylog.security.authservice.AuthServiceException) AuthServiceResult(org.graylog.security.authservice.AuthServiceResult) AuthServiceException(org.graylog.security.authservice.AuthServiceException) UnknownHostException(java.net.UnknownHostException) AuthenticationException(org.apache.shiro.authc.AuthenticationException)

Aggregations

UnknownHostException (java.net.UnknownHostException)1 AuthenticationException (org.apache.shiro.authc.AuthenticationException)1 AuthServiceCredentials (org.graylog.security.authservice.AuthServiceCredentials)1 AuthServiceException (org.graylog.security.authservice.AuthServiceException)1 AuthServiceResult (org.graylog.security.authservice.AuthServiceResult)1