Skip to content

Commit

Permalink
Fix #24095: catch Exception and re-throw it using a Exception recogni…
Browse files Browse the repository at this point in the history
…zed by Spring
  • Loading branch information
LEDfan committed Dec 24, 2020
1 parent 6597619 commit 2d7ba41
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
import org.springframework.security.oauth2.core.OAuth2Error;
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
Expand Down Expand Up @@ -122,7 +124,6 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
.userInfoEndpoint()
.userAuthoritiesMapper(createAuthoritiesMapper())
.oidcUserService(createOidcUserService());

}

@Override
Expand Down Expand Up @@ -246,7 +247,12 @@ protected OidcUserService createOidcUserService() {
return new OidcUserService() {
@Override
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
OidcUser user = super.loadUser(userRequest);
OidcUser user;
try {
user = super.loadUser(userRequest);
} catch (IllegalArgumentException ex) {
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST), "Error while loading user info", ex);
}
String nameAttributeKey = environment.getProperty("proxy.openid.username-attribute", "email");
return new CustomNameOidcUser(new HashSet<>(user.getAuthorities()), user.getIdToken(), user.getUserInfo(), nameAttributeKey);
}
Expand Down

0 comments on commit 2d7ba41

Please sign in to comment.