Author: alessio.soldano(a)jboss.com
Date: 2009-06-20 20:54:08 -0400 (Sat, 20 Jun 2009)
New Revision: 10207
Added:
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/SecurityActions.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/SecurityActions.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/SecurityActions.java
spi/trunk/src/main/java/org/jboss/wsf/spi/util/SecurityActions.java
Modified:
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSConsume.java
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSProvide.java
spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
Log:
[JBWS-2668] Adding required privileged blocks
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/SecurityActions.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/SecurityActions.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/SecurityActions.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.wsf.spi.tools;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * Security actions for this package
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 19-Jun-2009
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Set context classloader.
+ *
+ * @param cl the classloader
+ * @return previous context classloader
+ * @throws Throwable for any error
+ */
+ static ClassLoader setContextClassLoader(final ClassLoader cl)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ ClassLoader result = Thread.currentThread().getContextClassLoader();
+ if (cl != null)
+ Thread.currentThread().setContextClassLoader(cl);
+ return result;
+ }
+ else
+ {
+ try
+ {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<ClassLoader>() {
+ public ClassLoader run() throws Exception
+ {
+ try
+ {
+ ClassLoader result =
Thread.currentThread().getContextClassLoader();
+ if (cl != null)
+ Thread.currentThread().setContextClassLoader(cl);
+ return result;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException("Error setting context
classloader", e);
+ }
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException("Error running privileged action",
e.getCause());
+ }
+ }
+ }
+}
Property changes on: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java 2009-06-19
16:36:27 UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractConsumer.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -52,7 +52,7 @@
*/
public static WSContractConsumer newInstance()
{
- return newInstance(Thread.currentThread().getContextClassLoader());
+ return newInstance(SecurityActions.getContextClassLoader());
}
/**
@@ -64,16 +64,16 @@
*/
public static WSContractConsumer newInstance(ClassLoader loader)
{
- ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader oldLoader = SecurityActions.getContextClassLoader();
try
{
- Thread.currentThread().setContextClassLoader(loader);
+ SecurityActions.setContextClassLoader(loader);
WSContractConsumerFactory factory = (WSContractConsumerFactory)
ServiceLoader.loadService(PROVIDER_PROPERTY, DEFAULT_PROVIDER);
return factory.createConsumer();
}
finally
{
- Thread.currentThread().setContextClassLoader(oldLoader);
+ SecurityActions.setContextClassLoader(oldLoader);
}
}
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java 2009-06-19
16:36:27 UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/WSContractProvider.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -67,7 +67,7 @@
*/
public static WSContractProvider newInstance()
{
- return newInstance(Thread.currentThread().getContextClassLoader());
+ return newInstance(SecurityActions.getContextClassLoader());
}
/**
@@ -79,16 +79,16 @@
*/
public static WSContractProvider newInstance(ClassLoader loader)
{
- ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader oldLoader = SecurityActions.getContextClassLoader();
try
{
- Thread.currentThread().setContextClassLoader(loader);
+ SecurityActions.setContextClassLoader(loader);
WSContractProviderFactory factory = (WSContractProviderFactory)
ServiceLoader.loadService(PROVIDER_PROPERTY, DEFAULT_PROVIDER);
return factory.createProvider(loader);
}
finally
{
- Thread.currentThread().setContextClassLoader(oldLoader);
+ SecurityActions.setContextClassLoader(oldLoader);
}
}
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/SecurityActions.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/SecurityActions.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/SecurityActions.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -0,0 +1,137 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.wsf.spi.tools.ant;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * Security actions for this package
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 19-Jun-2009
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Set context classloader.
+ *
+ * @param cl the classloader
+ * @return previous context classloader
+ * @throws Throwable for any error
+ */
+ static ClassLoader setContextClassLoader(final ClassLoader cl)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ ClassLoader result = Thread.currentThread().getContextClassLoader();
+ if (cl != null)
+ Thread.currentThread().setContextClassLoader(cl);
+ return result;
+ }
+ else
+ {
+ try
+ {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<ClassLoader>() {
+ public ClassLoader run() throws Exception
+ {
+ try
+ {
+ ClassLoader result =
Thread.currentThread().getContextClassLoader();
+ if (cl != null)
+ Thread.currentThread().setContextClassLoader(cl);
+ return result;
+ }
+ catch (Exception e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException("Error setting context
classloader", e);
+ }
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw new RuntimeException("Error running privileged action",
e.getCause());
+ }
+ }
+ }
+
+ /**
+ * Get classloader from class.
+ *
+ * @param clazz the class
+ * @return class's classloader
+ */
+ static ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return clazz.getClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+ }
+
+}
Property changes on:
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java 2009-06-19
16:36:27 UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSConsumeTask.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -23,7 +23,6 @@
import java.io.File;
import java.io.PrintStream;
-import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
@@ -183,9 +182,9 @@
public void executeNonForked()
{
- ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
- ClassLoader antLoader = this.getClass().getClassLoader();
- Thread.currentThread().setContextClassLoader(antLoader);
+ ClassLoader prevCL = SecurityActions.getContextClassLoader();
+ ClassLoader antLoader = SecurityActions.getClassLoader(this.getClass());
+ SecurityActions.setContextClassLoader(antLoader);
try
{
WSContractConsumer consumer = WSContractConsumer.newInstance();
@@ -226,7 +225,7 @@
}
finally
{
- Thread.currentThread().setContextClassLoader(prevCL);
+ SecurityActions.setContextClassLoader(prevCL);
}
}
@@ -243,7 +242,7 @@
private Path getTaskClassPath()
{
// Why is everything in the Ant API a big hack???
- ClassLoader cl = this.getClass().getClassLoader();
+ ClassLoader cl = SecurityActions.getClassLoader(this.getClass());
if (cl instanceof AntClassLoader)
{
return new Path(getProject(), ((AntClassLoader)cl).getClasspath());
@@ -256,7 +255,7 @@
{
// Why is everything in the Ant API a big hack???
List<String> strings = new ArrayList<String>();
- ClassLoader cl = this.getClass().getClassLoader();
+ ClassLoader cl = SecurityActions.getClassLoader(this.getClass());
if (cl instanceof AntClassLoader)
{
for (String string :
((AntClassLoader)cl).getClasspath().split(File.pathSeparator))
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java 2009-06-19
16:36:27 UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/ant/WSProvideTask.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -196,9 +196,9 @@
public void executeNonForked()
{
- ClassLoader prevCL = Thread.currentThread().getContextClassLoader();
- ClassLoader antLoader = this.getClass().getClassLoader();
- Thread.currentThread().setContextClassLoader(antLoader);
+ ClassLoader prevCL = SecurityActions.getContextClassLoader();
+ ClassLoader antLoader = SecurityActions.getClassLoader(this.getClass());
+ SecurityActions.setContextClassLoader(antLoader);
try
{
WSContractProvider gen = WSContractProvider.newInstance(
@@ -225,7 +225,7 @@
}
finally
{
- Thread.currentThread().setContextClassLoader(prevCL);
+ SecurityActions.setContextClassLoader(prevCL);
}
}
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/SecurityActions.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/SecurityActions.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/SecurityActions.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.wsf.spi.tools.cmd;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * Security actions for this package
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 19-Jun-2009
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Load a class using the provided classloader
+ *
+ * @param name
+ * @return
+ * @throws PrivilegedActionException
+ */
+ static Class<?> loadClass(final ClassLoader cl, final String name) throws
PrivilegedActionException, ClassNotFoundException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return cl.loadClass(name);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws PrivilegedActionException
+ {
+ try
+ {
+ return cl.loadClass(name);
+ }
+ catch (Exception e)
+ {
+ throw new PrivilegedActionException(e);
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Get a system property
+ *
+ * @param name
+ * @param defaultValue
+ * @return
+ */
+ static String getSystemProperty(final String name, final String defaultValue)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ else
+ {
+ PrivilegedAction<String> action = new PrivilegedAction<String>() {
+ public String run()
+ {
+ return System.getProperty(name, defaultValue);
+ }
+ };
+ return AccessController.doPrivileged(action);
+ }
+ }
+}
Property changes on:
spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSConsume.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSConsume.java 2009-06-19 16:36:27
UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSConsume.java 2009-06-21 00:54:08
UTC (rev 10207)
@@ -71,7 +71,7 @@
private File sourceDir = null;
private String target = null;
- public static final String PROGRAM_NAME = System.getProperty("program.name",
WSConsume.class.getName());
+ public static final String PROGRAM_NAME =
SecurityActions.getSystemProperty("program.name", WSConsume.class.getName());
public static void main(String[] args)
{
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSProvide.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSProvide.java 2009-06-19 16:36:27
UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/tools/cmd/WSProvide.java 2009-06-21 00:54:08
UTC (rev 10207)
@@ -62,12 +62,12 @@
private boolean quiet = false;
private boolean showTraces = false;
private boolean loadProvider = false;
- private ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ private ClassLoader loader = SecurityActions.getContextClassLoader();
private File outputDir = new File("output");
private File resourceDir = null;
private File sourceDir = null;
- public static final String PROGRAM_NAME = System.getProperty("program.name",
WSProvide.class.getSimpleName());
+ public static final String PROGRAM_NAME =
SecurityActions.getSystemProperty("program.name",
WSProvide.class.getSimpleName());
public static void main(String[] args)
{
@@ -158,9 +158,9 @@
{
try
{
- loader.loadClass(endpoint);
+ SecurityActions.loadClass(loader, endpoint);
}
- catch (ClassNotFoundException e)
+ catch (Exception e)
{
System.err.println("Error: Could not load class [" + endpoint +
"]. Did you specify a valid --classpath?");
return 1;
Added: spi/trunk/src/main/java/org/jboss/wsf/spi/util/SecurityActions.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/util/SecurityActions.java
(rev 0)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/util/SecurityActions.java 2009-06-21
00:54:08 UTC (rev 10207)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, 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.wsf.spi.util;
+
+import java.io.InputStream;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * Security actions for this package
+ *
+ * @author alessio.soldano(a)jboss.com
+ * @since 19-Jun-2009
+ *
+ */
+class SecurityActions
+{
+ /**
+ * Get context classloader.
+ *
+ * @return the current context classloader
+ */
+ static ClassLoader getContextClassLoader()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ /**
+ * Get resource as stream
+ *
+ * @param cl
+ * @param filename
+ * @return input stream
+ * @throws PrivilegedActionException
+ */
+ static InputStream getResourceAsStream(final ClassLoader cl, final String filename)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return cl.getResourceAsStream(filename);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<InputStream>()
{
+ public InputStream run()
+ {
+ return cl.getResourceAsStream(filename);
+ }
+ });
+ }
+ }
+
+ /**
+ * Load a class using the provided classloader
+ *
+ * @param name
+ * @return
+ * @throws PrivilegedActionException
+ */
+ static Class<?> loadClass(final ClassLoader cl, final String name) throws
PrivilegedActionException, ClassNotFoundException
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ {
+ return cl.loadClass(name);
+ }
+ else
+ {
+ return AccessController.doPrivileged(new
PrivilegedExceptionAction<Class<?>>() {
+ public Class<?> run() throws PrivilegedActionException
+ {
+ try
+ {
+ return cl.loadClass(name);
+ }
+ catch (Exception e)
+ {
+ throw new PrivilegedActionException(e);
+ }
+ }
+ });
+ }
+ }
+}
Property changes on: spi/trunk/src/main/java/org/jboss/wsf/spi/util/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java
===================================================================
--- spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java 2009-06-19 16:36:27
UTC (rev 10206)
+++ spi/trunk/src/main/java/org/jboss/wsf/spi/util/ServiceLoader.java 2009-06-21 00:54:08
UTC (rev 10207)
@@ -35,6 +35,7 @@
* Load a service class using this ordered lookup procedure
*
* @author Thomas.Diesler(a)jboss.com
+ * @author alessio.soldano(a)jboss.com
* @since 14-Dec-2006
*/
public abstract class ServiceLoader
@@ -74,11 +75,11 @@
{
Object factory = null;
String factoryName = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = SecurityActions.getContextClassLoader();
// Use the Services API (as detailed in the JAR specification), if available, to
determine the classname.
String filename = "META-INF/services/" + propertyName;
- InputStream inStream = loader.getResourceAsStream(filename);
+ InputStream inStream = SecurityActions.getResourceAsStream(loader, filename);
if (inStream != null)
{
try
@@ -88,7 +89,7 @@
br.close();
if (factoryName != null)
{
- Class factoryClass = loader.loadClass(factoryName);
+ Class factoryClass = SecurityActions.loadClass(loader, factoryName);
factory = factoryClass.newInstance();
}
}
@@ -112,7 +113,7 @@
public static Object loadFromSystemProperty(String propertyName, String
defaultFactory)
{
Object factory = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = SecurityActions.getContextClassLoader();
PrivilegedAction action = new PropertyAccessAction(propertyName);
String factoryName = (String)AccessController.doPrivileged(action);
@@ -121,7 +122,7 @@
try
{
//if(log.isDebugEnabled()) log.debug("Load from system property: "
+ factoryName);
- Class factoryClass = loader.loadClass(factoryName);
+ Class factoryClass = SecurityActions.loadClass(loader, factoryName);
factory = factoryClass.newInstance();
}
catch (Throwable t)
@@ -148,14 +149,14 @@
{
Object factory = null;
String factoryName = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = SecurityActions.getContextClassLoader();
// Use the properties file "lib/jaxm.properties" in the JRE directory.
// This configuration file is in standard java.util.Properties format and contains
the fully qualified name of the implementation class with the key being the system
property defined above.
PrivilegedAction action = new PropertyAccessAction("java.home");
String javaHome = (String)AccessController.doPrivileged(action);
File jaxmFile = new File(javaHome + "/lib/jaxws.properties");
- if (jaxmFile.exists())
+ if ((Boolean)AccessController.doPrivileged(new PropertyFileExistAction(jaxmFile)))
{
try
{
@@ -165,7 +166,7 @@
if (factoryName != null)
{
//if(log.isDebugEnabled()) log.debug("Load from " + jaxmFile +
": " + factoryName);
- Class factoryClass = loader.loadClass(factoryName);
+ Class<?> factoryClass = SecurityActions.loadClass(loader,
factoryName);
factory = factoryClass.newInstance();
}
}
@@ -187,7 +188,7 @@
private static Object loadDefault(String defaultFactory)
{
Object factory = null;
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = SecurityActions.getContextClassLoader();
// Use the default factory implementation class.
if (defaultFactory != null)
@@ -195,7 +196,7 @@
try
{
//if(log.isDebugEnabled()) log.debug("Load from default: " +
factoryName);
- Class factoryClass = loader.loadClass(defaultFactory);
+ Class factoryClass = SecurityActions.loadClass(loader, defaultFactory);
factory = factoryClass.newInstance();
}
catch (Throwable t)
@@ -255,4 +256,19 @@
}
}
}
+
+ private static class PropertyFileExistAction implements PrivilegedAction
+ {
+ private File file;
+
+ PropertyFileExistAction(File file)
+ {
+ this.file = file;
+ }
+
+ public Object run()
+ {
+ return file.exists();
+ }
+ }
}