Class OpenSamlInitializationService


  • public final class OpenSamlInitializationService
    extends java.lang.Object
    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

      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 the XMLObjectProviderRegistry using the provided Consumer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 return false 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 return false.
        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 the 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.
        Parameters:
        registryConsumer - the Consumer to further configure the XMLObjectProviderRegistry
        Throws:
        Saml2Exception - if initialization already happened previously or if OpenSAML failed to initialize