org.opensaml.saml2.metadata.provider
Class HTTPMetadataProvider

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

public class HTTPMetadataProvider
extends AbstractReloadingMetadataProvider

A metadata provider that pulls metadata using an HTTP GET. Metadata is cached until one of these criteria is met:

Metadata is filtered prior to determining the cache expiration data. This allows a filter to remove XMLObjects that may effect the cache duration but for which the user of this provider does not care about. It is the responsibility of the caller to re-initialize, via AbstractMetadataProvider.initialize(), if any properties of this provider are changed.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.opensaml.saml2.metadata.provider.ObservableMetadataProvider
ObservableMetadataProvider.Observer
 
Field Summary
private  org.apache.commons.httpclient.auth.AuthScope authScope
          URL scope that requires authentication.
private  String cachedMetadataETag
          The ETag provided when the currently cached metadata was fetched.
private  String cachedMetadataLastModified
          The Last-Modified information provided when the currently cached metadata was fetched.
private  org.apache.commons.httpclient.HttpClient httpClient
          HTTP Client used to pull the metadata.
private  org.slf4j.Logger log
          Class logger.
private  URI metadataURI
          URL to the Metadata.
 
Fields inherited from class org.opensaml.saml2.metadata.provider.BaseMetadataProvider
unmarshallerFactory
 
Constructor Summary
HTTPMetadataProvider(String metadataURL, int requestTimeout)
          Deprecated. 
HTTPMetadataProvider(Timer backgroundTaskTimer, org.apache.commons.httpclient.HttpClient client, String metadataURL)
          Constructor.
 
Method Summary
protected  org.apache.commons.httpclient.methods.GetMethod buildGetMethod()
          Builds the HTTP GET method used to fetch the metadata.
 void destroy()
          Destroys the metadata provider and frees any resources current held by it.
protected  byte[] fetchMetadata()
          Gets the metadata document from the remote server.
 int getMaxCacheDuration()
          Deprecated. use AbstractReloadingMetadataProvider.getMaxRefreshDelay() instead
protected  byte[] getMetadataBytesFromResponse(org.apache.commons.httpclient.methods.GetMethod getMethod)
          Extracts the raw metadata bytes from the response taking in to account possible deflate and GZip compression.
protected  String getMetadataIdentifier()
          Gets an identifier which may be used to distinguish this metadata in logging statements.
 String getMetadataURI()
          Gets the URL to fetch the metadata.
 int getRequestTimeout()
          Gets the length of time in milliseconds to wait for the server to respond.
 boolean maintainExpiredMetadata()
          Deprecated. use BaseMetadataProvider.requireValidMetadata() instead
protected  void processConditionalRetrievalHeaders(org.apache.commons.httpclient.methods.GetMethod getMethod)
          Records the ETag and Last-Modified headers, from the response, if they are present.
 void setBasicCredentials(String username, String password)
          Sets the username and password used to access the metadata URL.
 void setMaintainExpiredMetadata(boolean maintain)
          Deprecated. use BaseMetadataProvider.setRequireValidMetadata(boolean) instead
 void setMaxCacheDuration(int newDuration)
          Deprecated. use AbstractReloadingMetadataProvider.setMaxRefreshDelay(long) instead
 void setSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory newSocketFactory)
          Deprecated. set this information on HTTP client used by provider
 
Methods inherited from class org.opensaml.saml2.metadata.provider.AbstractReloadingMetadataProvider
computeNextRefreshDelay, doGetMetadata, doInitialization, getExpirationTime, getLastRefresh, getLastUpdate, getMaxRefreshDelay, getMinRefreshDelay, getNextRefresh, getRefreshDelayFactor, inputstreamToByteArray, postProcessMetadata, processCachedMetadata, processNewMetadata, processNonExpiredMetadata, processPreExpiredMetadata, refresh, setMaxRefreshDelay, setMinRefreshDelay, setRefreshDelayFactor, unmarshallMetadata
 
Methods inherited from class org.opensaml.saml2.metadata.provider.AbstractObservableMetadataProvider
emitChangeEvent, getObservers
 
Methods inherited from class org.opensaml.saml2.metadata.provider.AbstractMetadataProvider
clearDescriptorIndex, doGetEntitiesDescriptor, doGetEntityDescriptor, doGetRole, doGetRole, filterMetadata, getEntitiesDescriptor, getEntitiesDescriptorByName, getEntityDescriptor, getEntityDescriptorById, getEntityDescriptorById, getMetadata, getParserPool, getRole, getRole, initialize, isFailFastInitialization, isInitialized, isValid, releaseMetadataDOM, setFailFastInitialization, setInitialized, setParserPool, unmarshallMetadata
 
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
 
Methods inherited from interface org.opensaml.saml2.metadata.provider.MetadataProvider
getEntitiesDescriptor, getEntityDescriptor, getMetadata, getMetadataFilter, getRole, getRole, requireValidMetadata, setMetadataFilter, setRequireValidMetadata
 

Field Detail

log

private final org.slf4j.Logger log
Class logger.


httpClient

private org.apache.commons.httpclient.HttpClient httpClient
HTTP Client used to pull the metadata.


metadataURI

private URI metadataURI
URL to the Metadata.


cachedMetadataETag

private String cachedMetadataETag
The ETag provided when the currently cached metadata was fetched.


