|
33 | 33 | import org.springframework.beans.factory.xml.ParserContext;
|
34 | 34 | import org.springframework.security.core.Authentication;
|
35 | 35 | import org.springframework.security.core.context.SecurityContextHolder;
|
| 36 | +import org.springframework.security.core.context.SecurityContextHolderStrategy; |
36 | 37 | import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
|
37 | 38 | import org.springframework.security.saml2.provider.service.web.DefaultRelyingPartyRegistrationResolver;
|
38 | 39 | import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestFilter;
|
@@ -166,6 +167,8 @@ private BeanMetadataElement createLogoutRequestMatcher() {
|
166 | 167 | BeanMetadataElement logoutMatcher = BeanDefinitionBuilder.rootBeanDefinition(AntPathRequestMatcher.class)
|
167 | 168 | .addConstructorArgValue(this.logoutUrl).addConstructorArgValue("POST").getBeanDefinition();
|
168 | 169 | BeanMetadataElement saml2Matcher = BeanDefinitionBuilder.rootBeanDefinition(Saml2RequestMatcher.class)
|
| 170 | + .addPropertyValue("securityContextHolderStrategy", |
| 171 | + this.authenticationFilterSecurityContextHolderStrategy) |
169 | 172 | .getBeanDefinition();
|
170 | 173 | return BeanDefinitionBuilder.rootBeanDefinition(AndRequestMatcher.class)
|
171 | 174 | .addConstructorArgValue(toManagedList(logoutMatcher, saml2Matcher)).getBeanDefinition();
|
@@ -227,17 +230,24 @@ public boolean matches(HttpServletRequest request) {
|
227 | 230 |
|
228 | 231 | }
|
229 | 232 |
|
230 |
| - private static class Saml2RequestMatcher implements RequestMatcher { |
| 233 | + public static class Saml2RequestMatcher implements RequestMatcher { |
| 234 | + |
| 235 | + private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder |
| 236 | + .getContextHolderStrategy(); |
231 | 237 |
|
232 | 238 | @Override
|
233 | 239 | public boolean matches(HttpServletRequest request) {
|
234 |
| - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); |
| 240 | + Authentication authentication = this.securityContextHolderStrategy.getContext().getAuthentication(); |
235 | 241 | if (authentication == null) {
|
236 | 242 | return false;
|
237 | 243 | }
|
238 | 244 | return authentication.getPrincipal() instanceof Saml2AuthenticatedPrincipal;
|
239 | 245 | }
|
240 | 246 |
|
| 247 | + public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) { |
| 248 | + this.securityContextHolderStrategy = securityContextHolderStrategy; |
| 249 | + } |
| 250 | + |
241 | 251 | }
|
242 | 252 |
|
243 | 253 | }
|
0 commit comments