|
@@ -1,5 +1,5 @@
|
|
|
/*
|
|
|
- * Copyright 2002-2022 the original author or authors.
|
|
|
+ * Copyright 2002-2023 the original author or authors.
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -18,6 +18,9 @@ package org.springframework.security.saml2.provider.service.web.authentication;
|
|
|
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
+import org.junit.jupiter.params.ParameterizedTest;
|
|
|
+import org.junit.jupiter.params.provider.Arguments;
|
|
|
+import org.junit.jupiter.params.provider.MethodSource;
|
|
|
import org.opensaml.xmlsec.signature.support.SignatureConstants;
|
|
|
|
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
@@ -32,6 +35,8 @@ import org.springframework.security.saml2.provider.service.registration.TestRely
|
|
|
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationPlaceholderResolvers;
|
|
|
import org.springframework.security.saml2.provider.service.web.RelyingPartyRegistrationPlaceholderResolvers.UriResolver;
|
|
|
|
|
|
+import java.util.stream.Stream;
|
|
|
+
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
|
@@ -47,11 +52,15 @@ public class OpenSamlAuthenticationRequestResolverTests {
|
|
|
this.relyingPartyRegistrationBuilder = TestRelyingPartyRegistrations.relyingPartyRegistration();
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void resolveAuthenticationRequestWhenSignedRedirectThenSignsAndRedirects() {
|
|
|
+ @ParameterizedTest
|
|
|
+ @MethodSource("provideSignRequestFlags")
|
|
|
+ public void resolveAuthenticationRequestWhenSignedRedirectThenSignsAndRedirects(boolean wantAuthRequestsSigned, boolean authnRequestsSigned) {
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
request.setPathInfo("/saml2/authenticate/registration-id");
|
|
|
- RelyingPartyRegistration registration = this.relyingPartyRegistrationBuilder.build();
|
|
|
+ RelyingPartyRegistration registration = this.relyingPartyRegistrationBuilder
|
|
|
+ .authnRequestsSigned(authnRequestsSigned)
|
|
|
+ .assertingPartyDetails(party -> party.wantAuthnRequestsSigned(wantAuthRequestsSigned))
|
|
|
+ .build();
|
|
|
OpenSamlAuthenticationRequestResolver resolver = authenticationRequestResolver(registration);
|
|
|
Saml2RedirectAuthenticationRequest result = resolver.resolve(request, (r, authnRequest) -> {
|
|
|
UriResolver uriResolver = RelyingPartyRegistrationPlaceholderResolvers.uriResolver(request, registration);
|
|
@@ -113,8 +122,9 @@ public class OpenSamlAuthenticationRequestResolverTests {
|
|
|
public void resolveAuthenticationRequestWhenUnsignedPostThenOnlyPosts() {
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
request.setPathInfo("/saml2/authenticate/registration-id");
|
|
|
- RelyingPartyRegistration registration = this.relyingPartyRegistrationBuilder.assertingPartyDetails(
|
|
|
- (party) -> party.singleSignOnServiceBinding(Saml2MessageBinding.POST).wantAuthnRequestsSigned(false))
|
|
|
+ RelyingPartyRegistration registration = this.relyingPartyRegistrationBuilder
|
|
|
+ .assertingPartyDetails((party) -> party.singleSignOnServiceBinding(Saml2MessageBinding.POST).wantAuthnRequestsSigned(false))
|
|
|
+ .authnRequestsSigned(false)
|
|
|
.build();
|
|
|
OpenSamlAuthenticationRequestResolver resolver = authenticationRequestResolver(registration);
|
|
|
Saml2PostAuthenticationRequest result = resolver.resolve(request, (r, authnRequest) -> {
|
|
@@ -134,12 +144,16 @@ public class OpenSamlAuthenticationRequestResolverTests {
|
|
|
assertThat(result.getId()).isNotEmpty();
|
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
- public void resolveAuthenticationRequestWhenSignedPostThenSignsAndPosts() {
|
|
|
+ @ParameterizedTest
|
|
|
+ @MethodSource("provideSignRequestFlags")
|
|
|
+ public void resolveAuthenticationRequestWhenSignedPostThenSignsAndPosts(boolean wantAuthRequestsSigned, boolean authnRequestsSigned) {
|
|
|
MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
request.setPathInfo("/saml2/authenticate/registration-id");
|
|
|
RelyingPartyRegistration registration = this.relyingPartyRegistrationBuilder
|
|
|
- .assertingPartyDetails((party) -> party.singleSignOnServiceBinding(Saml2MessageBinding.POST)).build();
|
|
|
+ .authnRequestsSigned(authnRequestsSigned)
|
|
|
+ .assertingPartyDetails((party) -> party.singleSignOnServiceBinding(Saml2MessageBinding.POST)
|
|
|
+ .wantAuthnRequestsSigned(wantAuthRequestsSigned))
|
|
|
+ .build();
|
|
|
OpenSamlAuthenticationRequestResolver resolver = authenticationRequestResolver(registration);
|
|
|
Saml2PostAuthenticationRequest result = resolver.resolve(request, (r, authnRequest) -> {
|
|
|
UriResolver uriResolver = RelyingPartyRegistrationPlaceholderResolvers.uriResolver(request, registration);
|
|
@@ -180,4 +194,12 @@ public class OpenSamlAuthenticationRequestResolverTests {
|
|
|
return new OpenSamlAuthenticationRequestResolver((request, id) -> registration);
|
|
|
}
|
|
|
|
|
|
+ private static Stream<Arguments> provideSignRequestFlags() {
|
|
|
+ return Stream.of(
|
|
|
+ Arguments.of(true, true),
|
|
|
+ Arguments.of(true, false),
|
|
|
+ Arguments.of(false, true)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
}
|