Author: anil.saldhana(a)jboss.com
Date: 2009-05-26 11:25:25 -0400 (Tue, 26 May 2009)
New Revision: 535
Added:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/JAXBUtil.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/SecurityActions.java
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/ValveUtil.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/MetadataConfigUnitTestCase.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/metadata/MetaDataBuilder.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/KeyUtil.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/XMLSignatureUtil.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLBaseFactory.java
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/metadata/store/FileBasedMetadataConfigurationStore.java
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/saml/v2/metadata/FileBasedMetadataConfigurationStoreUnitTestCase.java
Log:
JBID-120: use a central util for JAXB
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/ValveUtil.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/ValveUtil.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/ValveUtil.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -35,7 +35,7 @@
import org.jboss.identity.federation.bindings.config.IDPType;
import org.jboss.identity.federation.bindings.config.SPType;
import org.jboss.identity.federation.core.constants.JBossIdentityFederationConstants;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.xml.sax.SAXException;
/**
@@ -108,9 +108,9 @@
String pkgName = "org.jboss.identity.federation.bindings.config";
Unmarshaller un = null;
if(validate)
- un = JBossSAMLBaseFactory.getValidatingUnmarshaller(pkgName, schema);
+ un = JAXBUtil.getValidatingUnmarshaller(pkgName, schema);
else
- un = JBossSAMLBaseFactory.getUnmarshaller(pkgName);
+ un = JAXBUtil.getUnmarshaller(pkgName);
JAXBElement<IDPType> jaxbSp = (JAXBElement<IDPType>)
un.unmarshal(is);
return jaxbSp.getValue();
@@ -129,9 +129,9 @@
String pkgName = "org.jboss.identity.federation.bindings.config";
Unmarshaller un = null;
if(validate)
- un = JBossSAMLBaseFactory.getValidatingUnmarshaller(pkgName, schema);
+ un = JAXBUtil.getValidatingUnmarshaller(pkgName, schema);
else
- un = JBossSAMLBaseFactory.getUnmarshaller(pkgName);
+ un = JAXBUtil.getUnmarshaller(pkgName);
JAXBElement<SPType> jaxbSp = (JAXBElement<SPType>) un.unmarshal(is);
return jaxbSp.getValue();
Modified:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -40,7 +40,7 @@
import org.jboss.identity.federation.bindings.config.TokenProviderType;
import org.jboss.identity.federation.bindings.config.TokenProvidersType;
import org.jboss.identity.federation.bindings.config.TrustType;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
/**
* Unit Test the various config
@@ -174,7 +174,7 @@
InputStream is = tcl.getResourceAsStream(configFile);
assertNotNull("Inputstream not null", is);
- Unmarshaller un =
JBossSAMLBaseFactory.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
+ Unmarshaller un =
JAXBUtil.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
schema);
return un.unmarshal(is);
}
Modified:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/MetadataConfigUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/MetadataConfigUnitTestCase.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/MetadataConfigUnitTestCase.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -33,7 +33,7 @@
import org.jboss.identity.federation.bindings.config.KeyValueType;
import org.jboss.identity.federation.bindings.config.MetadataProviderType;
import org.jboss.identity.federation.bindings.config.TrustType;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
/**
@@ -81,7 +81,7 @@
assertNotNull("Inputstream not null", is);
Unmarshaller un =
-
JBossSAMLBaseFactory.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
+
JAXBUtil.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
schema);
return un.unmarshal(is);
}
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/metadata/MetaDataBuilder.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/metadata/MetaDataBuilder.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/saml/v2/metadata/MetaDataBuilder.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -28,7 +28,7 @@
import javax.xml.bind.Unmarshaller;
import org.jboss.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.federation.saml.v2.assertion.AttributeType;
import org.jboss.identity.federation.saml.v2.metadata.EndpointType;
import org.jboss.identity.federation.saml.v2.metadata.EntityDescriptorType;
@@ -180,7 +180,7 @@
*/
public static Marshaller getMarshaller() throws JAXBException
{
- return JBossSAMLBaseFactory.getMarshaller(pkgName);
+ return JAXBUtil.getMarshaller(pkgName);
}
/**
@@ -190,7 +190,7 @@
*/
public static Unmarshaller getUnmarshaller() throws JAXBException
{
- return JBossSAMLBaseFactory.getUnmarshaller(pkgName);
+ return JAXBUtil.getUnmarshaller(pkgName);
}
/**
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/KeyUtil.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/KeyUtil.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/KeyUtil.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -34,7 +34,7 @@
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.xmlsec.w3.xmldsig.KeyInfoType;
import org.jboss.identity.xmlsec.w3.xmldsig.ObjectFactory;
@@ -109,7 +109,7 @@
*/
public static Unmarshaller getUnmarshaller() throws JAXBException
{
- return
JBossSAMLBaseFactory.getUnmarshaller("org.jboss.identity.xmlsec.w3.xmldsig");
+ return JAXBUtil.getUnmarshaller("org.jboss.identity.xmlsec.w3.xmldsig");
}
/**
@@ -119,7 +119,7 @@
*/
public static Marshaller getMarshaller() throws JAXBException
{
- return
JBossSAMLBaseFactory.getMarshaller("org.jboss.identity.xmlsec.w3.xmldsig");
+ return JAXBUtil.getMarshaller("org.jboss.identity.xmlsec.w3.xmldsig");
}
/**
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/XMLSignatureUtil.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/XMLSignatureUtil.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/util/XMLSignatureUtil.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -53,7 +53,7 @@
import javax.xml.transform.stream.StreamResult;
import org.jboss.identity.federation.api.saml.v2.request.SAML2Request;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.federation.saml.v2.protocol.AuthnRequestType;
import org.jboss.identity.federation.saml.v2.protocol.RequestAbstractType;
import org.jboss.identity.xmlsec.w3.xmldsig.ObjectFactory;
@@ -231,7 +231,7 @@
public static void marshall(SignatureType signature, OutputStream os) throws
Exception
{
JAXBElement<SignatureType> jsig = objectFactory.createSignature(signature);
- Marshaller marshaller = JBossSAMLBaseFactory.getValidatingMarshaller(pkgName,
schemaLocation);
+ Marshaller marshaller = JAXBUtil.getValidatingMarshaller(pkgName, schemaLocation);
marshaller.marshal(jsig, os);
}
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnRequestFactory.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -30,6 +30,7 @@
import org.jboss.identity.federation.core.saml.v2.constants.JBossSAMLConstants;
import org.jboss.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.federation.saml.v2.assertion.NameIDType;
import org.jboss.identity.federation.saml.v2.protocol.AuthnRequestType;
import org.xml.sax.SAXException;
@@ -104,9 +105,9 @@
public static Marshaller getValidatingMarshaller(boolean schemaValidation) throws
SAXException, JAXBException
{
if(schemaValidation)
- return JBossSAMLBaseFactory.getValidatingMarshaller(pkgName, schemaLocation);
+ return JAXBUtil.getValidatingMarshaller(pkgName, schemaLocation);
else
- return JBossSAMLBaseFactory.getMarshaller(pkgName);
+ return JAXBUtil.getMarshaller(pkgName);
}
/**
@@ -119,8 +120,8 @@
public static Unmarshaller getValidatingUnmarshaller(boolean schemaValidation) throws
JAXBException, SAXException
{
if(schemaValidation)
- return JBossSAMLBaseFactory.getValidatingUnmarshaller(pkgName, schemaLocation);
+ return JAXBUtil.getValidatingUnmarshaller(pkgName, schemaLocation);
else
- return JBossSAMLBaseFactory.getUnmarshaller(pkgName);
+ return JAXBUtil.getUnmarshaller(pkgName);
}
}
\ No newline at end of file
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLAuthnResponseFactory.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -32,6 +32,7 @@
import org.jboss.identity.federation.core.saml.v2.holders.IssuerInfoHolder;
import org.jboss.identity.federation.core.saml.v2.holders.SPInfoHolder;
import org.jboss.identity.federation.core.saml.v2.util.XMLTimeUtil;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.federation.saml.v2.assertion.AssertionType;
import org.jboss.identity.federation.saml.v2.assertion.NameIDType;
import org.jboss.identity.federation.saml.v2.assertion.SubjectConfirmationDataType;
@@ -181,7 +182,7 @@
*/
public static Marshaller getValidatingMarshaller() throws SAXException, JAXBException
{
- return JBossSAMLBaseFactory.getValidatingMarshaller(pkgName, schemaLocation);
+ return JAXBUtil.getValidatingMarshaller(pkgName, schemaLocation);
}
/**
@@ -192,6 +193,6 @@
*/
public static Unmarshaller getValidatingUnmarshaller() throws JAXBException,
SAXException
{
- return JBossSAMLBaseFactory.getValidatingUnmarshaller(pkgName, schemaLocation);
+ return JAXBUtil.getValidatingUnmarshaller(pkgName, schemaLocation);
}
}
\ No newline at end of file
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLBaseFactory.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLBaseFactory.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/factories/JBossSAMLBaseFactory.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -21,16 +21,9 @@
*/
package org.jboss.identity.federation.core.saml.v2.factories;
-import java.net.URL;
-import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.validation.Schema;
-import javax.xml.validation.SchemaFactory;
import org.jboss.identity.federation.core.saml.v2.constants.JBossSAMLURIConstants;
import org.jboss.identity.federation.saml.v2.assertion.AssertionType;
@@ -41,7 +34,6 @@
import org.jboss.identity.federation.saml.v2.assertion.SubjectConfirmationDataType;
import org.jboss.identity.federation.saml.v2.assertion.SubjectConfirmationType;
import org.jboss.identity.federation.saml.v2.assertion.SubjectType;
-import org.xml.sax.SAXException;
/**
* Base methods for the factories
@@ -51,9 +43,7 @@
public class JBossSAMLBaseFactory
{
private static ObjectFactory assertionObjectFactory = new ObjectFactory();
-
- public static final String W3C_XML_SCHEMA_NS_URI =
"http://www.w3.org/2001/XMLSchema";
-
+
/**
* Create a plain assertion type
* @return
@@ -205,84 +195,4 @@
nid.setValue(issuerID);
return nid;
}
-
- /**
- * Get the JAXB Marshaller
- * @param pkgName The package name for the jaxb context
- * @return Marshaller
- * @throws JAXBException
- */
- public static Marshaller getMarshaller(String pkgName) throws JAXBException
- {
- if(pkgName == null)
- throw new IllegalArgumentException("pkgName is null");
-
- JAXBContext jc = JAXBContext.newInstance(pkgName);
- Marshaller marshaller = jc.createMarshaller();
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- return marshaller;
- }
-
- /**
- * Get the JAXB Marshaller
- * @param pkgName The package name for the jaxb context
- * @param schemaLocation location of the schema to validate against
- * @return Marshaller
- * @throws JAXBException
- * @throws SAXException
- */
- public static Marshaller getValidatingMarshaller(String pkgName, String
schemaLocation)
- throws JAXBException, SAXException
- {
- Marshaller marshaller = getMarshaller(pkgName);
- marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
- //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(W3C_XML_SCHEMA_NS_URI);
- Schema schema = scFact.newSchema(schemaURL);
- marshaller.setSchema(schema);
-
- return marshaller;
- }
-
- /**
- * Get the JAXB Unmarshaller
- * @param pkgName The package name for the jaxb context
- * @return unmarshaller
- * @throws JAXBException
- */
- public static Unmarshaller getUnmarshaller(String pkgName) throws JAXBException
- {
- if(pkgName == null)
- throw new IllegalArgumentException("pkgName is null");
- JAXBContext jc = JAXBContext.newInstance(pkgName);
- return jc.createUnmarshaller();
- }
-
- /**
- * Get the JAXB Unmarshaller
- * @param pkgName The package name for the jaxb context
- * @param schemaLocation location of the schema to validate against
- * @return unmarshaller
- * @throws JAXBException
- * @throws SAXException
- */
- public static Unmarshaller getValidatingUnmarshaller(String pkgName, String
schemaLocation)
- throws JAXBException, SAXException
- {
- Unmarshaller unmarshaller = getUnmarshaller(pkgName);
- //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(W3C_XML_SCHEMA_NS_URI);
- Schema schema = scFact.newSchema(schemaURL);
- unmarshaller.setSchema(schema);
-
- return unmarshaller;
- }
}
\ No newline at end of file
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/metadata/store/FileBasedMetadataConfigurationStore.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/metadata/store/FileBasedMetadataConfigurationStore.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/saml/v2/metadata/store/FileBasedMetadataConfigurationStore.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -35,7 +35,7 @@
import javax.xml.bind.Unmarshaller;
import org.apache.log4j.Logger;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.federation.saml.v2.metadata.EntityDescriptorType;
import org.jboss.identity.federation.saml.v2.metadata.ObjectFactory;
@@ -81,7 +81,7 @@
Unmarshaller un;
try
{
- un = JBossSAMLBaseFactory.getUnmarshaller(pkgName);
+ un = JAXBUtil.getUnmarshaller(pkgName);
JAXBElement<EntityDescriptorType> je =
(JAXBElement<EntityDescriptorType>) un.unmarshal(persistedFile);
return je.getValue();
@@ -109,7 +109,7 @@
Marshaller m;
try
{
- m = JBossSAMLBaseFactory.getMarshaller(pkgName);
+ m = JAXBUtil.getMarshaller(pkgName);
m.marshal(jentity, persistedFile);
}
catch (JAXBException e)
Added:
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/JAXBUtil.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/JAXBUtil.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/JAXBUtil.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -0,0 +1,124 @@
+/*
+ * 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.core.util;
+
+import java.net.URL;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Utility to obtain JAXB2 marshaller/unmarshaller etc
+ * @author Anil.Saldhana(a)redhat.com
+ * @since May 26, 2009
+ */
+public class JAXBUtil
+{
+ public static final String W3C_XML_SCHEMA_NS_URI =
"http://www.w3.org/2001/XMLSchema";
+
+
+ /**
+ * Get the JAXB Marshaller
+ * @param pkgName The package name for the jaxb context
+ * @param schemaLocation location of the schema to validate against
+ * @return Marshaller
+ * @throws JAXBException
+ * @throws SAXException
+ */
+ public static Marshaller getValidatingMarshaller(String pkgName, String
schemaLocation)
+ throws JAXBException, SAXException
+ {
+ Marshaller marshaller = JAXBUtil.getMarshaller(pkgName);
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+ //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(W3C_XML_SCHEMA_NS_URI);
+ Schema schema = scFact.newSchema(schemaURL);
+ marshaller.setSchema(schema);
+
+ return marshaller;
+ }
+
+ /**
+ * Get the JAXB Marshaller
+ * @param pkgName The package name for the jaxb context
+ * @return Marshaller
+ * @throws JAXBException
+ */
+ public static Marshaller getMarshaller(String pkgName) throws JAXBException
+ {
+ if(pkgName == null)
+ throw new IllegalArgumentException("pkgName is null");
+
+ JAXBContext jc = JAXBContext.newInstance(pkgName);
+ Marshaller marshaller = jc.createMarshaller();
+ marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+ return marshaller;
+ }
+
+ /**
+ * Get the JAXB Unmarshaller
+ * @param pkgName The package name for the jaxb context
+ * @return unmarshaller
+ * @throws JAXBException
+ */
+ public static Unmarshaller getUnmarshaller(String pkgName) throws JAXBException
+ {
+ if(pkgName == null)
+ throw new IllegalArgumentException("pkgName is null");
+ JAXBContext jc = JAXBContext.newInstance(pkgName);
+ return jc.createUnmarshaller();
+ }
+
+ /**
+ * Get the JAXB Unmarshaller
+ * @param pkgName The package name for the jaxb context
+ * @param schemaLocation location of the schema to validate against
+ * @return unmarshaller
+ * @throws JAXBException
+ * @throws SAXException
+ */
+ public static Unmarshaller getValidatingUnmarshaller(String pkgName, String
schemaLocation)
+ throws JAXBException, SAXException
+ {
+ Unmarshaller unmarshaller = getUnmarshaller(pkgName);
+ //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(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/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/SecurityActions.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/SecurityActions.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-core/src/main/java/org/jboss/identity/federation/core/util/SecurityActions.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -0,0 +1,65 @@
+/*
+ * 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.core.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Blocks
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Dec 9, 2008
+ */
+class SecurityActions
+{
+ /**
+ * Get the Thread Context ClassLoader
+ * @return
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+
+ /**
+ * Get the system property
+ * @param key
+ * @param defaultValue
+ * @return
+ */
+ static String getSystemProperty(final String key, final String defaultValue)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<String>()
+ {
+ public String run()
+ {
+ return System.getProperty(key, defaultValue);
+ }
+ });
+ }
+}
Modified:
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/saml/v2/metadata/FileBasedMetadataConfigurationStoreUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/saml/v2/metadata/FileBasedMetadataConfigurationStoreUnitTestCase.java 2009-05-26
15:09:14 UTC (rev 534)
+++
identity-federation/trunk/jboss-identity-fed-core/src/test/java/org/jboss/test/identity/federation/core/saml/v2/metadata/FileBasedMetadataConfigurationStoreUnitTestCase.java 2009-05-26
15:25:25 UTC (rev 535)
@@ -28,8 +28,8 @@
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Unmarshaller;
-import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
import
org.jboss.identity.federation.core.saml.v2.metadata.store.FileBasedMetadataConfigurationStore;
+import org.jboss.identity.federation.core.util.JAXBUtil;
import org.jboss.identity.federation.saml.v2.metadata.EntityDescriptorType;
import junit.framework.TestCase;
@@ -53,7 +53,7 @@
tcl.getResourceAsStream("saml2/metadata/idp-entitydescriptor.xml");
assertNotNull("Inputstream not null", is);
- Unmarshaller un = JBossSAMLBaseFactory.getUnmarshaller(pkgName);
+ Unmarshaller un = JAXBUtil.getUnmarshaller(pkgName);
JAXBElement<EntityDescriptorType> je =
(JAXBElement<EntityDescriptorType>) un.unmarshal(is);
EntityDescriptorType edt = je.getValue();
assertNotNull("EntityDescriptorType not null", edt);