Handler to server up IdP metadata, not added to default config yet
authorlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 18 Jan 2008 20:31:34 +0000 (20:31 +0000)
committerlajoie <lajoie@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Fri, 18 Jan 2008 20:31:34 +0000 (20:31 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@2582 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

resources/classpath/schema/shibboleth-2.0-idp-profile-handler.xsd
src/edu/internet2/middleware/shibboleth/idp/config/profile/SAMLMetadataHandlerBeanDefinitionParser.java [new file with mode: 0644]
src/edu/internet2/middleware/shibboleth/idp/profile/SAMLMetadataProfileHandler.java [new file with mode: 0644]

index 9c3a409..f7c0502 100644 (file)
             <xsd:extension base="RequestURIMappedProfileHandlerType" />
         </xsd:complexContent>
     </xsd:complexType>
+    
+    <xsd:complexType name="SAMLMetadata">
+        <xsd:annotation>
+            <xsd:documentation>Basic handler that returns a general status of the IdP.</xsd:documentation>
+        </xsd:annotation>
+        <xsd:complexContent>
+            <xsd:extension base="RequestURIMappedProfileHandlerType">
+                <xsd:attribute name="metadataFile" type="xsd:string" use="required">
+                    <xsd:annotation>
+                        <xsd:documentation>
+                            Location of the static IdP metadata file.
+                        </xsd:documentation>
+                    </xsd:annotation>
+                </xsd:attribute>
+            </xsd:extension>
+        </xsd:complexContent>
+    </xsd:complexType>
 
     <xsd:complexType name="SAML2SSO">
         <xsd:annotation>
diff --git a/src/edu/internet2/middleware/shibboleth/idp/config/profile/SAMLMetadataHandlerBeanDefinitionParser.java b/src/edu/internet2/middleware/shibboleth/idp/config/profile/SAMLMetadataHandlerBeanDefinitionParser.java
new file mode 100644 (file)
index 0000000..96850bd
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright [2007] [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.
+ */
+
+package edu.internet2.middleware.shibboleth.idp.config.profile;
+
+import javax.xml.namespace.QName;
+
+import org.springframework.beans.factory.support.BeanDefinitionBuilder;
+import org.w3c.dom.Element;
+
+import edu.internet2.middleware.shibboleth.common.config.profile.AbstractRequestURIMappedProfileHandlerBeanDefinitionParser;
+import edu.internet2.middleware.shibboleth.idp.profile.SAMLMetadataProfileHandler;
+
+/**
+ * Spring bean definition parser for {@link SAMLMetadataProfileHandler}s.
+ */
+public class SAMLMetadataHandlerBeanDefinitionParser extends AbstractRequestURIMappedProfileHandlerBeanDefinitionParser {
+
+    /** Schema type. */
+    public static final QName SCHEMA_TYPE = new QName(ProfileHandlerNamespaceHandler.NAMESPACE, "SAMLMetadata");
+
+    /** {@inheritDoc} */
+    protected Class getBeanClass(Element arg0) {
+        return SAMLMetadataProfileHandler.class;
+    }
+
+    /** {@inheritDoc} */
+    protected void doParse(Element config, BeanDefinitionBuilder builder) {
+        builder.addConstructorArg(config.getAttributeNS(null, "metadataFile"));
+    }
+
+    /** {@inheritDoc} */
+    protected boolean shouldGenerateId() {
+        return true;
+    }
+}
\ No newline at end of file
diff --git a/src/edu/internet2/middleware/shibboleth/idp/profile/SAMLMetadataProfileHandler.java b/src/edu/internet2/middleware/shibboleth/idp/profile/SAMLMetadataProfileHandler.java
new file mode 100644 (file)
index 0000000..a0081fb
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright [2007] [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.
+ */
+
+package edu.internet2.middleware.shibboleth.idp.profile;
+
+import java.io.File;
+import java.io.OutputStreamWriter;
+
+import javax.servlet.http.HttpServletRequestWrapper;
+
+import org.opensaml.Configuration;
+import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider;
+import org.opensaml.saml2.metadata.provider.MetadataProviderException;
+import org.opensaml.ws.transport.InTransport;
+import org.opensaml.ws.transport.OutTransport;
+import org.opensaml.xml.XMLObject;
+import org.opensaml.xml.io.Marshaller;
+import org.opensaml.xml.util.XMLHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import edu.internet2.middleware.shibboleth.common.profile.ProfileException;
+import edu.internet2.middleware.shibboleth.common.profile.provider.AbstractRequestURIMappedProfileHandler;
+
+/**
+ * A simple profile handler that serves up the IdP's metadata. Eventually this handler should auto generate the metadata
+ * but, for now, it just provides information from a static file.
+ */
+public class SAMLMetadataProfileHandler extends AbstractRequestURIMappedProfileHandler {
+
+    /** Class logger. */
+    private final Logger log = LoggerFactory.getLogger(SAMLMetadataProfileHandler.class);
+
+    /** Metadata provider. */
+    private FilesystemMetadataProvider metadataProvider;
+
+    /**
+     * Constructor.
+     * 
+     * @param metadataFile the IdPs metadata file
+     */
+    public SAMLMetadataProfileHandler(String metadataFile) {
+        try {
+            metadataProvider = new FilesystemMetadataProvider(new File(metadataFile));
+        } catch (MetadataProviderException e) {
+            log.error("Unable to read metadata file " + metadataFile, e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public String getProfileId() {
+        return "urn:mace:shibboleth:2.0:idp:profiles:saml2:metadata";
+    }
+
+    /** {@inheritDoc} */
+    public void processRequest(InTransport in, OutTransport out) throws ProfileException {
+        XMLObject metadata;
+
+        try {
+            String requestedEntity = ((HttpServletRequestWrapper) in).getParameter("entity");
+            if (requestedEntity == null) {
+                metadata = metadataProvider.getEntityDescriptor(requestedEntity);
+            } else {
+                metadata = metadataProvider.getMetadata();
+            }
+
+            Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(metadata);
+            XMLHelper.writeNode(marshaller.marshall(metadata), new OutputStreamWriter(out.getOutgoingStream()));
+        } catch (Exception e) {
+            log.error("Unable to retrieve and return metadata", e);
+            throw new ProfileException(e);
+        }
+    }
+}
\ No newline at end of file