Class SAMLMetadataLookupHandler

All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, MessageHandler

public class SAMLMetadataLookupHandler extends AbstractMessageHandler
Handler 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 Details

  • Constructor Details

    • SAMLMetadataLookupHandler

      public SAMLMetadataLookupHandler()
      Constructor.
  • Method Details

    • setCopyContextStrategy

      public void setCopyContextStrategy(@Nullable Function<MessageContext,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 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 RoleDescriptorResolver resolver)
      Set the RoleDescriptorResolver to use.
      Parameters:
      resolver - the resolver to use
    • setRoleDescriptorResolverLookupStrategy

      public void setRoleDescriptorResolverLookupStrategy(@Nonnull Function<MessageContext,RoleDescriptorResolver> strategy)
      Set the lookup strategy for the RoleDescriptorResolver to use.
      Parameters:
      strategy - lookup strategy
      Since:
      5.2.0
    • setProfileRequestContextLookupStrategy

      public void setProfileRequestContextLookupStrategy(@Nullable Function<MessageContext,ProfileRequestContext> strategy)
      Set optional lookup strategy for locating ProfileRequestContext.

      Defaults to parent lookup. If set and found, a ProfileRequestContextCriterion will be included in the attempt.

      Parameters:
      strategy - the lookup strategy
      Since:
      5.0.0
    • doInvoke

      protected void doInvoke(@Nonnull MessageContext messageContext) throws MessageHandlerException
      Performs the handler logic.
      Specified by:
      doInvoke in class AbstractMessageHandler
      Parameters:
      messageContext - the message context on which to invoke the handler
      Throws:
      MessageHandlerException - if there is an error invoking the handler on the message context
    • buildLookupCriteria

      @Nonnull protected CriteriaSet buildLookupCriteria(@Nonnull MessageContext messageContext, @Nonnull String entityID, @Nonnull QName role)
      Build the lookup criteria from the message context data.
      Parameters:
      messageContext - the current message context
      entityID - entityID to lookup
      role - role to lookup
      Returns:
      the new lookup criteria
    • resolveExisting

      @Nullable protected SAMLMetadataContext resolveExisting(@Nonnull 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