|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.security.saml2.core.Saml2X509Credential; |
|
|
|
import org.springframework.security.saml2.core.Saml2X509Credential; |
|
|
|
import org.springframework.security.saml2.core.TestSaml2X509Credentials; |
|
|
|
import org.springframework.security.saml2.core.TestSaml2X509Credentials; |
|
|
|
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistration.AssertingPartyDetails; |
|
|
|
|
|
|
|
import org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter; |
|
|
|
import org.springframework.security.saml2.provider.service.web.authentication.Saml2WebSsoAuthenticationFilter; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
@ -37,12 +36,12 @@ public class RelyingPartyRegistrationTests { |
|
|
|
RelyingPartyRegistration registration = TestRelyingPartyRegistrations.relyingPartyRegistration() |
|
|
|
RelyingPartyRegistration registration = TestRelyingPartyRegistrations.relyingPartyRegistration() |
|
|
|
.nameIdFormat("format") |
|
|
|
.nameIdFormat("format") |
|
|
|
.authnRequestsSigned(true) |
|
|
|
.authnRequestsSigned(true) |
|
|
|
.assertingPartyDetails((a) -> a.singleSignOnServiceBinding(Saml2MessageBinding.POST)) |
|
|
|
.assertingPartyMetadata((a) -> a.singleSignOnServiceBinding(Saml2MessageBinding.POST)) |
|
|
|
.assertingPartyDetails((a) -> a.wantAuthnRequestsSigned(false)) |
|
|
|
.assertingPartyMetadata((a) -> a.wantAuthnRequestsSigned(false)) |
|
|
|
.assertingPartyDetails((a) -> a.signingAlgorithms((algs) -> algs.add("alg"))) |
|
|
|
.assertingPartyMetadata((a) -> a.signingAlgorithms((algs) -> algs.add("alg"))) |
|
|
|
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT) |
|
|
|
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
RelyingPartyRegistration copy = RelyingPartyRegistration.withRelyingPartyRegistration(registration).build(); |
|
|
|
RelyingPartyRegistration copy = registration.mutate().build(); |
|
|
|
compareRegistrations(registration, copy); |
|
|
|
compareRegistrations(registration, copy); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -50,9 +49,9 @@ public class RelyingPartyRegistrationTests { |
|
|
|
void mutateWhenInvokedThenCreatesCopy() { |
|
|
|
void mutateWhenInvokedThenCreatesCopy() { |
|
|
|
RelyingPartyRegistration registration = TestRelyingPartyRegistrations.relyingPartyRegistration() |
|
|
|
RelyingPartyRegistration registration = TestRelyingPartyRegistrations.relyingPartyRegistration() |
|
|
|
.nameIdFormat("format") |
|
|
|
.nameIdFormat("format") |
|
|
|
.assertingPartyDetails((a) -> a.singleSignOnServiceBinding(Saml2MessageBinding.POST)) |
|
|
|
.assertingPartyMetadata((a) -> a.singleSignOnServiceBinding(Saml2MessageBinding.POST)) |
|
|
|
.assertingPartyDetails((a) -> a.wantAuthnRequestsSigned(false)) |
|
|
|
.assertingPartyMetadata((a) -> a.wantAuthnRequestsSigned(false)) |
|
|
|
.assertingPartyDetails((a) -> a.signingAlgorithms((algs) -> algs.add("alg"))) |
|
|
|
.assertingPartyMetadata((a) -> a.signingAlgorithms((algs) -> algs.add("alg"))) |
|
|
|
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT) |
|
|
|
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
RelyingPartyRegistration copy = registration.mutate().build(); |
|
|
|
RelyingPartyRegistration copy = registration.mutate().build(); |
|
|
|
@ -61,8 +60,8 @@ public class RelyingPartyRegistrationTests { |
|
|
|
|
|
|
|
|
|
|
|
private void compareRegistrations(RelyingPartyRegistration registration, RelyingPartyRegistration copy) { |
|
|
|
private void compareRegistrations(RelyingPartyRegistration registration, RelyingPartyRegistration copy) { |
|
|
|
assertThat(copy.getRegistrationId()).isEqualTo(registration.getRegistrationId()).isEqualTo("simplesamlphp"); |
|
|
|
assertThat(copy.getRegistrationId()).isEqualTo(registration.getRegistrationId()).isEqualTo("simplesamlphp"); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getEntityId()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getEntityId()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getEntityId()) |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getEntityId()) |
|
|
|
.isEqualTo("https://simplesaml-for-spring-saml.apps.pcfone.io/saml2/idp/metadata.php"); |
|
|
|
.isEqualTo("https://simplesaml-for-spring-saml.apps.pcfone.io/saml2/idp/metadata.php"); |
|
|
|
assertThat(copy.getAssertionConsumerServiceLocation()) |
|
|
|
assertThat(copy.getAssertionConsumerServiceLocation()) |
|
|
|
.isEqualTo(registration.getAssertionConsumerServiceLocation()) |
|
|
|
.isEqualTo(registration.getAssertionConsumerServiceLocation()) |
|
|
|
@ -73,25 +72,25 @@ public class RelyingPartyRegistrationTests { |
|
|
|
.isEqualTo(copy.getEntityId()) |
|
|
|
.isEqualTo(copy.getEntityId()) |
|
|
|
.isEqualTo(registration.getEntityId()) |
|
|
|
.isEqualTo(registration.getEntityId()) |
|
|
|
.isEqualTo("{baseUrl}/saml2/service-provider-metadata/{registrationId}"); |
|
|
|
.isEqualTo("{baseUrl}/saml2/service-provider-metadata/{registrationId}"); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getSingleSignOnServiceLocation()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getSingleSignOnServiceLocation()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getSingleSignOnServiceLocation()) |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getSingleSignOnServiceLocation()) |
|
|
|
.isEqualTo("https://simplesaml-for-spring-saml.apps.pcfone.io/saml2/idp/SSOService.php"); |
|
|
|
.isEqualTo("https://simplesaml-for-spring-saml.apps.pcfone.io/saml2/idp/SSOService.php"); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getSingleSignOnServiceBinding()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getSingleSignOnServiceBinding()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getSingleSignOnServiceBinding()) |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getSingleSignOnServiceBinding()) |
|
|
|
.isEqualTo(Saml2MessageBinding.POST); |
|
|
|
.isEqualTo(Saml2MessageBinding.POST); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getWantAuthnRequestsSigned()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getWantAuthnRequestsSigned()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getWantAuthnRequestsSigned()) |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getWantAuthnRequestsSigned()) |
|
|
|
.isFalse(); |
|
|
|
.isFalse(); |
|
|
|
assertThat(copy.getAssertionConsumerServiceBinding()) |
|
|
|
assertThat(copy.getAssertionConsumerServiceBinding()) |
|
|
|
.isEqualTo(registration.getAssertionConsumerServiceBinding()); |
|
|
|
.isEqualTo(registration.getAssertionConsumerServiceBinding()); |
|
|
|
assertThat(copy.getDecryptionX509Credentials()).isEqualTo(registration.getDecryptionX509Credentials()); |
|
|
|
assertThat(copy.getDecryptionX509Credentials()).isEqualTo(registration.getDecryptionX509Credentials()); |
|
|
|
assertThat(copy.getSigningX509Credentials()).isEqualTo(registration.getSigningX509Credentials()); |
|
|
|
assertThat(copy.getSigningX509Credentials()).isEqualTo(registration.getSigningX509Credentials()); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getEncryptionX509Credentials()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getEncryptionX509Credentials()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getEncryptionX509Credentials()); |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getEncryptionX509Credentials()); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getVerificationX509Credentials()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getVerificationX509Credentials()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getVerificationX509Credentials()); |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getVerificationX509Credentials()); |
|
|
|
assertThat(copy.getAssertingPartyDetails().getSigningAlgorithms()) |
|
|
|
assertThat(copy.getAssertingPartyMetadata().getSigningAlgorithms()) |
|
|
|
.isEqualTo(registration.getAssertingPartyDetails().getSigningAlgorithms()); |
|
|
|
.isEqualTo(registration.getAssertingPartyMetadata().getSigningAlgorithms()); |
|
|
|
assertThat(copy.getNameIdFormat()).isEqualTo(registration.getNameIdFormat()); |
|
|
|
assertThat(copy.getNameIdFormat()).isEqualTo(registration.getNameIdFormat()); |
|
|
|
assertThat(copy.isAuthnRequestsSigned()).isEqualTo(registration.isAuthnRequestsSigned()); |
|
|
|
assertThat(copy.isAuthnRequestsSigned()).isEqualTo(registration.isAuthnRequestsSigned()); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -101,7 +100,7 @@ public class RelyingPartyRegistrationTests { |
|
|
|
RelyingPartyRegistration relyingPartyRegistration = RelyingPartyRegistration.withRegistrationId("id") |
|
|
|
RelyingPartyRegistration relyingPartyRegistration = RelyingPartyRegistration.withRegistrationId("id") |
|
|
|
.entityId("entity-id") |
|
|
|
.entityId("entity-id") |
|
|
|
.assertionConsumerServiceLocation("location") |
|
|
|
.assertionConsumerServiceLocation("location") |
|
|
|
.assertingPartyDetails((assertingParty) -> assertingParty.entityId("entity-id") |
|
|
|
.assertingPartyMetadata((assertingParty) -> assertingParty.entityId("entity-id") |
|
|
|
.singleSignOnServiceLocation("location") |
|
|
|
.singleSignOnServiceLocation("location") |
|
|
|
.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()))) |
|
|
|
.verificationX509Credentials((c) -> c.add(TestSaml2X509Credentials.relyingPartyVerifyingCredential()))) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
@ -119,7 +118,7 @@ public class RelyingPartyRegistrationTests { |
|
|
|
|
|
|
|
|
|
|
|
// Test with the alt credentials first
|
|
|
|
// Test with the alt credentials first
|
|
|
|
RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials() |
|
|
|
RelyingPartyRegistration relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials() |
|
|
|
.assertingPartyDetails((assertingParty) -> assertingParty.verificationX509Credentials((c) -> { |
|
|
|
.assertingPartyMetadata((assertingParty) -> assertingParty.verificationX509Credentials((c) -> { |
|
|
|
c.add(altApCredential); |
|
|
|
c.add(altApCredential); |
|
|
|
c.add(verifyingCredential); |
|
|
|
c.add(verifyingCredential); |
|
|
|
}).encryptionX509Credentials((c) -> { |
|
|
|
}).encryptionX509Credentials((c) -> { |
|
|
|
@ -139,14 +138,14 @@ public class RelyingPartyRegistrationTests { |
|
|
|
signingCredential); |
|
|
|
signingCredential); |
|
|
|
assertThat(relyingPartyRegistration.getDecryptionX509Credentials()).containsExactly(altRpCredential, |
|
|
|
assertThat(relyingPartyRegistration.getDecryptionX509Credentials()).containsExactly(altRpCredential, |
|
|
|
decryptionCredential); |
|
|
|
decryptionCredential); |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyDetails().getVerificationX509Credentials()) |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyMetadata().getVerificationX509Credentials()) |
|
|
|
.containsExactly(altApCredential, verifyingCredential); |
|
|
|
.containsExactly(altApCredential, verifyingCredential); |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyDetails().getEncryptionX509Credentials()) |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyMetadata().getEncryptionX509Credentials()) |
|
|
|
.containsExactly(altApCredential, encryptingCredential); |
|
|
|
.containsExactly(altApCredential, encryptingCredential); |
|
|
|
|
|
|
|
|
|
|
|
// Test with the alt credentials last
|
|
|
|
// Test with the alt credentials last
|
|
|
|
relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials() |
|
|
|
relyingPartyRegistration = TestRelyingPartyRegistrations.noCredentials() |
|
|
|
.assertingPartyDetails((assertingParty) -> assertingParty.verificationX509Credentials((c) -> { |
|
|
|
.assertingPartyMetadata((assertingParty) -> assertingParty.verificationX509Credentials((c) -> { |
|
|
|
c.add(verifyingCredential); |
|
|
|
c.add(verifyingCredential); |
|
|
|
c.add(altApCredential); |
|
|
|
c.add(altApCredential); |
|
|
|
}).encryptionX509Credentials((c) -> { |
|
|
|
}).encryptionX509Credentials((c) -> { |
|
|
|
@ -166,9 +165,9 @@ public class RelyingPartyRegistrationTests { |
|
|
|
altRpCredential); |
|
|
|
altRpCredential); |
|
|
|
assertThat(relyingPartyRegistration.getDecryptionX509Credentials()).containsExactly(decryptionCredential, |
|
|
|
assertThat(relyingPartyRegistration.getDecryptionX509Credentials()).containsExactly(decryptionCredential, |
|
|
|
altRpCredential); |
|
|
|
altRpCredential); |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyDetails().getVerificationX509Credentials()) |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyMetadata().getVerificationX509Credentials()) |
|
|
|
.containsExactly(verifyingCredential, altApCredential); |
|
|
|
.containsExactly(verifyingCredential, altApCredential); |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyDetails().getEncryptionX509Credentials()) |
|
|
|
assertThat(relyingPartyRegistration.getAssertingPartyMetadata().getEncryptionX509Credentials()) |
|
|
|
.containsExactly(encryptingCredential, altApCredential); |
|
|
|
.containsExactly(encryptingCredential, altApCredential); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -203,10 +202,12 @@ public class RelyingPartyRegistrationTests { |
|
|
|
AssertingPartyMetadata metadata = new CustomAssertingPartyMetadata(); |
|
|
|
AssertingPartyMetadata metadata = new CustomAssertingPartyMetadata(); |
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
.isThrownBy(() -> RelyingPartyRegistration.withAssertingPartyMetadata(metadata) |
|
|
|
.isThrownBy(() -> RelyingPartyRegistration.withAssertingPartyMetadata(metadata) |
|
|
|
.assertingPartyDetails((a) -> a.entityId("entity-id")) |
|
|
|
.assertingPartyMetadata((a) -> a.entityId("entity-id")) |
|
|
|
.build()); |
|
|
|
.build()); |
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy( |
|
|
|
assertThatExceptionOfType(IllegalArgumentException.class) |
|
|
|
() -> RelyingPartyRegistration.withAssertingPartyMetadata(metadata).build().getAssertingPartyDetails()); |
|
|
|
.isThrownBy(() -> RelyingPartyRegistration.withAssertingPartyMetadata(metadata) |
|
|
|
|
|
|
|
.build() |
|
|
|
|
|
|
|
.getAssertingPartyMetadata()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -218,9 +219,9 @@ public class RelyingPartyRegistrationTests { |
|
|
|
.assertingPartyMetadata((a) -> a.signingAlgorithms((algs) -> algs.add("alg"))) |
|
|
|
.assertingPartyMetadata((a) -> a.signingAlgorithms((algs) -> algs.add("alg"))) |
|
|
|
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT) |
|
|
|
.assertionConsumerServiceBinding(Saml2MessageBinding.REDIRECT) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
AssertingPartyDetails details = registration.getAssertingPartyDetails(); |
|
|
|
AssertingPartyMetadata details = registration.getAssertingPartyMetadata(); |
|
|
|
RelyingPartyRegistration copied = RelyingPartyRegistration.withAssertingPartyDetails(details) |
|
|
|
RelyingPartyRegistration copied = RelyingPartyRegistration.withAssertingPartyMetadata(details) |
|
|
|
.assertingPartyDetails((a) -> a.entityId(details.getEntityId())) |
|
|
|
.assertingPartyMetadata((a) -> a.entityId(details.getEntityId())) |
|
|
|
.registrationId(registration.getRegistrationId()) |
|
|
|
.registrationId(registration.getRegistrationId()) |
|
|
|
.entityId(registration.getEntityId()) |
|
|
|
.entityId(registration.getEntityId()) |
|
|
|
.signingX509Credentials((c) -> c.addAll(registration.getSigningX509Credentials())) |
|
|
|
.signingX509Credentials((c) -> c.addAll(registration.getSigningX509Credentials())) |
|
|
|
|