org.opensaml.saml2.metadata.provider
Class ChainingMetadataProvider

java.lang.Object
  extended by org.opensaml.saml2.metadata.provider.BaseMetadataProvider
      extended by org.opensaml.saml2.metadata.provider.ChainingMetadataProvider
All Implemented Interfaces:
MetadataProvider, ObservableMetadataProvider

public class ChainingMetadataProvider
extends BaseMetadataProvider
implements ObservableMetadataProvider

A metadata provider that uses registered providers, in turn, to answer queries. When searching for entity specific information (entity metadata, roles, etc.) the entity descriptor used is the first non-null descriptor found while iterating over the registered providers in insertion order. This chaining provider implements observation by registering an observer with each contained provider. When the contained provider emits a change this provider will also emit a change to observers registered with it. As such, developers should be careful not to register a the same observer with both container providers and this provider. Doing so will result in an observer being notified twice for each change.


Nested Class Summary
private  class ChainingMetadataProvider.ChainingEntitiesDescriptor
          Class that wraps the currently list of providers and exposes it as an EntitiesDescriptors.
private  class ChainingMetadataProvider.ContainedProviderObserver
          Observer that clears the descriptor index of this provider.
 
Nested classes/interfaces inherited from interface org.opensaml.saml2.metadata.provider.ObservableMetadataProvider
ObservableMetadataProvider.Observer
 
Field Summary
private  org.slf4j.Logger log
          Class logger.
private  List<ObservableMetadataProvider.Observer> observers
          List of registered observers.
private  ReadWriteLock providerLock
          Lock used to block reads during write and vice versa.
private  List<MetadataProvider> providers
          Registered providers.
 
Fields inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider
unmarshallerFactory
 
Constructor Summary
ChainingMetadataProvider()
          Constructor.
 
Method Summary
 void addMetadataProvider(MetadataProvider newProvider)
          Adds a metadata provider to the list of registered providers.
 void destroy()
          Destroys the metadata provider and frees any resources current held by it.
protected  void doAddMetadataProvider(MetadataProvider provider, List<MetadataProvider> providerList)
          Adds a metadata provider to the given collection.
protected  void emitChangeEvent()
          Convenience method for calling ObservableMetadataProvider.Observer.onEvent(MetadataProvider) on every registered Observer passing in this provider.
 EntitiesDescriptor getEntitiesDescriptor(String name)
          Gets a valid named EntitiesDescriptor from the metadata.
 EntityDescriptor getEntityDescriptor(String entityID)
          Gets the valid metadata for a given entity.
 XMLObject getMetadata()
          Gets the metadata from every registered provider and places each within a newly created EntitiesDescriptor.
 MetadataFilter getMetadataFilter()
          Gets the metadata filter applied to the metadata.
 List<ObservableMetadataProvider.Observer> getObservers()
          Gets the list of observers for the provider.
 List<MetadataProvider> getProviders()
          Gets an immutable the list of currently registered providers.
 List<RoleDescriptor> getRole(String entityID, QName roleName)
          Gets the valid role descriptors of a given type for a given entity.
 RoleDescriptor getRole(String entityID, QName roleName, String supportedProtocol)
          Gets the valid role descriptors of a given type for a given entity that support the given protocol.
 void removeMetadataProvider(MetadataProvider provider)
          Removes a metadata provider from the list of registered providers.
 void setMetadataFilter(MetadataFilter newFilter)
          Sets the metadata filter applied to the metadata.
 void setProviders(List<MetadataProvider> newProviders)
          Replaces the current set of metadata providers with give collection.
 void setRequireValidMetadata(boolean requireValidMetadata)
          Sets whether the metadata returned by queries must be valid.
 
Methods inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider
requireValidMetadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensaml.saml2.metadata.provider.MetadataProvider
requireValidMetadata
 

Field Detail

log

private final org.slf4j.Logger log
Class logger.


observers

private List<ObservableMetadataProvider.Observer> observers
List of registered observers.


providers

private List<MetadataProvider> providers
Registered providers.


providerLock

private ReadWriteLock providerLock
Lock used to block reads during write and vice versa.

Constructor Detail

ChainingMetadataProvider

public ChainingMetadataProvider()
Constructor.

Method Detail

getProviders

public List<MetadataProvider> getProviders()
Gets an immutable the list of currently registered providers.

Returns:
list of currently registered providers

setProviders

public void setProviders(List<MetadataProvider> newProviders)
                  throws MetadataProviderException
Replaces the current set of metadata providers with give collection.

Parameters:
newProviders - the metadata providers to replace the current providers with
Throws:
MetadataProviderException - thrown if there is a problem adding the metadata provider

addMetadataProvider

public void addMetadataProvider(MetadataProvider newProvider)
                         throws MetadataProviderException
Adds a metadata provider to the list of registered providers.

Parameters:
newProvider - the provider to be added
Throws:
MetadataProviderException - thrown if there is a problem adding the metadata provider

