Skip to content

Commit

Permalink
Merge pull request 'Fix #24095: catch Exception and re-throw it using…
Browse files Browse the repository at this point in the history
… a Exception recognized by Spring' (#24) from bugfix/24095 into develop
  • Loading branch information
fmichielssen committed Feb 17, 2021
2 parents cbfec34 + 2d7ba41 commit 0ed1af6
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 @@ -123,7 +125,6 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
.userInfoEndpoint()
.userAuthoritiesMapper(createAuthoritiesMapper())
.oidcUserService(createOidcUserService());

}

@Override
Expand Down Expand Up @@ -247,7 +248,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 0ed1af6

Please sign in to comment.