|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
70 | 70 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestFilter;
|
71 | 71 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestRepository;
|
72 | 72 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestResolver;
|
| 73 | +import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestValidatorParametersResolver; |
73 | 74 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutResponseFilter;
|
74 | 75 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutResponseResolver;
|
75 | 76 | import org.springframework.security.web.SecurityFilterChain;
|
@@ -542,6 +543,22 @@ public void saml2LogoutWhenLogoutFilterPostProcessedThenUses() {
|
542 | 543 |
|
543 | 544 | }
|
544 | 545 |
|
| 546 | + @Test |
| 547 | + public void saml2LogoutWhenCustomLogoutRequestParametersResolverBeanThenUses() throws Exception { |
| 548 | + this.spring.register(Saml2DefaultsWithLogoutRequestParametersResolverBeanConfig.class).autowire(); |
| 549 | + this.mvc.perform(post("/logout").with(authentication(this.user)).with(csrf())); |
| 550 | + verify(Saml2DefaultsWithLogoutRequestParametersResolverBeanConfig.logoutRequestParametersResolver) |
| 551 | + .resolve(any(), eq(this.user)); |
| 552 | + } |
| 553 | + |
| 554 | + @Test |
| 555 | + public void saml2LogoutWhenCustomLogoutRequestParametersResolverSetThenUses() throws Exception { |
| 556 | + this.spring.register(Saml2DefaultsWithLogoutRequestParametersResolverSetConfig.class).autowire(); |
| 557 | + this.mvc.perform(post("/logout").with(authentication(this.user)).with(csrf())); |
| 558 | + verify(Saml2DefaultsWithLogoutRequestParametersResolverSetConfig.logoutRequestParametersResolver).resolve(any(), |
| 559 | + eq(this.user)); |
| 560 | + } |
| 561 | + |
545 | 562 | private <T> T getBean(Class<T> clazz) {
|
546 | 563 | return this.spring.getContext().getBean(clazz);
|
547 | 564 | }
|
@@ -723,6 +740,55 @@ Saml2LogoutResponseResolver logoutResponseResolver() {
|
723 | 740 |
|
724 | 741 | }
|
725 | 742 |
|
| 743 | + @Configuration |
| 744 | + @EnableWebSecurity |
| 745 | + @Import(Saml2LoginConfigBeans.class) |
| 746 | + static class Saml2DefaultsWithLogoutRequestParametersResolverBeanConfig { |
| 747 | + |
| 748 | + static Saml2LogoutRequestValidatorParametersResolver logoutRequestParametersResolver = mock( |
| 749 | + Saml2LogoutRequestValidatorParametersResolver.class); |
| 750 | + |
| 751 | + @Bean |
| 752 | + SecurityFilterChain web(HttpSecurity http) throws Exception { |
| 753 | + // @formatter:off |
| 754 | + http |
| 755 | + .authorizeRequests((authorize) -> authorize.anyRequest().authenticated()) |
| 756 | + .saml2Login(withDefaults()) |
| 757 | + .saml2Logout(withDefaults()); |
| 758 | + return http.build(); |
| 759 | + // @formatter:on |
| 760 | + } |
| 761 | + |
| 762 | + @Bean |
| 763 | + Saml2LogoutRequestValidatorParametersResolver logoutRequestParametersResolver() { |
| 764 | + return logoutRequestParametersResolver; |
| 765 | + } |
| 766 | + |
| 767 | + } |
| 768 | + |
| 769 | + @Configuration |
| 770 | + @EnableWebSecurity |
| 771 | + @Import(Saml2LoginConfigBeans.class) |
| 772 | + static class Saml2DefaultsWithLogoutRequestParametersResolverSetConfig { |
| 773 | + |
| 774 | + static Saml2LogoutRequestValidatorParametersResolver logoutRequestParametersResolver = mock( |
| 775 | + Saml2LogoutRequestValidatorParametersResolver.class); |
| 776 | + |
| 777 | + @Bean |
| 778 | + SecurityFilterChain web(HttpSecurity http) throws Exception { |
| 779 | + // @formatter:off |
| 780 | + http |
| 781 | + .authorizeRequests((authorize) -> authorize.anyRequest().authenticated()) |
| 782 | + .saml2Login(withDefaults()) |
| 783 | + .saml2Logout((logout) -> logout |
| 784 | + .logoutRequest((logoutRequest) -> logoutRequest |
| 785 | + .logoutRequestParametersResolver(logoutRequestParametersResolver))); |
| 786 | + return http.build(); |
| 787 | + // @formatter:on |
| 788 | + } |
| 789 | + |
| 790 | + } |
| 791 | + |
726 | 792 | static class Saml2LoginConfigBeans {
|
727 | 793 |
|
728 | 794 | @Bean
|
|
0 commit comments