This issue is related to #6638.
I use single OpenIDC IdP (google) from OAuth2Login Sample. Added a rest endpoint that use the same security configuration. When an ajax request to the rest endpoint with an expired JSESSIONID or no JESSIONID at all, the response is a redirect to google IdP. The redirect will be blocked by the browser since cross domain redirect is not allowed in CORS policy.
After tracing the code a little bit, and found the request matcher logic in OAuth2LoginConfigurer might contribute to this behavior:
|
this.registerAuthenticationEntryPoint(http, this.getLoginEntryPoint(http, providerLoginPage)); |
|
private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLoginPage) { |
|
RequestMatcher loginPageMatcher = new AntPathRequestMatcher(this.getLoginPage()); |
|
RequestMatcher faviconMatcher = new AntPathRequestMatcher("/favicon.ico"); |
|
RequestMatcher defaultEntryPointMatcher = this.getAuthenticationEntryPointMatcher(http); |
|
RequestMatcher defaultLoginPageMatcher = new AndRequestMatcher( |
|
new OrRequestMatcher(loginPageMatcher, faviconMatcher), defaultEntryPointMatcher); |
|
|
|
LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>(); |
|
entryPoints.put(new NegatedRequestMatcher(defaultLoginPageMatcher), |
|
new LoginUrlAuthenticationEntryPoint(providerLoginPage)); |
|
|
|
DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints); |
|
loginEntryPoint.setDefaultEntryPoint(this.getAuthenticationEntryPoint()); |
|
|
|
return loginEntryPoint; |
|
} |
The defaultEntryPointMatcher will filter out XMLHttpRequest. Should the entryPoints be something like
entryPoints.put(new OrRequestMatcher(new NegatedRequestMatcher(defaultLoginPageMatcher), defaultEntryPointMatcher),
new LoginUrlAuthenticationEntryPoint(providerLoginPage));
Then the AJAX call to data will simply got 401 instead of a redirect, which the browser will block since it will be a cross domain redirect.
Originally posted by @simpleway in #6638 (comment)
This issue is related to #6638.
I use single OpenIDC IdP (google) from OAuth2Login Sample. Added a rest endpoint that use the same security configuration. When an ajax request to the rest endpoint with an expired JSESSIONID or no JESSIONID at all, the response is a redirect to google IdP. The redirect will be blocked by the browser since cross domain redirect is not allowed in CORS policy.
After tracing the code a little bit, and found the request matcher logic in
OAuth2LoginConfigurermight contribute to this behavior:spring-security/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java
Line 450 in 5aacd0c
spring-security/config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/client/OAuth2LoginConfigurer.java
Lines 619 to 634 in 5aacd0c
The
defaultEntryPointMatcherwill filter out XMLHttpRequest. Should theentryPointsbe something likeThen the AJAX call to data will simply got 401 instead of a redirect, which the browser will block since it will be a cross domain redirect.
Originally posted by @simpleway in #6638 (comment)