|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2023 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.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.security.config.http;
|
18 | 18 |
|
| 19 | +import org.opensaml.core.Version; |
19 | 20 | import org.w3c.dom.Element;
|
20 | 21 |
|
21 | 22 | import org.springframework.beans.BeanMetadataElement;
|
|
25 | 26 | import org.springframework.security.saml2.provider.service.authentication.logout.OpenSamlLogoutResponseValidator;
|
26 | 27 | import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
27 | 28 | import org.springframework.security.saml2.provider.service.web.authentication.logout.HttpSessionLogoutRequestRepository;
|
| 29 | +import org.springframework.util.ClassUtils; |
28 | 30 | import org.springframework.util.StringUtils;
|
29 | 31 |
|
30 | 32 | /**
|
|
33 | 35 | */
|
34 | 36 | final class Saml2LogoutBeanDefinitionParserUtils {
|
35 | 37 |
|
| 38 | + private static final String OPEN_SAML_4_VERSION = "4"; |
| 39 | + |
36 | 40 | private static final String ATT_RELYING_PARTY_REGISTRATION_REPOSITORY_REF = "relying-party-registration-repository-ref";
|
37 | 41 |
|
38 | 42 | private static final String ATT_LOGOUT_REQUEST_VALIDATOR_REF = "logout-request-validator-ref";
|
@@ -62,8 +66,14 @@ static BeanMetadataElement getLogoutResponseResolver(Element element, BeanMetada
|
62 | 66 | if (StringUtils.hasText(logoutResponseResolver)) {
|
63 | 67 | return new RuntimeBeanReference(logoutResponseResolver);
|
64 | 68 | }
|
| 69 | + if (version().startsWith("4")) { |
| 70 | + return BeanDefinitionBuilder.rootBeanDefinition( |
| 71 | + "org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver") |
| 72 | + .addConstructorArgValue(registrations) |
| 73 | + .getBeanDefinition(); |
| 74 | + } |
65 | 75 | return BeanDefinitionBuilder.rootBeanDefinition(
|
66 |
| - "org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver") |
| 76 | + "org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSamlLogoutResponseResolver") |
67 | 77 | .addConstructorArgValue(registrations)
|
68 | 78 | .getBeanDefinition();
|
69 | 79 | }
|
@@ -97,10 +107,29 @@ static BeanMetadataElement getLogoutRequestResolver(Element element, BeanMetadat
|
97 | 107 | if (StringUtils.hasText(logoutRequestResolver)) {
|
98 | 108 | return new RuntimeBeanReference(logoutRequestResolver);
|
99 | 109 | }
|
| 110 | + if (version().startsWith("4")) { |
| 111 | + return BeanDefinitionBuilder.rootBeanDefinition( |
| 112 | + "org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutRequestResolver") |
| 113 | + .addConstructorArgValue(registrations) |
| 114 | + .getBeanDefinition(); |
| 115 | + } |
100 | 116 | return BeanDefinitionBuilder.rootBeanDefinition(
|
101 |
| - "org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutRequestResolver") |
| 117 | + "org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSamlLogoutRequestResolver") |
102 | 118 | .addConstructorArgValue(registrations)
|
103 | 119 | .getBeanDefinition();
|
104 | 120 | }
|
105 | 121 |
|
| 122 | + static String version() { |
| 123 | + String version = Version.getVersion(); |
| 124 | + if (StringUtils.hasText(version)) { |
| 125 | + return version; |
| 126 | + } |
| 127 | + boolean openSaml4ClassPresent = ClassUtils |
| 128 | + .isPresent("org.opensaml.core.xml.persist.impl.PassthroughSourceStrategy", null); |
| 129 | + if (openSaml4ClassPresent) { |
| 130 | + return OPEN_SAML_4_VERSION; |
| 131 | + } |
| 132 | + throw new IllegalStateException("cannot determine OpenSAML version"); |
| 133 | + } |
| 134 | + |
106 | 135 | }
|
0 commit comments