|
20 | 20 | import java.util.List;
|
21 | 21 |
|
22 | 22 | import jakarta.servlet.http.HttpServletRequest;
|
| 23 | +import org.opensaml.core.Version; |
23 | 24 |
|
24 | 25 | import org.springframework.context.ApplicationContext;
|
25 | 26 | import org.springframework.security.authentication.AuthenticationManager;
|
|
33 | 34 | import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
|
34 | 35 | import org.springframework.security.saml2.provider.service.authentication.logout.OpenSaml4LogoutRequestValidator;
|
35 | 36 | import org.springframework.security.saml2.provider.service.authentication.logout.OpenSaml4LogoutResponseValidator;
|
| 37 | +import org.springframework.security.saml2.provider.service.authentication.logout.OpenSaml5LogoutRequestValidator; |
| 38 | +import org.springframework.security.saml2.provider.service.authentication.logout.OpenSaml5LogoutResponseValidator; |
36 | 39 | import org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutRequestValidator;
|
37 | 40 | import org.springframework.security.saml2.provider.service.authentication.logout.Saml2LogoutResponseValidator;
|
38 | 41 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration;
|
39 | 42 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
40 | 43 | import org.springframework.security.saml2.provider.service.web.authentication.logout.HttpSessionLogoutRequestRepository;
|
41 | 44 | import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutRequestResolver;
|
42 |
| -import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver; |
43 | 45 | import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutRequestValidatorParametersResolver;
|
| 46 | +import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver; |
| 47 | +import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml5LogoutRequestResolver; |
| 48 | +import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml5LogoutRequestValidatorParametersResolver; |
| 49 | +import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml5LogoutResponseResolver; |
44 | 50 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestFilter;
|
45 | 51 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestRepository;
|
46 | 52 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestResolver;
|
| 53 | +import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestValidatorParametersResolver; |
47 | 54 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutResponseFilter;
|
48 | 55 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutResponseResolver;
|
49 | 56 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2RelyingPartyInitiatedLogoutSuccessHandler;
|
|
106 | 113 | public final class Saml2LogoutConfigurer<H extends HttpSecurityBuilder<H>>
|
107 | 114 | extends AbstractHttpConfigurer<Saml2LogoutConfigurer<H>, H> {
|
108 | 115 |
|
| 116 | + private static final boolean USE_OPENSAML_5 = Version.getVersion().startsWith("5"); |
| 117 | + |
109 | 118 | private ApplicationContext context;
|
110 | 119 |
|
111 | 120 | private RelyingPartyRegistrationRepository relyingPartyRegistrationRepository;
|
@@ -250,14 +259,26 @@ private Saml2LogoutRequestFilter createLogoutRequestProcessingFilter(
|
250 | 259 | RelyingPartyRegistrationRepository registrations) {
|
251 | 260 | LogoutHandler[] logoutHandlers = this.logoutHandlers.toArray(new LogoutHandler[0]);
|
252 | 261 | Saml2LogoutResponseResolver logoutResponseResolver = createSaml2LogoutResponseResolver(registrations);
|
| 262 | + Saml2LogoutRequestFilter filter = new Saml2LogoutRequestFilter( |
| 263 | + createSaml2LogoutResponseParametersResolver(registrations), |
| 264 | + this.logoutRequestConfigurer.logoutRequestValidator(), logoutResponseResolver, logoutHandlers); |
| 265 | + filter.setSecurityContextHolderStrategy(getSecurityContextHolderStrategy()); |
| 266 | + return postProcess(filter); |
| 267 | + } |
| 268 | + |
| 269 | + private Saml2LogoutRequestValidatorParametersResolver createSaml2LogoutResponseParametersResolver( |
| 270 | + RelyingPartyRegistrationRepository registrations) { |
253 | 271 | RequestMatcher requestMatcher = createLogoutRequestMatcher();
|
| 272 | + if (USE_OPENSAML_5) { |
| 273 | + OpenSaml5LogoutRequestValidatorParametersResolver parameters = new OpenSaml5LogoutRequestValidatorParametersResolver( |
| 274 | + registrations); |
| 275 | + parameters.setRequestMatcher(requestMatcher); |
| 276 | + return parameters; |
| 277 | + } |
254 | 278 | OpenSaml4LogoutRequestValidatorParametersResolver parameters = new OpenSaml4LogoutRequestValidatorParametersResolver(
|
255 | 279 | registrations);
|
256 | 280 | parameters.setRequestMatcher(requestMatcher);
|
257 |
| - Saml2LogoutRequestFilter filter = new Saml2LogoutRequestFilter(parameters, |
258 |
| - this.logoutRequestConfigurer.logoutRequestValidator(), logoutResponseResolver, logoutHandlers); |
259 |
| - filter.setSecurityContextHolderStrategy(getSecurityContextHolderStrategy()); |
260 |
| - return postProcess(filter); |
| 281 | + return parameters; |
261 | 282 | }
|
262 | 283 |
|
263 | 284 | private Saml2LogoutResponseFilter createLogoutResponseProcessingFilter(
|
@@ -397,16 +418,22 @@ public Saml2LogoutConfigurer<H> and() {
|
397 | 418 | }
|
398 | 419 |
|
399 | 420 | private Saml2LogoutRequestValidator logoutRequestValidator() {
|
400 |
| - if (this.logoutRequestValidator == null) { |
401 |
| - return new OpenSaml4LogoutRequestValidator(); |
| 421 | + if (this.logoutRequestValidator != null) { |
| 422 | + return this.logoutRequestValidator; |
402 | 423 | }
|
403 |
| - return this.logoutRequestValidator; |
| 424 | + if (USE_OPENSAML_5) { |
| 425 | + return new OpenSaml5LogoutRequestValidator(); |
| 426 | + } |
| 427 | + return new OpenSaml4LogoutRequestValidator(); |
404 | 428 | }
|
405 | 429 |
|
406 | 430 | private Saml2LogoutRequestResolver logoutRequestResolver(RelyingPartyRegistrationRepository registrations) {
|
407 | 431 | if (this.logoutRequestResolver != null) {
|
408 | 432 | return this.logoutRequestResolver;
|
409 | 433 | }
|
| 434 | + if (USE_OPENSAML_5) { |
| 435 | + return new OpenSaml5LogoutRequestResolver(registrations); |
| 436 | + } |
410 | 437 | return new OpenSaml4LogoutRequestResolver(registrations);
|
411 | 438 | }
|
412 | 439 |
|
@@ -473,17 +500,23 @@ public Saml2LogoutConfigurer<H> and() {
|
473 | 500 | }
|
474 | 501 |
|
475 | 502 | private Saml2LogoutResponseValidator logoutResponseValidator() {
|
476 |
| - if (this.logoutResponseValidator == null) { |
477 |
| - return new OpenSaml4LogoutResponseValidator(); |
| 503 | + if (this.logoutResponseValidator != null) { |
| 504 | + return this.logoutResponseValidator; |
478 | 505 | }
|
479 |
| - return this.logoutResponseValidator; |
| 506 | + if (USE_OPENSAML_5) { |
| 507 | + return new OpenSaml5LogoutResponseValidator(); |
| 508 | + } |
| 509 | + return new OpenSaml4LogoutResponseValidator(); |
480 | 510 | }
|
481 | 511 |
|
482 | 512 | private Saml2LogoutResponseResolver logoutResponseResolver(RelyingPartyRegistrationRepository registrations) {
|
483 |
| - if (this.logoutResponseResolver == null) { |
484 |
| - return new OpenSaml4LogoutResponseResolver(registrations); |
| 513 | + if (this.logoutResponseResolver != null) { |
| 514 | + return this.logoutResponseResolver; |
| 515 | + } |
| 516 | + if (USE_OPENSAML_5) { |
| 517 | + return new OpenSaml5LogoutResponseResolver(registrations); |
485 | 518 | }
|
486 |
| - return this.logoutResponseResolver; |
| 519 | + return new OpenSaml4LogoutResponseResolver(registrations); |
487 | 520 | }
|
488 | 521 |
|
489 | 522 | }
|
|
0 commit comments