Skip to content

Commit

Permalink
In HTTP authentication, throw exception from provider if there is one. (
Browse files Browse the repository at this point in the history
apache#7100)

Co-authored-by: Chris Kellogg <ckellogg@splunk.com>
  • Loading branch information
merlimat and Chris Kellogg authored May 29, 2020
1 parent c281d95 commit 09fc647
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ public String authenticate(AuthenticationDataSource authData, String authMethodN

public String authenticateHttpRequest(HttpServletRequest request) throws AuthenticationException {
// Try to validate with any configured provider
AuthenticationException authenticationException = null;
AuthenticationDataSource authData = new AuthenticationDataHttps(request);
for (AuthenticationProvider provider : providers.values()) {
try {
return provider.authenticate(authData);
} catch (AuthenticationException e) {
// Ignore the exception because we don't know which authentication method is expected here.
// Store the exception so we can throw it later instead of a generic one
authenticationException = e;
}
}

Expand All @@ -99,7 +101,11 @@ public String authenticateHttpRequest(HttpServletRequest request) throws Authent
return anonymousUserRole;
}
// If at least a provider was configured, then the authentication needs to be provider
throw new AuthenticationException("Authentication required");
if (authenticationException != null) {
throw authenticationException;
} else {
throw new AuthenticationException("Authentication required");
}
} else {
// No authentication required
return "<none>";
Expand Down

0 comments on commit 09fc647

Please sign in to comment.