From 3fbbf6118d487b1a1c4f595a4d3a697758cc6c2b Mon Sep 17 00:00:00 2001 From: opensource Date: Sun, 10 Nov 2024 22:24:58 +0900 Subject: [PATCH] Initialize OpenSAML in OpenSamlAssertingPartyMetadataRepository Closes gh-16042 This commit adds a static initializer block to both OpenSaml4AssertingPartyMetadataRepository and OpenSaml5AssertingPartyMetadataRepository. This ensures OpenSAML is initialized upon class loading, preventing failures when methods like withMetadataLocation are invoked without prior initialization. --- .../OpenSaml4AssertingPartyMetadataRepository.java | 5 +++++ .../OpenSaml4AssertingPartyMetadataRepositoryTests.java | 5 ----- .../OpenSaml5AssertingPartyMetadataRepository.java | 5 +++++ .../OpenSaml5AssertingPartyMetadataRepositoryTests.java | 5 ----- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepository.java b/saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepository.java index 56145326280..3485f9964c1 100644 --- a/saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepository.java +++ b/saml2/saml2-service-provider/src/opensaml4Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepository.java @@ -50,6 +50,7 @@ import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.security.saml2.Saml2Exception; +import org.springframework.security.saml2.core.OpenSamlInitializationService; import org.springframework.security.saml2.provider.service.registration.BaseOpenSamlAssertingPartyMetadataRepository.MetadataResolverAdapter; import org.springframework.util.Assert; @@ -68,6 +69,10 @@ */ public final class OpenSaml4AssertingPartyMetadataRepository implements AssertingPartyMetadataRepository { + static { + OpenSamlInitializationService.initialize(); + } + private final BaseOpenSamlAssertingPartyMetadataRepository delegate; /** diff --git a/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepositoryTests.java b/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepositoryTests.java index 7134cd7291f..96c9f0c1780 100644 --- a/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepositoryTests.java +++ b/saml2/saml2-service-provider/src/opensaml4Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml4AssertingPartyMetadataRepositoryTests.java @@ -53,7 +53,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ResourceLoader; import org.springframework.security.saml2.Saml2Exception; -import org.springframework.security.saml2.core.OpenSamlInitializationService; import org.springframework.security.saml2.core.TestSaml2X509Credentials; import org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects; @@ -71,10 +70,6 @@ */ public class OpenSaml4AssertingPartyMetadataRepositoryTests { - static { - OpenSamlInitializationService.initialize(); - } - private static MetadataDispatcher dispatcher = new MetadataDispatcher() .addResponse("/entity.xml", readFile("test-metadata.xml")) .addResponse("/entities.xml", readFile("test-entitiesdescriptor.xml")); diff --git a/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepository.java b/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepository.java index 381bb599b90..31eda772d06 100644 --- a/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepository.java +++ b/saml2/saml2-service-provider/src/opensaml5Main/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepository.java @@ -50,6 +50,7 @@ import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.security.saml2.Saml2Exception; +import org.springframework.security.saml2.core.OpenSamlInitializationService; import org.springframework.security.saml2.provider.service.registration.BaseOpenSamlAssertingPartyMetadataRepository.MetadataResolverAdapter; import org.springframework.util.Assert; @@ -68,6 +69,10 @@ */ public final class OpenSaml5AssertingPartyMetadataRepository implements AssertingPartyMetadataRepository { + static { + OpenSamlInitializationService.initialize(); + } + private final BaseOpenSamlAssertingPartyMetadataRepository delegate; /** diff --git a/saml2/saml2-service-provider/src/opensaml5Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepositoryTests.java b/saml2/saml2-service-provider/src/opensaml5Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepositoryTests.java index 586e9b1f643..6f1bf1b5663 100644 --- a/saml2/saml2-service-provider/src/opensaml5Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepositoryTests.java +++ b/saml2/saml2-service-provider/src/opensaml5Test/java/org/springframework/security/saml2/provider/service/registration/OpenSaml5AssertingPartyMetadataRepositoryTests.java @@ -53,7 +53,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ResourceLoader; import org.springframework.security.saml2.Saml2Exception; -import org.springframework.security.saml2.core.OpenSamlInitializationService; import org.springframework.security.saml2.core.TestSaml2X509Credentials; import org.springframework.security.saml2.provider.service.authentication.TestOpenSamlObjects; @@ -71,10 +70,6 @@ */ public class OpenSaml5AssertingPartyMetadataRepositoryTests { - static { - OpenSamlInitializationService.initialize(); - } - private static MetadataDispatcher dispatcher = new MetadataDispatcher() .addResponse("/entity.xml", readFile("test-metadata.xml")) .addResponse("/entities.xml", readFile("test-entitiesdescriptor.xml"));