Author: anil.saldhana(a)jboss.com
Date: 2009-04-22 23:48:49 -0400 (Wed, 22 Apr 2009)
New Revision: 454
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/MetadataServlet.java
Log:
JBID-42: samlv2 metadata
Added:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/MetadataServlet.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/MetadataServlet.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/servlets/MetadataServlet.java 2009-04-23
03:48:49 UTC (rev 454)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.identity.federation.bindings.servlets;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.bind.JAXBElement;
+
+import org.apache.log4j.Logger;
+import org.jboss.identity.federation.api.saml.v2.metadata.MetaDataBuilder;
+import org.jboss.identity.federation.bindings.config.KeyValueType;
+import org.jboss.identity.federation.bindings.config.MetadataProviderType;
+import org.jboss.identity.federation.bindings.config.ProviderType;
+import org.jboss.identity.federation.bindings.providers.IMetadataProvider;
+import org.jboss.identity.federation.bindings.util.ValveUtil;
+import org.jboss.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
+import org.jboss.identity.federation.saml.v2.metadata.EntityDescriptorType;
+
+/**
+ * Metadata servlet for the IDP/SP
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Apr 22, 2009
+ */
+public class MetadataServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+ private static Logger log = Logger.getLogger(MetadataServlet.class);
+
+ private String configFileLocation = "/WEB-INF/jboss-idfed.xml";
+ private MetadataProviderType metadataProviderType = null;
+
+ private IMetadataProvider<?> metadataProvider = null;
+
+ private EntityDescriptorType metadata;
+
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void init(ServletConfig config) throws ServletException
+ {
+ super.init(config);
+ ServletContext context = config.getServletContext();
+ String configL = config.getInitParameter("configFile");
+ if(configL != null && configL.length() > 0)
+ configFileLocation = configL;
+ log.trace("Config File Location="+ configFileLocation);
+ InputStream is = context.getResourceAsStream(configFileLocation);
+ if(is == null)
+ throw new RuntimeException(configFileLocation + " missing");
+ try
+ {
+ ProviderType providerType = ValveUtil.getIDPConfiguration(is);
+ metadataProviderType = providerType.getMetaDataProvider();
+ String fqn = metadataProviderType.getClassName();
+ ClassLoader tcl = SecurityActions.getContextClassLoader();
+ Class<?> clazz = tcl.loadClass(fqn);
+ metadataProvider = (IMetadataProvider) clazz.newInstance();
+ List<KeyValueType> keyValues = metadataProviderType.getOption();
+ Map<String,String> options = new HashMap<String,String>();
+ if(keyValues != null)
+ {
+ for(KeyValueType kvt: keyValues)
+ options.put(kvt.getKey(), kvt.getValue());
+ }
+ metadataProvider.init(options);
+ if(metadataProvider.isMultiple())
+ throw new RuntimeException("Multiple Entities not currently
supported");
+
+ String fileInjectionStr = metadataProvider.requireFileInjection();
+ if(fileInjectionStr != null && fileInjectionStr.length() > 0)
+ {
+
metadataProvider.injectFileStream(context.getResourceAsStream(fileInjectionStr));
+ }
+
+ //TODO: signing and encryption key
+
+ metadata = (EntityDescriptorType) metadataProvider.getMetaData();
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException
+ {
+ resp.setContentType(JBossSAMLConstants.METADATA_MIME.get());
+ OutputStream os = resp.getOutputStream();
+ JAXBElement<?> jaxbEl =
MetaDataBuilder.getObjectFactory().createEntityDescriptor(metadata);
+ try
+ {
+ MetaDataBuilder.getMarshaller().marshal(jaxbEl , os);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
\ No newline at end of file