diff --git a/src/main/java/eu/openanalytics/containerproxy/auth/impl/OpenIDAuthenticationBackend.java b/src/main/java/eu/openanalytics/containerproxy/auth/impl/OpenIDAuthenticationBackend.java index 46fc51d2..097c7611 100644 --- a/src/main/java/eu/openanalytics/containerproxy/auth/impl/OpenIDAuthenticationBackend.java +++ b/src/main/java/eu/openanalytics/containerproxy/auth/impl/OpenIDAuthenticationBackend.java @@ -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; @@ -123,7 +125,6 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo .userInfoEndpoint() .userAuthoritiesMapper(createAuthoritiesMapper()) .oidcUserService(createOidcUserService()); - } @Override @@ -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); }