doAddMetadataProvider

protected void doAddMetadataProvider(MetadataProvider provider,
                                     List<MetadataProvider> providerList)
Adds a metadata provider to the given collection. The new provider is checked to see if it is null, if not the providers MetadataProvider.requireValidMetadata() property is set to the value of this metadata provider's property. If the given metadata provider is an instance of ObservableMetadataProvider then a ContainedProviderObserver is added to it as well.

Parameters:
provider - provider to be added to the collection
providerList - collection to which the provider is added

removeMetadataProvider

public void removeMetadataProvider(MetadataProvider provider)
Removes a metadata provider from the list of registered providers.

Parameters:
provider - provider to be removed

setRequireValidMetadata

public void setRequireValidMetadata(boolean requireValidMetadata)
Sets whether the metadata returned by queries must be valid.

Specified by:
setRequireValidMetadata in interface MetadataProvider
Overrides:
setRequireValidMetadata in class BaseMetadataProvider
Parameters:
requireValidMetadata - whether the metadata returned by queries must be valid

getMetadataFilter

public MetadataFilter getMetadataFilter()
Gets the metadata filter applied to the metadata.

Specified by:
getMetadataFilter in interface MetadataProvider
Overrides:
getMetadataFilter in class BaseMetadataProvider
Returns:
the metadata filter applied to the metadata

setMetadataFilter

public void setMetadataFilter(MetadataFilter newFilter)
                       throws MetadataProviderException
Sets the metadata filter applied to the metadata.

Specified by:
setMetadataFilter in interface MetadataProvider
Overrides:
setMetadataFilter in class BaseMetadataProvider
Parameters:
newFilter - the metadata filter applied to the metadata
Throws:
MetadataProviderException - thrown if the provider can not apply the filter to the metadata

getMetadata

public XMLObject getMetadata()
                      throws MetadataProviderException
Gets the metadata from every registered provider and places each within a newly created EntitiesDescriptor. Gets the valid metadata tree, after the registered filter has been applied.

Specified by:
getMetadata in interface MetadataProvider
Returns:
the entire metadata tree
Throws:
MetadataProviderException - thrown if the provider can not fetch the metadata, must not be thrown simply if there is no metadata to fetch

getEntitiesDescriptor

public EntitiesDescriptor getEntitiesDescriptor(String name)
                                         throws MetadataProviderException
Gets a valid named EntitiesDescriptor from the metadata.

Specified by:
getEntitiesDescriptor in interface MetadataProvider
Parameters:
name - the name of the EntitiesDescriptor
Returns:
the EntitiesDescriptor or null
Throws:
MetadataProviderException - thrown if the provider can not fetch the metadata, must not be thrown if there is simply no EntitiesDescriptor with the given name

getEntityDescriptor

public EntityDescriptor getEntityDescriptor(String entityID)
                                     throws MetadataProviderException
Gets the valid metadata for a given entity.

Specified by:
getEntityDescriptor in interface MetadataProvider
Parameters:
entityID - the ID of the entity
Returns:
the entity's metadata or null if there is no metadata or no valid metadata
Throws:
MetadataProviderException - thrown if the provider can not fetch the metadata, must not be thrown if there is simply no EntityDescriptor with the given ID

getRole

public List<RoleDescriptor> getRole(String entityID,
                                    QName roleName)
                             throws MetadataProviderException
Gets the valid role descriptors of a given type for a given entity.

Specified by:
getRole in interface MetadataProvider
Parameters:
entityID - the ID of the entity
roleName - the role type
Returns:
the modifiable list of role descriptors
Throws:
MetadataProviderException - thrown if the provider can not fetch the metadata, must not be thrown if there is simply no such entity with the given roles

getRole

public RoleDescriptor getRole(String entityID,
                              QName roleName,
                              String supportedProtocol)
                       throws MetadataProviderException
Gets the valid role descriptors of a given type for a given entity that support the given protocol.

Specified by:
getRole in interface MetadataProvider
Parameters:
entityID - the ID of the entity
roleName - the role type
supportedProtocol - the protocol supported by the role
Returns:
the role descriptor
Throws:
MetadataProviderException - thrown if the provider can not fetch the metadata, must not be thrown if there is simply no such entity with the given role supporting the given protocol

getObservers

public List<ObservableMetadataProvider.Observer> getObservers()
Gets the list of observers for the provider. New observers may be added to the list or old ones removed.

Specified by:
getObservers in interface ObservableMetadataProvider
Returns:
the list of observers

destroy

public void destroy()
Destroys the metadata provider and frees any resources current held by it. Default method is a no-op.

Overrides:
destroy in class BaseMetadataProvider

emitChangeEvent

protected void emitChangeEvent()
Convenience method for calling ObservableMetadataProvider.Observer.onEvent(MetadataProvider) on every registered Observer passing in this provider.



Copyright © 1999-2013. All Rights Reserved.