Skip to content

Commit 2d7ba41

Browse files
committed
Fix #24095: catch Exception and re-throw it using a Exception recognized by Spring
1 parent 6597619 commit 2d7ba41

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;
@@ -122,7 +124,6 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
122124
.userInfoEndpoint()
123125
.userAuthoritiesMapper(createAuthoritiesMapper())
124126
.oidcUserService(createOidcUserService());
125-
126127
}
127128

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

0 commit comments

Comments
 (0)