Package org.opensaml.saml.common.binding.impl

# Class SAMLMetadataLookupHandler

java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
org.opensaml.messaging.handler.AbstractMessageHandler
org.opensaml.saml.common.binding.impl.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 Summary

Fields
Modifier and Type
Field
Description
`private Function<MessageContext,SAMLMetadataContext>`
`copyContextStrategy`
Optional strategy for resolving an existing metadata context from which to copy data.
`private Class<? extends AbstractSAMLEntityContext>`
`entityContextClass`
The context class representing the SAML entity whose data is to be resolved.
`private final org.slf4j.Logger`
`log`
Logger.
`private Function<MessageContext,RoleDescriptorResolver>`
`metadataResolverLookupStrategy`
Resolver used to look up SAML metadata.
`private Function<MessageContext,ProfileRequestContext>`
`profileRequestContextLookupStrategy`
Optional but defaulted strategy for locating a PRC.

## Constructor Summary

Constructors
Constructor
Description
`SAMLMetadataLookupHandler()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected CriteriaSet`
`buildLookupCriteria(MessageContext messageContext, String entityID, QName role)`
Build the lookup criteria from the message context data.
`protected void`
`doInvoke(MessageContext messageContext)`
Performs the handler logic.
`protected SAMLMetadataContext`
`resolveExisting(MessageContext messageContext, String entityID, QName role)`
Attempt to resolve an existing `SAMLMetadataContext` from which to copy.
`void`
`setCopyContextStrategy(Function<MessageContext,SAMLMetadataContext> strategy)`
Set the optional strategy for resolving an existing metadata context from which to copy data.
`void`
`setEntityContextClass(Class<? extends AbstractSAMLEntityContext> clazz)`
Set the class type holding the SAML entity data.
`void`
`setProfileRequestContextLookupStrategy(Function<MessageContext,ProfileRequestContext> strategy)`
Set optional lookup strategy for locating `ProfileRequestContext`.
`void`
`setRoleDescriptorResolver(RoleDescriptorResolver resolver)`
Set the `RoleDescriptorResolver` to use.
`void`
`setRoleDescriptorResolverLookupStrategy(Function<MessageContext,RoleDescriptorResolver> strategy)`
Set the lookup strategy for the `RoleDescriptorResolver` to use.

### Methods inherited from class org.opensaml.messaging.handler.AbstractMessageHandler

`doPostInvoke, doPostInvoke, doPreInvoke, getActivationCondition, getLogPrefix, invoke, isPreInvokeCalled, setActivationCondition`

### Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent

`checkComponentActive, checkSetterPreconditions, destroy, doDestroy, doInitialize, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface net.shibboleth.shared.component.InitializableComponent

`initialize, isInitialized`

## Field Details

### log

@Nonnull private final org.slf4j.Logger log
Logger.

### metadataResolverLookupStrategy

@Nonnull private Function<MessageContext,RoleDescriptorResolver> metadataResolverLookupStrategy
Resolver used to look up SAML metadata.

### entityContextClass

@Nonnull private Class<? extends AbstractSAMLEntityContext> entityContextClass
The context class representing the SAML entity whose data is to be resolved. Defaults to: `SAMLPeerEntityContext`.

### copyContextStrategy

@Nullable private Function<MessageContext,SAMLMetadataContext> copyContextStrategy
Optional strategy for resolving an existing metadata context from which to copy data.

### profileRequestContextLookupStrategy

@Nullable private Function<MessageContext,ProfileRequestContext> profileRequestContextLookupStrategy
Optional but defaulted strategy for locating a PRC.

## 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