cachedMetadataLastModified

private String cachedMetadataLastModified
The Last-Modified information provided when the currently cached metadata was fetched.


authScope

private org.apache.commons.httpclient.auth.AuthScope authScope
URL scope that requires authentication.

Constructor Detail

HTTPMetadataProvider

@Deprecated
public HTTPMetadataProvider(String metadataURL,
                                       int requestTimeout)
                     throws MetadataProviderException
Deprecated. 

Constructor.

Parameters:
metadataURL - the URL to fetch the metadata
requestTimeout - the time, in milliseconds, to wait for the metadata server to respond
Throws:
MetadataProviderException - thrown if the URL is not a valid URL or the metadata can not be retrieved from the URL

HTTPMetadataProvider

public HTTPMetadataProvider(Timer backgroundTaskTimer,
                            org.apache.commons.httpclient.HttpClient client,
                            String metadataURL)
                     throws MetadataProviderException
Constructor.

Parameters:
client - HTTP client used to pull in remote metadata
backgroundTaskTimer - timer used to schedule background metadata refresh tasks
metadataURL - URL to the remove remote metadata
Throws:
MetadataProviderException - thrown if the HTTP client is null or the metadata URL provided is invalid
Method Detail

getMetadataURI

public String getMetadataURI()
Gets the URL to fetch the metadata.

Returns:
the URL to fetch the metadata

setBasicCredentials

public void setBasicCredentials(String username,
                                String password)
Sets the username and password used to access the metadata URL. To disable BASIC authentication set the username and password to null;

Parameters:
username - the username
password - the password

getRequestTimeout

public int getRequestTimeout()
Gets the length of time in milliseconds to wait for the server to respond.

Returns:
length of time in milliseconds to wait for the server to respond

setSocketFactory

public void setSocketFactory(org.apache.commons.httpclient.protocol.ProtocolSocketFactory newSocketFactory)
Deprecated. set this information on HTTP client used by provider

Sets the socket factory used to create sockets to the HTTP server.

Parameters:
newSocketFactory - the socket factory used to produce sockets used to connect to the server
See Also:
HTTPClient SSL guide

getMaxCacheDuration

public int getMaxCacheDuration()
Deprecated. use AbstractReloadingMetadataProvider.getMaxRefreshDelay() instead

Gets the maximum amount of time, in seconds, metadata will be cached for.

Returns:
maximum amount of time, in seconds, metadata will be cached for

setMaxCacheDuration

public void setMaxCacheDuration(int newDuration)
Deprecated. use AbstractReloadingMetadataProvider.setMaxRefreshDelay(long) instead

Sets the maximum amount of time, in seconds, metadata will be cached for.

Parameters:
newDuration - maximum amount of time, in seconds, metadata will be cached for

maintainExpiredMetadata

public boolean maintainExpiredMetadata()
Deprecated. use BaseMetadataProvider.requireValidMetadata() instead

Gets whether cached metadata should be discarded if it expires and can not be refreshed.

Returns:
whether cached metadata should be discarded if it expires and can not be refreshed.

setMaintainExpiredMetadata

public void setMaintainExpiredMetadata(boolean maintain)
Deprecated. use BaseMetadataProvider.setRequireValidMetadata(boolean) instead

Sets whether cached metadata should be discarded if it expires and can not be refreshed.

Parameters:
maintain - whether cached metadata should be discarded if it expires and can not be refreshed.

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 AbstractReloadingMetadataProvider

getMetadataIdentifier

protected String getMetadataIdentifier()
Gets an identifier which may be used to distinguish this metadata in logging statements.

Specified by:
getMetadataIdentifier in class AbstractReloadingMetadataProvider
Returns:
identifier which may be used to distinguish this metadata in logging statements

fetchMetadata

protected byte[] fetchMetadata()
                        throws MetadataProviderException
Gets the metadata document from the remote server.

Specified by:
fetchMetadata in class AbstractReloadingMetadataProvider
Returns:
the metadata from remote server, or null if the metadata document has not changed since the last retrieval
Throws:
MetadataProviderException - thrown if there is a problem retrieving the metadata from the remote server

buildGetMethod

protected org.apache.commons.httpclient.methods.GetMethod buildGetMethod()
Builds the HTTP GET method used to fetch the metadata. The returned method advertises support for GZIP and deflate compression, enables conditional GETs if the cached metadata came with either an ETag or Last-Modified information, and sets up basic authentication if such is configured.

Returns:
the constructed GET method

processConditionalRetrievalHeaders

protected void processConditionalRetrievalHeaders(org.apache.commons.httpclient.methods.GetMethod getMethod)
Records the ETag and Last-Modified headers, from the response, if they are present.

Parameters:
getMethod - GetMethod containing a valid HTTP response

getMetadataBytesFromResponse

protected byte[] getMetadataBytesFromResponse(org.apache.commons.httpclient.methods.GetMethod getMethod)
                                       throws MetadataProviderException
Extracts the raw metadata bytes from the response taking in to account possible deflate and GZip compression.

Parameters:
getMethod - GetMethod containing a valid HTTP response
Returns:
the raw metadata bytes
Throws:
MetadataProviderException - thrown if there is a problem getting the raw metadata bytes from the response


Copyright © 1999-2012. All Rights Reserved.