Skip to content

Commit

Permalink
Initialize OpenSAML in OpenSamlAssertingPartyMetadataRepository
Browse files Browse the repository at this point in the history
Closes spring-projectsgh-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.
  • Loading branch information
opensource authored and opensource committed Nov 10, 2024
1 parent c61ccd9 commit 3fbbf61
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -68,6 +69,10 @@
*/
public final class OpenSaml4AssertingPartyMetadataRepository implements AssertingPartyMetadataRepository {

static {
OpenSamlInitializationService.initialize();
}

private final BaseOpenSamlAssertingPartyMetadataRepository delegate;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -68,6 +69,10 @@
*/
public final class OpenSaml5AssertingPartyMetadataRepository implements AssertingPartyMetadataRepository {

static {
OpenSamlInitializationService.initialize();
}

private final BaseOpenSamlAssertingPartyMetadataRepository delegate;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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"));
Expand Down

0 comments on commit 3fbbf61

Please # to comment.