public class OpenSamlInitializationService
extends java.lang.Object
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.Constructor and Description |
---|
OpenSamlInitializationService() |
Modifier and Type | Method and 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 the
XMLObjectProviderRegistry
using the provided Consumer . |
public static boolean initialize()
false
if initialization already took place earlier in the application.true
while the rest will return false
.Saml2Exception
- if OpenSAML failed to initializepublic static void requireInitialize(java.util.function.Consumer<org.opensaml.core.xml.config.XMLObjectProviderRegistry> registryConsumer)
XMLObjectProviderRegistry
using the provided Consumer
.
Initialization is guaranteed to happen only once per application. This method will throw an exception
if initialization already took place earlier in the application.registryConsumer
- the Consumer
to further configure the XMLObjectProviderRegistry
Saml2Exception
- if initialization already happened previously or if OpenSAML failed to initialize