Closed hauntingEcho closed 5 years ago
If you configure a custom .failureHandler
you might be able to get the error message (and prevent the loop).
Something simple like this will spit out the error messages anyway
.oauth2Login()
.loginPage(loginPage) // should send us directly to oidc login
.successHandler(customSuccessHandler())
.failureHandler(new CustomAuthenticationFailureHandler())
.tokenEndpoint()
...
public class CustomAuthenticationFailureHandler implements AuthenticationFailureHandler {
@Override
public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException {
httpServletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
String jsonPayload = "{\"message\" : \"%s\", \"timestamp\" : \"%s\" }";
httpServletResponse.getOutputStream().println(String.format(jsonPayload, e.getMessage(), Calendar.getInstance().getTime()));
}
}
EDIT: In case someone finds this while searching. Above is just meant for debugging in development. Do NOT write out security exceptions to the user.
@hauntingEcho This is a duplicate of #5262. As the ticket indicates, we need to add logging in the oauth2 modules as logging is non-existent at the moment. We're trying to get to this but there are other higher priority items we need to add into the upcoming 5.2 release. I'm going to close this issue and please keep track of #5262.
Summary
No message is logged when an OIDC session fails to connect to the identity provider after a token is provided. This is likely a specific instance of #5262
Actual Behavior
trying to debug an OpenID-Connect application, I was receiving no hints until I added
-Djavax.net.debug=all
to read the communication between my application & the OIDC provider. My application was receiving a 401 response with:However, I was receiving no logging from Spring-Security, and my only hint on the frontend was a redirect loop (OIDC provider -> oauth consumer -> oauth error). The error page I was being brought to was
/oauth2/authorization/wso2?error
, with no value on the error parameter.Expected Behavior
a message is logged when communication with the OAuth provider fails
Configuration
application.properties:
WebSecurityConfigurerAdapter:
Version
5.1.5-RELEASE