|
47 | 47 | import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository;
|
48 | 48 | import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter;
|
49 | 49 | import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver;
|
| 50 | +import org.springframework.security.web.AuthenticationEntryPoint; |
50 | 51 | import org.springframework.security.web.authentication.AuthenticationConverter;
|
| 52 | +import org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint; |
51 | 53 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
52 | 54 | import org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter;
|
| 55 | +import org.springframework.security.web.util.matcher.AndRequestMatcher; |
53 | 56 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
| 57 | +import org.springframework.security.web.util.matcher.NegatedRequestMatcher; |
| 58 | +import org.springframework.security.web.util.matcher.OrRequestMatcher; |
| 59 | +import org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher; |
54 | 60 | import org.springframework.security.web.util.matcher.RequestMatcher;
|
55 | 61 | import org.springframework.util.Assert;
|
56 | 62 | import org.springframework.util.ClassUtils;
|
@@ -252,8 +258,7 @@ public void init(B http) throws Exception {
|
252 | 258 | this.updateAuthenticationDefaults();
|
253 | 259 | this.updateAccessDefaults(http);
|
254 | 260 | String loginUrl = providerUrlMap.entrySet().iterator().next().getKey();
|
255 |
| - final LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint(loginUrl); |
256 |
| - registerAuthenticationEntryPoint(http, entryPoint); |
| 261 | + registerAuthenticationEntryPoint(http, getLoginEntryPoint(http, loginUrl)); |
257 | 262 | }
|
258 | 263 | else {
|
259 | 264 | super.init(http);
|
@@ -295,6 +300,22 @@ RelyingPartyRegistrationRepository relyingPartyRegistrationRepository(B http) {
|
295 | 300 | return this.relyingPartyRegistrationRepository;
|
296 | 301 | }
|
297 | 302 |
|
| 303 | + private AuthenticationEntryPoint getLoginEntryPoint(B http, String providerLoginPage) { |
| 304 | + RequestMatcher loginPageMatcher = new AntPathRequestMatcher(this.getLoginPage()); |
| 305 | + RequestMatcher faviconMatcher = new AntPathRequestMatcher("/favicon.ico"); |
| 306 | + RequestMatcher defaultEntryPointMatcher = this.getAuthenticationEntryPointMatcher(http); |
| 307 | + RequestMatcher defaultLoginPageMatcher = new AndRequestMatcher( |
| 308 | + new OrRequestMatcher(loginPageMatcher, faviconMatcher), defaultEntryPointMatcher); |
| 309 | + RequestMatcher notXRequestedWith = new NegatedRequestMatcher( |
| 310 | + new RequestHeaderRequestMatcher("X-Requested-With", "XMLHttpRequest")); |
| 311 | + LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPoints = new LinkedHashMap<>(); |
| 312 | + entryPoints.put(new AndRequestMatcher(notXRequestedWith, new NegatedRequestMatcher(defaultLoginPageMatcher)), |
| 313 | + new LoginUrlAuthenticationEntryPoint(providerLoginPage)); |
| 314 | + DelegatingAuthenticationEntryPoint loginEntryPoint = new DelegatingAuthenticationEntryPoint(entryPoints); |
| 315 | + loginEntryPoint.setDefaultEntryPoint(this.getAuthenticationEntryPoint()); |
| 316 | + return loginEntryPoint; |
| 317 | + } |
| 318 | + |
298 | 319 | private void setAuthenticationRequestRepository(B http,
|
299 | 320 | Saml2WebSsoAuthenticationFilter saml2WebSsoAuthenticationFilter) {
|
300 | 321 | saml2WebSsoAuthenticationFilter.setAuthenticationRequestRepository(getAuthenticationRequestRepository(http));
|
|
0 commit comments