Class SAMLMetadataLookupHandler

  • All Implemented Interfaces:
    net.shibboleth.utilities.java.support.component.Component, net.shibboleth.utilities.java.support.component.DestructableComponent, net.shibboleth.utilities.java.support.component.InitializableComponent, org.opensaml.messaging.handler.MessageHandler

    public class SAMLMetadataLookupHandler
    extends org.opensaml.messaging.handler.AbstractMessageHandler
    Handler for inbound SAML protocol messages that attempts to locate SAML metadata for a SAML entity, and attaches it as a SAMLMetadataContext child of a pre-existing concrete instance of AbstractSAMLEntityContext.

    The entity context class is configurable and defaults to SAMLPeerEntityContext. The handler will no-op in the absence of an existing AbstractSAMLEntityContext child of the message context with non-null values for both entityID and role.

    If the optional copy strategy is configured via setCopyContextStrategy(Function), and if that lookup finds an existing metadata context with compatible data (matching entityID and role), then its data will be re-used.

    Otherwise an attempt to resolve metadata will be performed with the configured RoleDescriptorResolver. A protocol from a SAMLProtocolContext will be added to the lookup, if available.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Function<org.opensaml.messaging.context.MessageContext,​org.opensaml.saml.common.messaging.context.SAMLMetadataContext> copyContextStrategy
      Optional strategy for resolving an existing metadata context from which to copy data.
      private Class<? extends org.opensaml.saml.common.messaging.context.AbstractSAMLEntityContext> entityContextClass
      The context class representing the SAML entity whose data is to be resolved.
      private Logger log
      Logger.
      private org.opensaml.saml.metadata.resolver.RoleDescriptorResolver metadataResolver
      Resolver used to look up SAML metadata.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doInitialize()
      protected void doInvoke​(org.opensaml.messaging.context.MessageContext messageContext)
      protected org.opensaml.saml.common.messaging.context.SAMLMetadataContext resolveExisting​(org.opensaml.messaging.context.MessageContext messageContext, String entityID, QName role)
      Attempt to resolve an existing SAMLMetadataContext from which to copy.
      void setCopyContextStrategy​(Function<org.opensaml.messaging.context.MessageContext,​org.opensaml.saml.common.messaging.context.SAMLMetadataContext> strategy)
      Set the optional strategy for resolving an existing metadata context from which to copy data.
      void setEntityContextClass​(Class<? extends org.opensaml.saml.common.messaging.context.AbstractSAMLEntityContext> clazz)
      Set the class type holding the SAML entity data.
      void setRoleDescriptorResolver​(org.opensaml.saml.metadata.resolver.RoleDescriptorResolver resolver)
      Set the RoleDescriptorResolver to use.
      • Methods inherited from class org.opensaml.messaging.handler.AbstractMessageHandler

        doPostInvoke, doPostInvoke, doPreInvoke, getActivationCondition, getLogPrefix, invoke, setActivationCondition
      • Methods inherited from class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent

        destroy, doDestroy, initialize, isDestroyed, isInitialized
      • Methods inherited from interface net.shibboleth.utilities.java.support.component.InitializableComponent

        initialize, isInitialized
    • Field Detail

      • log

        @Nonnull
        private final Logger log
        Logger.
      • metadataResolver

        @NonnullAfterInit
        private org.opensaml.saml.metadata.resolver.RoleDescriptorResolver metadataResolver
        Resolver used to look up SAML metadata.
      • entityContextClass

        @Nonnull
        private Class<? extends org.opensaml.saml.common.messaging.context.AbstractSAMLEntityContext> entityContextClass
        The context class representing the SAML entity whose data is to be resolved. Defaults to: SAMLPeerEntityContext.
      • copyContextStrategy

        @Nullable
        private Function<org.opensaml.messaging.context.MessageContext,​org.opensaml.saml.common.messaging.context.SAMLMetadataContext> copyContextStrategy
        Optional strategy for resolving an existing metadata context from which to copy data.
    • Constructor Detail

      • SAMLMetadataLookupHandler

        public SAMLMetadataLookupHandler()
    • Method Detail

      • setCopyContextStrategy

        public void setCopyContextStrategy​(@Nullable
                                           Function<org.opensaml.messaging.context.MessageContext,​org.opensaml.saml.common.messaging.context.SAMLMetadataContext> strategy)
        Set the optional strategy for resolving an existing metadata context from which to copy data.
        Parameters:
        strategy - the strategy function
      • setEntityContextClass

        public void setEntityContextClass​(@Nonnull
                                          Class<? extends org.opensaml.saml.common.messaging.context.AbstractSAMLEntityContext> clazz)
        Set the class type holding the SAML entity data.

        Defaults to: SAMLPeerEntityContext.

        Parameters:
        clazz - the entity context class type
      • setRoleDescriptorResolver

        public void setRoleDescriptorResolver​(@Nonnull
                                              org.opensaml.saml.metadata.resolver.RoleDescriptorResolver resolver)
        Set the RoleDescriptorResolver to use.
        Parameters:
        resolver - the resolver to use
      • doInitialize

        protected void doInitialize()
                             throws net.shibboleth.utilities.java.support.component.ComponentInitializationException
        Overrides:
        doInitialize in class net.shibboleth.utilities.java.support.component.AbstractInitializableComponent
        Throws:
        net.shibboleth.utilities.java.support.component.ComponentInitializationException
      • doInvoke

        protected void doInvoke​(@Nonnull
                                org.opensaml.messaging.context.MessageContext messageContext)
                         throws org.opensaml.messaging.handler.MessageHandlerException
        Specified by:
        doInvoke in class org.opensaml.messaging.handler.AbstractMessageHandler
        Throws:
        org.opensaml.messaging.handler.MessageHandlerException
      • resolveExisting

        @Nullable
        protected org.opensaml.saml.common.messaging.context.SAMLMetadataContext resolveExisting​(@Nonnull
                                                                                                 org.opensaml.messaging.context.MessageContext messageContext,
                                                                                                 @Nonnull
                                                                                                 String entityID,
                                                                                                 @Nonnull
                                                                                                 QName role)
        Attempt to resolve an existing SAMLMetadataContext from which to copy.

        The returned context will always be a fresh parent-less instance, suitable for the caller to directly store in the current message context.

        Parameters:
        messageContext - the current message context
        entityID - the entityID against which to match
        role - the entity role against which to match
        Returns:
        a new instance of SAMLMetadataContext, or null if one can not be resolved