From 7d09ef8d1415637274e33b18087fa4974bedbd21 Mon Sep 17 00:00:00 2001 From: lajoie Date: Mon, 5 Feb 2007 13:11:06 +0000 Subject: [PATCH] Metadata code moved to shib-common git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2140 ab3bd59b-922f-494d-bb5f-6f0a3c29deca --- .../shibboleth/metadata/DOMMetadataProvider.java | 27 ------- .../metadata/FilesystemMetadataProvider.java | 51 ------------- .../metadata/MetadataProviderFactory.java | 51 ------------- .../ShibbolethConfigurableMetadataProvider.java | 79 -------------------- .../shibboleth/metadata/URLMetadataProvider.java | 65 ---------------- 5 files changed, 273 deletions(-) delete mode 100644 src/edu/internet2/middleware/shibboleth/metadata/DOMMetadataProvider.java delete mode 100644 src/edu/internet2/middleware/shibboleth/metadata/FilesystemMetadataProvider.java delete mode 100644 src/edu/internet2/middleware/shibboleth/metadata/MetadataProviderFactory.java delete mode 100644 src/edu/internet2/middleware/shibboleth/metadata/ShibbolethConfigurableMetadataProvider.java delete mode 100644 src/edu/internet2/middleware/shibboleth/metadata/URLMetadataProvider.java diff --git a/src/edu/internet2/middleware/shibboleth/metadata/DOMMetadataProvider.java b/src/edu/internet2/middleware/shibboleth/metadata/DOMMetadataProvider.java deleted file mode 100644 index 3b9c9db..0000000 --- a/src/edu/internet2/middleware/shibboleth/metadata/DOMMetadataProvider.java +++ /dev/null @@ -1,27 +0,0 @@ - -package edu.internet2.middleware.shibboleth.metadata; - -import org.opensaml.saml2.metadata.provider.MetadataProvider; -import org.opensaml.saml2.metadata.provider.MetadataProviderException; -import org.w3c.dom.Element; - -/** - * Loads metadata directly from the IdP configuration. - * - * @author Walter Hoehn - */ -/* - * We could do without this class, I guess, since the OpenSAML version has the right constructor; but it seems prudent - * to put it in the same hierarchy with its peers. - */ -public class DOMMetadataProvider extends ShibbolethConfigurableMetadataProvider implements MetadataProvider { - - public DOMMetadataProvider(Element configuration) throws MetadataProviderException { - - super(configuration); - - provider = new org.opensaml.saml2.metadata.provider.DOMMetadataProvider(configuration); - - } - -} diff --git a/src/edu/internet2/middleware/shibboleth/metadata/FilesystemMetadataProvider.java b/src/edu/internet2/middleware/shibboleth/metadata/FilesystemMetadataProvider.java deleted file mode 100644 index b3535af..0000000 --- a/src/edu/internet2/middleware/shibboleth/metadata/FilesystemMetadataProvider.java +++ /dev/null @@ -1,51 +0,0 @@ - -package edu.internet2.middleware.shibboleth.metadata; - -import java.io.IOException; - -import org.apache.log4j.Logger; -import org.opensaml.saml2.metadata.provider.MetadataProvider; -import org.opensaml.saml2.metadata.provider.MetadataProviderException; -import org.w3c.dom.Element; - -import edu.internet2.middleware.shibboleth.common.ShibResource; -import edu.internet2.middleware.shibboleth.common.ShibResource.ResourceNotAvailableException; - -/** - * Loads metadata from a path specified in the IdP configuration. - * - * @author Walter Hoehn - */ -public class FilesystemMetadataProvider extends ShibbolethConfigurableMetadataProvider implements MetadataProvider { - - private static Logger log = Logger.getLogger(FilesystemMetadataProvider.class.getName()); - - public FilesystemMetadataProvider(Element configuration) throws MetadataProviderException { - - super(configuration); - - // Grab the path from the config - String path = ((Element) configuration).getAttribute("path"); - if (path == null || path.equals("")) { - log.error("Unable to load File System Metadata Provider. A (path) attribute is required. " - + "Add a (path) attribute to ."); - throw new MetadataProviderException("Required configuration not specified."); - } - - // Construct provider from config - try { - provider = new org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider(new ShibResource(path) - .getFile()); - - } catch (MetadataProviderException e) { - log.error("Unable to load URL Metadata Provider: " + e); - throw e; - } catch (ResourceNotAvailableException e) { - log.error("Unable to load File System Metadata Provider. Could not access file at (" + path + ")."); - throw new MetadataProviderException("Supplied configuration is invalid."); - } catch (IOException e) { - log.error("Unable to load File System Metadata Provider. Error while reading file: " + e); - throw new MetadataProviderException("Supplied configuration is invalid."); - } - } -} diff --git a/src/edu/internet2/middleware/shibboleth/metadata/MetadataProviderFactory.java b/src/edu/internet2/middleware/shibboleth/metadata/MetadataProviderFactory.java deleted file mode 100644 index f8d7327..0000000 --- a/src/edu/internet2/middleware/shibboleth/metadata/MetadataProviderFactory.java +++ /dev/null @@ -1,51 +0,0 @@ - -package edu.internet2.middleware.shibboleth.metadata; - -/* - * Copyright [2005] [University Corporation for Advanced Internet Development, Inc.] - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.log4j.Logger; -import org.opensaml.saml2.metadata.provider.MetadataProvider; -import org.opensaml.saml2.metadata.provider.MetadataProviderException; -import org.w3c.dom.Element; - -public class MetadataProviderFactory { - - private static Logger log = Logger.getLogger(MetadataProviderFactory.class.getName()); - - public static MetadataProvider loadProvider(Element e) throws MetadataProviderException { - - String className = e.getAttribute("type"); - if (className == null || className.equals("")) { - log.error("Metadata Provider requires specification of the attribute \"type\"."); - throw new MetadataProviderException("Failed to initialize Metadata Provider."); - } else { - try { - Class[] params = {Class.forName("org.w3c.dom.Element"),}; - return (MetadataProvider) Class.forName(className).getConstructor(params).newInstance(new Object[]{e}); - - } catch (Exception loaderException) { - log.error("Failed to load Metadata Provider implementation class: " + loaderException); - Throwable cause = loaderException.getCause(); - while (cause != null) { - log.error("caused by: " + cause); - cause = cause.getCause(); - } - throw new MetadataProviderException("Failed to initialize Metadata Provider."); - } - } - } -} diff --git a/src/edu/internet2/middleware/shibboleth/metadata/ShibbolethConfigurableMetadataProvider.java b/src/edu/internet2/middleware/shibboleth/metadata/ShibbolethConfigurableMetadataProvider.java deleted file mode 100644 index 30042a0..0000000 --- a/src/edu/internet2/middleware/shibboleth/metadata/ShibbolethConfigurableMetadataProvider.java +++ /dev/null @@ -1,79 +0,0 @@ - -package edu.internet2.middleware.shibboleth.metadata; - -import java.util.List; - -import javax.xml.namespace.QName; - -import org.opensaml.saml2.metadata.EntitiesDescriptor; -import org.opensaml.saml2.metadata.EntityDescriptor; -import org.opensaml.saml2.metadata.RoleDescriptor; -import org.opensaml.saml2.metadata.provider.MetadataFilter; -import org.opensaml.saml2.metadata.provider.MetadataProvider; -import org.opensaml.saml2.metadata.provider.MetadataProviderException; -import org.opensaml.xml.XMLObject; -import org.w3c.dom.Element; - -/** - * Base class for MetadataProvider implementations that can be loaded based on the IdP runtime - * configuration. Implementors should create a constructor that accepts a configuration Element and sets - * the provider field. - * - * @author Walter Hoehn - */ -public abstract class ShibbolethConfigurableMetadataProvider implements MetadataProvider { - - protected org.opensaml.saml2.metadata.provider.MetadataProvider provider; - - public ShibbolethConfigurableMetadataProvider(Element configuration) { - - } - - public boolean requireValidMetadata() { - - return provider.requireValidMetadata(); - } - - public void setRequireValidMetadata(boolean requireValidMetadata) { - - provider.setRequireValidMetadata(requireValidMetadata); - - } - - public MetadataFilter getMetadataFilter() { - - return provider.getMetadataFilter(); - } - - public void setMetadataFilter(MetadataFilter newFilter) throws MetadataProviderException { - - provider.setMetadataFilter(newFilter); - - } - - public EntityDescriptor getEntityDescriptor(String entityID) throws MetadataProviderException { - - return provider.getEntityDescriptor(entityID); - } - - public List getRole(String entityID, QName roleName) throws MetadataProviderException { - - return provider.getRole(entityID, roleName); - } - - public XMLObject getMetadata() throws MetadataProviderException { - - return provider.getMetadata(); - } - - public EntitiesDescriptor getEntitiesDescriptor(String name) throws MetadataProviderException { - - return provider.getEntitiesDescriptor(name); - } - - public RoleDescriptor getRole(String entityID, QName roleName, String supportedProtocol) - throws MetadataProviderException { - - return provider.getRole(entityID, roleName, supportedProtocol); - } -} diff --git a/src/edu/internet2/middleware/shibboleth/metadata/URLMetadataProvider.java b/src/edu/internet2/middleware/shibboleth/metadata/URLMetadataProvider.java deleted file mode 100644 index 70b2bc7..0000000 --- a/src/edu/internet2/middleware/shibboleth/metadata/URLMetadataProvider.java +++ /dev/null @@ -1,65 +0,0 @@ - -package edu.internet2.middleware.shibboleth.metadata; - -import org.apache.log4j.Logger; -import org.opensaml.saml2.metadata.provider.MetadataProvider; -import org.opensaml.saml2.metadata.provider.MetadataProviderException; -import org.w3c.dom.Element; - -/** - * Loads metadata from a URL specified in the IdP configuration. - * - * @author Walter Hoehn - */ -public class URLMetadataProvider extends ShibbolethConfigurableMetadataProvider implements MetadataProvider { - - private static Logger log = Logger.getLogger(URLMetadataProvider.class.getName()); - - public URLMetadataProvider(Element configuration) throws MetadataProviderException { - - super(configuration); - - // Grab the URL from the config - String url = ((Element) configuration).getAttribute("url"); - if (url == null || url.equals("")) { - log.error("Unable to load URL Metadata Provider. A (url) attribute is required. " - + "Add a (url) attribute to ."); - throw new MetadataProviderException("Required configuration not specified."); - } - - // Grab the request timeout, if there is one. If not, use a reasonable default - int requestTimeout = 1000 * 1 * 60; // 1 minute - String rawRequestTimeout = ((Element) configuration).getAttribute("requestTimeout"); - if (rawRequestTimeout != null && !rawRequestTimeout.equals("")) { - try { - requestTimeout = Integer.valueOf(rawRequestTimeout); - } catch (NumberFormatException nfe) { - log.error("Unable to load URL Metadata Provider. The (requestTimeout) attribute must be an integer. " - + "Modify the (requestTimeout) attribute on ."); - throw new MetadataProviderException("Configuration is invalid."); - } - } - - // Construct provider from config - try { - provider = new org.opensaml.saml2.metadata.provider.URLMetadataProvider(url, requestTimeout); - - // If there is a cache duration, set it - String rawMaxCacheDuration = ((Element) configuration).getAttribute("maxCacheDuration"); - if (rawMaxCacheDuration != null && !rawMaxCacheDuration.equals("")) { - try { - ((org.opensaml.saml2.metadata.provider.URLMetadataProvider) provider).setMaxDuration(Integer - .valueOf(rawMaxCacheDuration)); - } catch (NumberFormatException nfe) { - log.error("Unable to load URL Metadata Provider. The (maxCacheDuration) attribute must be " - + "an integer. Modify the (maxCacheDuration) attribute on ."); - throw new MetadataProviderException("Configuration is invalid."); - } - } - - } catch (MetadataProviderException e) { - log.error("Unable to load URL Metadata Provider: " + e); - throw e; - } - } -} -- 1.7.10.4