|
25 | 25 | import jakarta.servlet.ServletException;
|
26 | 26 | import jakarta.servlet.http.HttpServletRequest;
|
27 | 27 | import jakarta.servlet.http.HttpServletResponse;
|
28 |
| -import net.shibboleth.utilities.java.support.xml.SerializeSupport; |
| 28 | +import org.instancio.internal.util.ReflectionUtils; |
29 | 29 | import org.junit.jupiter.api.AfterEach;
|
30 | 30 | import org.junit.jupiter.api.BeforeAll;
|
31 | 31 | import org.junit.jupiter.api.BeforeEach;
|
32 | 32 | import org.junit.jupiter.api.Test;
|
33 | 33 | import org.junit.jupiter.api.extension.ExtendWith;
|
34 | 34 | import org.mockito.ArgumentCaptor;
|
| 35 | +import org.opensaml.core.Version; |
35 | 36 | import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
|
36 | 37 | import org.opensaml.core.xml.io.Marshaller;
|
37 | 38 | import org.opensaml.saml.saml2.core.Assertion;
|
|
69 | 70 | import org.springframework.security.saml2.core.TestSaml2X509Credentials;
|
70 | 71 | import org.springframework.security.saml2.provider.service.authentication.AbstractSaml2AuthenticationRequest;
|
71 | 72 | import org.springframework.security.saml2.provider.service.authentication.OpenSaml4AuthenticationProvider;
|
| 73 | +import org.springframework.security.saml2.provider.service.authentication.OpenSaml5AuthenticationProvider; |
72 | 74 | import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticatedPrincipal;
|
73 | 75 | import org.springframework.security.saml2.provider.service.authentication.Saml2Authentication;
|
74 | 76 | import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException;
|
|
83 | 85 | import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationRequestRepository;
|
84 | 86 | import org.springframework.security.saml2.provider.service.web.Saml2AuthenticationTokenConverter;
|
85 | 87 | import org.springframework.security.saml2.provider.service.web.authentication.OpenSaml4AuthenticationRequestResolver;
|
| 88 | +import org.springframework.security.saml2.provider.service.web.authentication.OpenSaml5AuthenticationRequestResolver; |
86 | 89 | import org.springframework.security.saml2.provider.service.web.authentication.Saml2AuthenticationRequestResolver;
|
87 | 90 | import org.springframework.security.web.FilterChainProxy;
|
88 | 91 | import org.springframework.security.web.SecurityFilterChain;
|
|
91 | 94 | import org.springframework.security.web.context.HttpRequestResponseHolder;
|
92 | 95 | import org.springframework.security.web.context.HttpSessionSecurityContextRepository;
|
93 | 96 | import org.springframework.security.web.context.SecurityContextRepository;
|
| 97 | +import org.springframework.test.util.ReflectionTestUtils; |
94 | 98 | import org.springframework.test.web.servlet.MockMvc;
|
95 | 99 | import org.springframework.test.web.servlet.MvcResult;
|
96 | 100 | import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
|
@@ -134,6 +138,8 @@ public class Saml2LoginConfigurerTests {
|
134 | 138 | .verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential())))
|
135 | 139 | .build();
|
136 | 140 |
|
| 141 | + private static final boolean USE_OPENSAML_5 = Version.getVersion().startsWith("5"); |
| 142 | + |
137 | 143 | private static String SIGNED_RESPONSE;
|
138 | 144 |
|
139 | 145 | private static final AuthenticationConverter AUTHENTICATION_CONVERTER = mock(AuthenticationConverter.class);
|
@@ -174,7 +180,11 @@ static void createResponse() throws Exception {
|
174 | 180 | registration.getSigningX509Credentials().iterator().next(), relyingPartyEntityId);
|
175 | 181 | Marshaller marshaller = XMLObjectProviderRegistrySupport.getMarshallerFactory().getMarshaller(signed);
|
176 | 182 | Element element = marshaller.marshall(signed);
|
177 |
| - String serialized = SerializeSupport.nodeToString(element); |
| 183 | + Class<?> clazz = ReflectionUtils.loadClass("net.shibboleth.utilities.java.support.xml.SerializeSupport"); |
| 184 | + if (clazz == null) { |
| 185 | + clazz = ReflectionUtils.loadClass("net.shibboleth.shared.xml.SerializeSupport"); |
| 186 | + } |
| 187 | + String serialized = ReflectionTestUtils.invokeMethod(clazz, "nodeToString", element); |
178 | 188 | SIGNED_RESPONSE = Saml2Utils.samlEncode(serialized.getBytes(StandardCharsets.UTF_8));
|
179 | 189 | }
|
180 | 190 |
|
@@ -541,6 +551,12 @@ Saml2AuthenticationRequestResolver authenticationRequestResolver(
|
541 | 551 | RelyingPartyRegistrationRepository registrations) {
|
542 | 552 | RelyingPartyRegistrationResolver registrationResolver = new DefaultRelyingPartyRegistrationResolver(
|
543 | 553 | registrations);
|
| 554 | + if (USE_OPENSAML_5) { |
| 555 | + OpenSaml5AuthenticationRequestResolver delegate = new OpenSaml5AuthenticationRequestResolver( |
| 556 | + registrationResolver); |
| 557 | + delegate.setAuthnRequestCustomizer((parameters) -> parameters.getAuthnRequest().setForceAuthn(true)); |
| 558 | + return delegate; |
| 559 | + } |
544 | 560 | OpenSaml4AuthenticationRequestResolver delegate = new OpenSaml4AuthenticationRequestResolver(
|
545 | 561 | registrationResolver);
|
546 | 562 | delegate.setAuthnRequestCustomizer((parameters) -> parameters.getAuthnRequest().setForceAuthn(true));
|
@@ -574,6 +590,12 @@ Saml2AuthenticationRequestResolver authenticationRequestResolver(
|
574 | 590 | RelyingPartyRegistrationRepository registrations) {
|
575 | 591 | RelyingPartyRegistrationResolver registrationResolver = new DefaultRelyingPartyRegistrationResolver(
|
576 | 592 | registrations);
|
| 593 | + if (USE_OPENSAML_5) { |
| 594 | + OpenSaml5AuthenticationRequestResolver delegate = new OpenSaml5AuthenticationRequestResolver( |
| 595 | + registrationResolver); |
| 596 | + delegate.setAuthnRequestCustomizer((parameters) -> parameters.getAuthnRequest().setForceAuthn(true)); |
| 597 | + return delegate; |
| 598 | + } |
577 | 599 | OpenSaml4AuthenticationRequestResolver delegate = new OpenSaml4AuthenticationRequestResolver(
|
578 | 600 | registrationResolver);
|
579 | 601 | delegate.setAuthnRequestCustomizer((parameters) -> parameters.getAuthnRequest().setForceAuthn(true));
|
@@ -752,7 +774,8 @@ Saml2AuthenticationTokenConverter authenticationTokenConverter() {
|
752 | 774 | @Import(Saml2LoginConfigBeans.class)
|
753 | 775 | static class CustomAuthenticationProviderConfig {
|
754 | 776 |
|
755 |
| - private final OpenSaml4AuthenticationProvider provider = spy(new OpenSaml4AuthenticationProvider()); |
| 777 | + private final AuthenticationProvider provider = spy( |
| 778 | + USE_OPENSAML_5 ? new OpenSaml5AuthenticationProvider() : new OpenSaml4AuthenticationProvider()); |
756 | 779 |
|
757 | 780 | @Bean
|
758 | 781 | SecurityFilterChain web(HttpSecurity http) throws Exception {
|
|
0 commit comments