2 package edu.internet2.middleware.shibboleth.metadata;
4 import org.apache.log4j.Logger;
5 import org.opensaml.saml2.metadata.provider.MetadataProvider;
6 import org.opensaml.saml2.metadata.provider.MetadataProviderException;
7 import org.w3c.dom.Element;
10 * Loads metadata from a URL specified in the IdP configuration.
12 * @author Walter Hoehn
14 public class URLMetadataProvider extends ShibbolethConfigurableMetadataProvider implements MetadataProvider {
16 private static Logger log = Logger.getLogger(URLMetadataProvider.class.getName());
18 public URLMetadataProvider(Element configuration) throws MetadataProviderException {
22 // Grab the URL from the config
23 String url = ((Element) configuration).getAttribute("url");
24 if (url == null || url.equals("")) {
25 log.error("Unable to load URL Metadata Provider. A (url) attribute is required. "
26 + "Add a (url) attribute to <MetadataProvider/>.");
27 throw new MetadataProviderException("Required configuration not specified.");
30 // Grab the request timeout, if there is one. If not, use a reasonable default
31 int requestTimeout = 1000 * 1 * 60; // 1 minute
32 String rawRequestTimeout = ((Element) configuration).getAttribute("requestTimeout");
33 if (rawRequestTimeout != null && !rawRequestTimeout.equals("")) {
35 requestTimeout = Integer.valueOf(rawRequestTimeout);
36 } catch (NumberFormatException nfe) {
37 log.error("Unable to load URL Metadata Provider. The (requestTimeout) attribute must be an integer. "
38 + "Modify the (requestTimeout) attribute on <MetadataProvider/>.");
39 throw new MetadataProviderException("Configuration is invalid.");
43 // Construct provider from config
45 provider = new org.opensaml.saml2.metadata.provider.URLMetadataProvider(url, requestTimeout);
47 // If there is a cache duration, set it
48 String rawMaxCacheDuration = ((Element) configuration).getAttribute("maxCacheDuration");
49 if (rawMaxCacheDuration != null && !rawMaxCacheDuration.equals("")) {
51 ((org.opensaml.saml2.metadata.provider.URLMetadataProvider) provider).setMaxDuration(Integer
52 .valueOf(rawMaxCacheDuration));
53 } catch (NumberFormatException nfe) {
54 log.error("Unable to load URL Metadata Provider. The (maxCacheDuration) attribute must be "
55 + "an integer. Modify the (maxCacheDuration) attribute on <MetadataProvider/>.");
56 throw new MetadataProviderException("Configuration is invalid.");
60 } catch (MetadataProviderException e) {
61 log.error("Unable to load URL Metadata Provider: " + e);