Author: anil.saldhana(a)jboss.com
Date: 2011-03-02 12:26:35 -0500 (Wed, 02 Mar 2011)
New Revision: 788
Added:
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/PicketLinkSeamUtil.java
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/SecurityActions.java
Modified:
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/Configuration.java
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/SamlConfiguration.java
Log:
PLFED-155: use tccl as backup
Modified:
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/Configuration.java
===================================================================
---
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/Configuration.java 2011-03-01
19:35:51 UTC (rev 787)
+++
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/Configuration.java 2011-03-02
17:26:35 UTC (rev 788)
@@ -48,6 +48,7 @@
import org.picketlink.identity.federation.core.util.StringUtil;
import
org.picketlink.identity.seam.federation.jaxb.config.ExternalAuthenticationConfigType;
import org.picketlink.identity.seam.federation.jaxb.config.ServiceProviderType;
+import org.picketlink.identity.seam.federation.util.PicketLinkSeamUtil;
import org.xml.sax.SAXException;
/**
@@ -96,7 +97,7 @@
{
JAXBContext jaxbContext =
JAXBContext.newInstance("org.picketlink.identity.seam.federation.jaxb.config");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
- URL schemaURL =
getClass().getResource("/schema/config/external-authentication-config.xsd");
+ URL schemaURL = PicketLinkSeamUtil.loadResource(getClass(),
"/schema/config/external-authentication-config.xsd" );
Schema schema;
try
{
@@ -108,7 +109,7 @@
}
unmarshaller.setSchema(schema);
- JAXBElement<?> o = (JAXBElement<?>)
unmarshaller.unmarshal(getClass().getResource(CONFIGURATION_FILE));
+ JAXBElement<?> o = (JAXBElement<?>) unmarshaller.unmarshal(
PicketLinkSeamUtil.loadResource( getClass(), CONFIGURATION_FILE));
externalAuthenticationConfig = (ExternalAuthenticationConfigType) o.getValue();
}
catch (JAXBException e)
Modified:
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/SamlConfiguration.java
===================================================================
---
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/SamlConfiguration.java 2011-03-01
19:35:51 UTC (rev 787)
+++
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/configuration/SamlConfiguration.java 2011-03-02
17:26:35 UTC (rev 788)
@@ -46,6 +46,7 @@
import
org.picketlink.identity.federation.newmodel.saml.v2.metadata.IDPSSODescriptorType;
import org.picketlink.identity.seam.federation.jaxb.config.SamlConfigType;
import org.picketlink.identity.seam.federation.jaxb.config.SamlIdentityProviderType;
+import org.picketlink.identity.seam.federation.util.PicketLinkSeamUtil;
/**
@@ -136,7 +137,7 @@
{
try
{
- InputStream samlEntitiesStream = getClass().getResourceAsStream(
SAML_ENTITIES_FILE );
+ InputStream samlEntitiesStream = PicketLinkSeamUtil.loadResourceAsStream(
getClass(), SAML_ENTITIES_FILE );
if( samlEntitiesStream == null )
throw new RuntimeException( "SAML Entities File is missing" );
@@ -206,7 +207,7 @@
InputStream keyStoreStream;
if (keyStoreUrl.startsWith(classPathPrefix))
{
- keyStoreStream = getClass().getClassLoader().getResourceAsStream(
+ keyStoreStream = PicketLinkSeamUtil.loadResourceAsStream( getClass(),
keyStoreUrl.substring(classPathPrefix.length()));
}
else
Added:
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/PicketLinkSeamUtil.java
===================================================================
---
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/PicketLinkSeamUtil.java
(rev 0)
+++
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/PicketLinkSeamUtil.java 2011-03-02
17:26:35 UTC (rev 788)
@@ -0,0 +1,71 @@
+/*
+ * 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.picketlink.identity.seam.federation.util;
+
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Utility class
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Mar 2, 2011
+ */
+public class PicketLinkSeamUtil
+{
+ /**
+ * Get a resource first with the {@link ClassLoader}
+ * of the current class. If we do not find the resource,
+ * then we try with the Thread Context ClassLoader
+ * @param currentClass
+ * @param resource
+ * @return {@link InputStream} or null
+ */
+ public static InputStream loadResourceAsStream( Class<?> currentClass, String
resource )
+ {
+ InputStream is = null;
+ ClassLoader cl = SecurityActions.getClassLoader(currentClass);
+ if( cl != null )
+ is = cl.getResourceAsStream(resource);
+ if( is == null )
+ is = SecurityActions.getTCCL().getResourceAsStream(resource);
+ return is;
+ }
+
+ /**
+ * Get a resource first with the {@link ClassLoader}
+ * of the current class. If we do not find the resource,
+ * then we try with the Thread Context ClassLoader
+ * @param currentClass
+ * @param resource
+ * @return {@link URL} or null
+ */
+ public static URL loadResource( Class<?> currentClass, String resource )
+ {
+ URL url = null;
+ ClassLoader cl = SecurityActions.getClassLoader(currentClass);
+ if( cl != null )
+ url = cl.getResource(resource);
+ if( url == null )
+ url = SecurityActions.getTCCL().getResource(resource);
+ return url;
+ }
+}
\ No newline at end of file
Added:
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/SecurityActions.java
===================================================================
---
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/SecurityActions.java
(rev 0)
+++
picketlink-seam/trunk/picketlink-seam/src/main/java/org/picketlink/identity/seam/federation/util/SecurityActions.java 2011-03-02
17:26:35 UTC (rev 788)
@@ -0,0 +1,55 @@
+/*
+ * 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.picketlink.identity.seam.federation.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Privileged Actions
+ * @author Anil.Saldhana(a)redhat.com
+ * @since Mar 2, 2011
+ */
+public class SecurityActions
+{
+ static ClassLoader getClassLoader( final Class<?> clazz )
+ {
+ return AccessController.doPrivileged( new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+
+ static ClassLoader getTCCL()
+ {
+ return AccessController.doPrivileged( new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+}
\ No newline at end of file