Class OpenSamlInitializationService
java.lang.Object
org.springframework.security.saml2.core.OpenSamlInitializationService
An initialization service for initializing OpenSAML. Each Spring Security
OpenSAML-based component invokes the
initialize()
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 this initialize()
method when using Spring Security and OpenSAML
instead of OpenSAML's InitializationService.initialize()
.
The primary purpose of initialize()
is to prepare OpenSAML's
XMLObjectProviderRegistry
with some reasonable defaults. Any changes that
Spring Security makes to the registry happen in this method.
To override those defaults, call requireInitialize(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 before
requireInitialize(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 call requireInitialize(Consumer)
multiple times.- Since:
- 5.4
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
Ready OpenSAML for use and configure it with reasonable defaults.static void
requireInitialize
(Consumer<org.opensaml.core.xml.config.XMLObjectProviderRegistry> registryConsumer) Ready OpenSAML for use, configure it with reasonable defaults, and modify theXMLObjectProviderRegistry
using the providedConsumer
.
-
Method Details
-
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(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
-