Author: anil.saldhana(a)jboss.com
Date: 2008-12-09 15:03:26 -0500 (Tue, 09 Dec 2008)
New Revision: 141
Added:
identity-federation/trunk/identity-fed-api/src/main/
identity-federation/trunk/identity-fed-api/src/main/java/
identity-federation/trunk/identity-fed-api/src/main/java/org/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLBaseFactory.java
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/SecurityActions.java
identity-federation/trunk/identity-fed-api/src/main/resources/
Log:
factory
Added:
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
===================================================================
---
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
(rev 0)
+++
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2008-12-09
20:03:26 UTC (rev 141)
@@ -0,0 +1,63 @@
+/*
+ * 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.api.saml.v2.factories;
+
+import java.io.InputStream;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Unmarshaller;
+
+import org.jboss.identity.federation.saml.v2.protocol.AuthnRequestType;
+
+/**
+ * Factory for SAML2 AuthnRequest
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Dec 9, 2008
+ */
+public class JBossSAMLAuthnRequestFactory
+{
+ private static String pkgName =
"org.jboss.identity.federation.saml.v2.protocol";
+ private static String schemaLocation =
"schema/saml-schema-protocol-2.0.xsd";
+
+ /**
+ * Get AuthnRequestType from a file
+ * @param fileName file with the serialized AuthnRequestType
+ * @return AuthnRequestType
+ * @throws Exception
+ * @throws IllegalArgumentException if the input fileName is null
+ * IllegalStateException if the InputStream from the fileName is null
+ */
+ @SuppressWarnings("unchecked")
+ public static AuthnRequestType getAuthnRequestType(String fileName) throws Exception
+ {
+ if(fileName == null)
+ throw new IllegalArgumentException("fileName is null");
+
+ Unmarshaller un = JBossSAMLBaseFactory.getValidatingUnmarshaller(pkgName,
schemaLocation);
+ ClassLoader tcl = SecurityActions.getContextClassLoader();
+ InputStream is = tcl.getResourceAsStream(fileName);
+ if(is == null)
+ throw new IllegalStateException("InputStream is null for "+
fileName);
+ JAXBElement<AuthnRequestType> jaxbAuthnRequestType =
(JAXBElement<AuthnRequestType>) un.unmarshal(is);
+ return jaxbAuthnRequestType.getValue();
+ }
+}
Added:
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLBaseFactory.java
===================================================================
---
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLBaseFactory.java
(rev 0)
+++
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/JBossSAMLBaseFactory.java 2008-12-09
20:03:26 UTC (rev 141)
@@ -0,0 +1,67 @@
+/*
+ * 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.api.saml.v2.factories;
+
+import java.net.URL;
+
+import javax.xml.XMLConstants;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+/**
+ * Base methods for the factories
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Dec 9, 2008
+ */
+public class JBossSAMLBaseFactory
+{
+ /**
+ * Get the JAXB Unmarshaller
+ * @param pkgName The package name for the jaxb context
+ * @param schemaLocation location of the schema to validate against
+ * @param schemaValidating need a validating schema unmarshaller?
+ * @return unmarshaller
+ * @throws Exception
+ */
+ public static Unmarshaller getValidatingUnmarshaller(String pkgName, String
schemaLocation)
+ throws Exception
+ {
+ if(pkgName == null)
+ throw new IllegalArgumentException("pkgName is null");
+
+ JAXBContext jc = JAXBContext.newInstance(pkgName);
+ Unmarshaller unmarshaller = jc.createUnmarshaller();
+ //Validate against schema
+ ClassLoader tcl = SecurityActions.getContextClassLoader();
+ URL schemaURL = tcl.getResource(schemaLocation);
+ if(schemaURL == null)
+ throw new IllegalStateException("Schema URL is null:" +
schemaLocation);
+ SchemaFactory scFact =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Schema schema = scFact.newSchema(schemaURL);
+ unmarshaller.setSchema(schema);
+
+ return unmarshaller;
+ }
+
+}
\ No newline at end of file
Added:
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/SecurityActions.java
===================================================================
---
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/SecurityActions.java
(rev 0)
+++
identity-federation/trunk/identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/factories/SecurityActions.java 2008-12-09
20:03:26 UTC (rev 141)
@@ -0,0 +1,44 @@
+/*
+ * 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.api.saml.v2.factories;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Dec 9, 2008
+ */
+class SecurityActions
+{
+ static ClassLoader getContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}