org.opensaml.saml2.metadata.provider
Class AbstractMetadataProvider

java.lang.Object
  extended by org.opensaml.saml2.metadata.provider.BaseMetadataProvider
      extended by org.opensaml.saml2.metadata.provider.AbstractMetadataProvider
All Implemented Interfaces:
MetadataProvider
Direct Known Subclasses:
AbstractObservableMetadataProvider

public abstract class AbstractMetadataProvider
extends BaseMetadataProvider

An abstract, base, implementation of a metadata provider.


Field Summary
private  boolean failFastInitialization
          Whether problems during initialization should cause the provider to fail or go on without metadata.
private  Map<String,EntityDescriptor> indexedDescriptors
          Cache of entity IDs to their descriptors.
private  boolean initialized
          Whether the metadata provider has been initialized.
private  org.slf4j.Logger log
          Class logger.
private  ParserPool parser
          Pool of parsers used to process XML.
 
Fields inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider
unmarshallerFactory
 
Constructor Summary
AbstractMetadataProvider()
          Constructor.
 
Method Summary
protected  void clearDescriptorIndex()
          Clears the entity ID to entity descriptor index.
 void destroy()
          Destroys the metadata provider and frees any resources current held by it.
protected  EntitiesDescriptor doGetEntitiesDescriptor(String name)
          Gets the named EntitiesDescriptor from the metadata.
protected  EntityDescriptor doGetEntityDescriptor(String entityID)
          Gets the identified EntityDescriptor from the metadata.
protected abstract  XMLObject doGetMetadata()
          Gets the metadata currently held by the provider.
protected  List<RoleDescriptor> doGetRole(String entityID, QName roleName)
          Gets the identified roles from an EntityDescriptor.
protected  RoleDescriptor doGetRole(String entityID, QName roleName, String supportedProtocol)
          Gets the role which supports the given protocol.
protected  void doInitialization()
          Subclasses should override this method to perform any initialization logic necessary.
protected  void filterMetadata(XMLObject metadata)
          Filters the given metadata.
 EntitiesDescriptor getEntitiesDescriptor(String name)
          Gets a valid named EntitiesDescriptor from the metadata.
protected  EntitiesDescriptor getEntitiesDescriptorByName(String name, EntitiesDescriptor rootDescriptor)
          Gets the entities descriptor with the given name.
 EntityDescriptor getEntityDescriptor(String entityID)
          Gets the valid metadata for a given entity.
protected  EntityDescriptor getEntityDescriptorById(String entityID, EntitiesDescriptor descriptor)
          Gets the entity descriptor with the given ID that is a descendant of the given entities descriptor.
protected  EntityDescriptor getEntityDescriptorById(String entityID, XMLObject metadata)
          Gets the EntityDescriptor with the given ID from the cached metadata.
 XMLObject getMetadata()
          Gets the valid metadata tree, after the registered filter has been applied.
 ParserPool getParserPool()
          Gets the pool of parsers to use to parse XML.
 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 initialize()
          Initializes this metadata provider.
 boolean isFailFastInitialization()
          Gets whether problems during initialization should cause the provider to fail or go on without metadata.
 boolean isInitialized()
          Gets whether this provider is initialized.
protected  boolean isValid(XMLObject descriptor)
          Returns whether the given descriptor is valid.
protected  void releaseMetadataDOM(XMLObject metadata)
          Releases the DOM representation from the metadata object.
 void setFailFastInitialization(boolean failFast)
          Sets whether problems during initialization should cause the provider to fail or go on without metadata.
protected  void setInitialized(boolean isInitialized)
          Sets whether this provider is initialized.
 void setParserPool(ParserPool pool)
          Sets the pool of parsers to use to parse XML.
protected  XMLObject unmarshallMetadata(InputStream metadataInput)
          Unmarshalls the metadata from the given stream.
 
Methods inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider
getMetadataFilter, requireValidMetadata, setMetadataFilter, setRequireValidMetadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private final org.slf4j.Logger log
Class logger.


initialized

private boolean initialized
Whether the metadata provider has been initialized.


failFastInitialization

private boolean failFastInitialization
Whether problems during initialization should cause the provider to fail or go on without metadata. The assumption being that in most cases a provider will recover at some point in the future. Default: true.


indexedDescriptors

private Map<String,EntityDescriptor> indexedDescriptors
Cache of entity IDs to their descriptors.


parser

private ParserPool parser
Pool of parsers used to process XML.

Constructor Detail

AbstractMetadataProvider

public AbstractMetadataProvider()
Constructor.

Method Detail

getMetadata

public XMLObject getMetadata()
                      throws MetadataProviderException
Gets the valid metadata tree, after the registered filter has been applied.

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

doGetMetadata

protected abstract XMLObject doGetMetadata()
                                    throws MetadataProviderException
Gets the metadata currently held by the provider. This method should not check if the provider is initialized, if the metadata is valid, etc. All of this is done by the invoker of this method.

Returns:
the metadata currently held by this provider or null if no metadata is available
Throws:
MetadataProviderException - thrown if there is a problem retrieving the metadata

getEntitiesDescriptor

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

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

doGetEntitiesDescriptor

protected EntitiesDescriptor doGetEntitiesDescriptor(String name)
                                              throws MetadataProviderException
Gets the named EntitiesDescriptor from the metadata. This method should not check if the provider is initialized, if arguments are null, if metadata is valid, etc. All of this is done by the invoker of this method.

Parameters:
name - the name of the EntitiesDescriptor, never null
Returns:
the named EntitiesDescriptor or null if no such EntitiesDescriptor exists
Throws:
MetadataProviderException - thrown if there is a problem searching for the EntitiesDescriptor

