Skip to content

Commit 0ed1af6

Browse files
committed
Merge pull request 'Fix #24095: catch Exception and re-throw it using a Exception recognized by Spring' (#24) from bugfix/24095 into develop
2 parents cbfec34 + 2d7ba41 commit 0ed1af6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/main/java/eu/openanalytics/containerproxy/auth/impl/OpenIDAuthenticationBackend.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestRedirectFilter;
5757
import org.springframework.security.oauth2.core.AuthorizationGrantType;
5858
import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
59+
import org.springframework.security.oauth2.core.OAuth2Error;
60+
import org.springframework.security.oauth2.core.OAuth2ErrorCodes;
5961
import org.springframework.security.oauth2.core.oidc.OidcIdToken;
6062
import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
6163
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
@@ -123,7 +125,6 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
123125
.userInfoEndpoint()
124126
.userAuthoritiesMapper(createAuthoritiesMapper())
125127
.oidcUserService(createOidcUserService());
126-
127128
}
128129

129130
@Override
@@ -247,7 +248,12 @@ protected OidcUserService createOidcUserService() {
247248
return new OidcUserService() {
248249
@Override
249250
public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
250-
OidcUser user = super.loadUser(userRequest);
251+
OidcUser user;
252+
try {
253+
user = super.loadUser(userRequest);
254+
} catch (IllegalArgumentException ex) {
255+
throw new OAuth2AuthenticationException(new OAuth2Error(OAuth2ErrorCodes.INVALID_REQUEST), "Error while loading user info", ex);
256+
}
251257
String nameAttributeKey = environment.getProperty("proxy.openid.username-attribute", "email");
252258
return new CustomNameOidcUser(new HashSet<>(user.getAuthorities()), user.getIdToken(), user.getUserInfo(), nameAttributeKey);
253259
}

0 commit comments

Comments
 (0)