Class OpenSamlInitializationService
- java.lang.Object
-
- org.springframework.security.saml2.core.OpenSamlInitializationService
-
public final class OpenSamlInitializationService extends java.lang.Object
An initialization service for initializing OpenSAML. Each Spring Security OpenSAML-based component invokes theinitialize()
method at static initialization time.initialize()
is idempotent and may be safely called in custom classes that need OpenSAML to be initialized in order to function correctly. It's recommended that you call thisinitialize()
method when using Spring Security and OpenSAML instead of OpenSAML'sInitializationService.initialize()
. The primary purpose ofinitialize()
is to prepare OpenSAML'sXMLObjectProviderRegistry
with some reasonable defaults. Any changes that Spring Security makes to the registry happen in this method. To override those defaults, callrequireInitialize(Consumer)
and change the registry:static { OpenSamlInitializationService.requireInitialize((registry) -> { registry.setParserPool(...); registry.getBuilderFactory().registerBuilder(...); }); }
requireInitialize(Consumer)
may only be called once per application. If the application already initialized OpenSAML beforerequireInitialize(Consumer)
was called, then the configuration changes will not be applied and an exception will be thrown. The reason for this is to alert you to the fact that there are likely some initialization ordering problems in your application that would otherwise lead to an unpredictable state. If you must change the registry's configuration in multiple places in your application, you are expected to handle the initialization ordering issues yourself instead of trying to callrequireInitialize(Consumer)
multiple times.- Since:
- 5.4
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
initialize()
Ready OpenSAML for use and configure it with reasonable defaults.static void
requireInitialize(java.util.function.Consumer<org.opensaml.core.xml.config.XMLObjectProviderRegistry> registryConsumer)
Ready OpenSAML for use, configure it with reasonable defaults, and modify theXMLObjectProviderRegistry
using the providedConsumer
.
-
-
-
Method Detail
-
initialize
public static boolean initialize()
Ready OpenSAML for use and configure it with reasonable defaults. Initialization is guaranteed to happen only once per application. This method will passively returnfalse
if initialization already took place earlier in the application.- Returns:
- whether or not initialization was performed. The first thread to initialize
OpenSAML will return
true
while the rest will returnfalse
. - Throws:
Saml2Exception
- if OpenSAML failed to initialize
-
requireInitialize
public static void requireInitialize(java.util.function.Consumer<org.opensaml.core.xml.config.XMLObjectProviderRegistry> registryConsumer)
Ready OpenSAML for use, configure it with reasonable defaults, and modify theXMLObjectProviderRegistry
using the providedConsumer
. Initialization is guaranteed to happen only once per application. This method will throw an exception if initialization already took place earlier in the application.- Parameters:
registryConsumer
- theConsumer
to further configure theXMLObjectProviderRegistry
- Throws:
Saml2Exception
- if initialization already happened previously or if OpenSAML failed to initialize
-
-