getEntityDescriptor

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

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

doGetEntityDescriptor

protected EntityDescriptor doGetEntityDescriptor(String entityID)
                                          throws MetadataProviderException
Gets the identified EntityDescriptor from the metadata. This method should not check if the provider is initialized, if arguments are null, if the metadata is valid, etc. All of this is done by the invoker of this method.

Parameters:
entityID - ID of the EntityDescriptor, never null
Returns:
the identified EntityDescriptor or null if no such EntityDescriptor exists
Throws:
MetadataProviderException - thrown if there is a problem searching for the EntityDescriptor

getRole

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

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

doGetRole

protected List<RoleDescriptor> doGetRole(String entityID,
                                         QName roleName)
                                  throws MetadataProviderException
Gets the identified roles from an EntityDescriptor. This method should not check if the provider is initialized, if arguments are null, if the roles are valid, etc. All of this is done by the invoker of this method.

Parameters:
entityID - ID of the entity from which to retrieve the roles, never null
roleName - name of the roles to search for, never null
Returns:
the modifiable list of identified roles or an empty list if no roles exists
Throws:
MetadataProviderException - thrown if there is a problem searching for the 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.

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

doGetRole

protected RoleDescriptor doGetRole(String entityID,
                                   QName roleName,
                                   String supportedProtocol)
                            throws MetadataProviderException
Gets the role which supports the given protocol.

Parameters:
entityID - ID of the entity from which to retrieve roles, never null
roleName - name of the role to search for, never null
supportedProtocol - protocol to search for, never null
Returns:
the role supporting the protocol or null if no such role exists
Throws:
MetadataProviderException - thrown if there is a problem search for the roles

isInitialized

public boolean isInitialized()
Gets whether this provider is initialized.

Returns:
whether this provider is initialized

setInitialized

protected void setInitialized(boolean isInitialized)
Sets whether this provider is initialized.

Parameters:
isInitialized - whether this provider is initialized

isFailFastInitialization

public boolean isFailFastInitialization()
Gets whether problems during initialization should cause the provider to fail or go on without metadata. The assumption being that in most cases a provider will recover at some point in the future.

Returns:
whether problems during initialization should cause the provider to fail

setFailFastInitialization

public void setFailFastInitialization(boolean failFast)
Sets whether problems during initialization should cause the provider to fail or go on without metadata. The assumption being that in most cases a provider will recover at some point in the future.

Parameters:
failFast - whether problems during initialization should cause the provider to fail

getParserPool

public ParserPool getParserPool()
Gets the pool of parsers to use to parse XML.

Returns:
pool of parsers to use to parse XML

setParserPool

public void setParserPool(ParserPool pool)
Sets the pool of parsers to use to parse XML.

Parameters:
pool - pool of parsers to use to parse XML

initialize

public void initialize()
                throws MetadataProviderException
Initializes this metadata provider. If called after the metadata provider has already been initialized this method simply returns.

Throws:
MetadataProviderException - thrown if there is a problem initializing the problem and fail fast Initialization is enabled

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

doInitialization

protected void doInitialization()
                         throws MetadataProviderException
Subclasses should override this method to perform any initialization logic necessary. Default implementation is a no-op.

Throws:
MetadataProviderException - thrown if there is a problem initializing the provider

clearDescriptorIndex

protected void clearDescriptorIndex()
Clears the entity ID to entity descriptor index.


unmarshallMetadata

protected XMLObject unmarshallMetadata(InputStream metadataInput)
                                throws UnmarshallingException
Unmarshalls the metadata from the given stream. The stream is closed by this method and the returned metadata released its DOM representation.

Parameters:
metadataInput - the input reader to the metadata.
Returns:
the unmarshalled metadata
Throws:
UnmarshallingException - thrown if the metadata can no be unmarshalled

filterMetadata

protected void filterMetadata(XMLObject metadata)
                       throws FilterException
Filters the given metadata.

Parameters:
metadata - the metadata to be filtered
Throws:
FilterException - thrown if there is an error filtering the metadata

releaseMetadataDOM

protected void releaseMetadataDOM(XMLObject metadata)
Releases the DOM representation from the metadata object.

Parameters:
metadata - the metadata object

getEntityDescriptorById

protected EntityDescriptor getEntityDescriptorById(String entityID,
                                                   XMLObject metadata)
Gets the EntityDescriptor with the given ID from the cached metadata.

Parameters:
entityID - the ID of the entity to get the descriptor for
metadata - metadata associated with the entity
Returns:
the EntityDescriptor

getEntityDescriptorById

protected EntityDescriptor getEntityDescriptorById(String entityID,
                                                   EntitiesDescriptor descriptor)
Gets the entity descriptor with the given ID that is a descendant of the given entities descriptor.

Parameters:
entityID - the ID of the entity whose descriptor is to be fetched
descriptor - the entities descriptor
Returns:
the entity descriptor

getEntitiesDescriptorByName

protected EntitiesDescriptor getEntitiesDescriptorByName(String name,
                                                         EntitiesDescriptor rootDescriptor)
Gets the entities descriptor with the given name.

Parameters:
name - name of the entities descriptor
rootDescriptor - the root descriptor to search in
Returns:
the EntitiesDescriptor with the given name

isValid

protected boolean isValid(XMLObject descriptor)
Returns whether the given descriptor is valid. If valid metadata is not required this method always returns true.

Parameters:
descriptor - the descriptor to check
Returns:
true if valid metadata is not required or the given descriptor is valid, false otherwise


Copyright © 1999-2013. All Rights Reserved.