[jboss-cvs] JBoss Messaging SVN: r5366 - in branches/Branch_1_4: src/main/org/jboss/jms/client and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 14 16:46:28 EST 2008
Author: clebert.suconic at jboss.com
Date: 2008-11-14 16:46:28 -0500 (Fri, 14 Nov 2008)
New Revision: 5366
Added:
branches/Branch_1_4/src/main/org/jboss/jms/client/SecurityActions.java
branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/SecurityActions.java
branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SecurityActions.java
branches/Branch_1_4/src/main/org/jboss/messaging/util/SecurityActions.java
Modified:
branches/Branch_1_4/build-thirdparty-AS5.xml
branches/Branch_1_4/src/main/org/jboss/jms/client/ClientAOPStackLoader.java
branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java
branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/SecurityActions.java
branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SerializedPacket.java
branches/Branch_1_4/src/main/org/jboss/messaging/util/JBMExecutor.java
branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
branches/Branch_1_4/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java
Log:
JBMESSAGING-1446, JBMESSAGING-1447, JBMESSAGING-1448 and JBMESSAGING-1453
setting various setTCL and getTCL and other actions under security blocks
and
also upgrading JGroups to the latest 2.6.7 with JGRP-855
Modified: branches/Branch_1_4/build-thirdparty-AS5.xml
===================================================================
--- branches/Branch_1_4/build-thirdparty-AS5.xml 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/build-thirdparty-AS5.xml 2008-11-14 21:46:28 UTC (rev 5366)
@@ -85,7 +85,7 @@
<componentref name="oswego-concurrent" version="1.3.4-jboss-update1"/>
<componentref name="apache-log4j" version="1.2.14"/>
<componentref name="javassist" version="3.9.0.GA"/>
- <componentref name="jgroups" version="snapshot"/>
+ <componentref name="jgroups" version="2.6.7.GA"/>
<componentref name="trove" version="1.0.2"/>
<componentref name="jboss/common-core" version="2.2.8.GA"/>
<componentref name="jboss/common-logging-jdk" version="2.0.2.GA"/>
Modified: branches/Branch_1_4/src/main/org/jboss/jms/client/ClientAOPStackLoader.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/ClientAOPStackLoader.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/ClientAOPStackLoader.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -64,13 +64,13 @@
return;
}
- ClassLoader savedLoader = Thread.currentThread().getContextClassLoader();
+ ClassLoader savedLoader = SecurityActions.getTCL();
try
{
// This was done because of some weird behavior of AOP & classLoading
// http://jira.jboss.org/jira/browse/JBMESSAGING-980
- Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ SecurityActions.setTCL(this.getClass().getClassLoader());
byte[] clientAOPStack = delegate.getClientAOPStack();
@@ -80,7 +80,7 @@
}
finally
{
- Thread.currentThread().setContextClassLoader(savedLoader);
+ SecurityActions.setTCL(savedLoader);
}
}
Added: branches/Branch_1_4/src/main/org/jboss/jms/client/SecurityActions.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/client/SecurityActions.java (rev 0)
+++ branches/Branch_1_4/src/main/org/jboss/jms/client/SecurityActions.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.jms.client;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * A SecurityActions
+ *
+ * SecurityActions need to be on each package because of configuration issues on the Security Manager
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ * Created Nov 14, 2008 1:50:58 PM
+ *
+ *
+ */
+class SecurityActions
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ static ClassLoader getTCL()
+ {
+ if (System.getSecurityManager() != null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ static void setTCL(final ClassLoader tcl)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ return null;
+ }
+ });
+ }
+ }
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/ConnectionFactory.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -21,6 +21,8 @@
import org.jboss.system.ServiceMBeanSupport;
import org.w3c.dom.Element;
+
+
/**
* A deployable JBoss Messaging connection factory.
*
@@ -394,7 +396,7 @@
}
//We don't use Class.forName() since then it won't work with scoped deployments
- Class clz = Thread.currentThread().getContextClassLoader().loadClass(factoryName);
+ Class clz = SecurityActions.getTCL().loadClass(factoryName);
loadBalancingFactory = (LoadBalancingFactory)clz.newInstance();
}
Added: branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/SecurityActions.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/SecurityActions.java (rev 0)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/connectionfactory/SecurityActions.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt 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.jms.server.connectionfactory;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * A SecurityActions
+ *
+ * SecurityActions need to be on each package because of configuration issues on the Security Manager
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ * Created Nov 14, 2008 1:50:58 PM
+ *
+ *
+ */
+class SecurityActions
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ static ClassLoader getTCL()
+ {
+ if (System.getSecurityManager() != null)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ else
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ }
+
+ static ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+
+ }
+ else
+ {
+ return clazz.getClassLoader();
+ }
+
+ }
+
+ static void setTCL(final ClassLoader tcl)
+ {
+ if (System.getSecurityManager() != null)
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ return null;
+ }
+ });
+ }
+ else
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ }
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/SecurityActions.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/SecurityActions.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/SecurityActions.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -29,7 +29,6 @@
import org.jboss.security.SecurityAssociation;
-
/** A collection of privileged actions for this package
* @author Scott.Stark at jboss.org
* @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
@@ -43,45 +42,40 @@
{
PrincipalInfoAction PRIVILEGED = new PrincipalInfoAction()
{
- public void push(final Principal principal, final Object credential,
- final Subject subject)
+ public void push(final Principal principal, final Object credential, final Subject subject)
{
- AccessController.doPrivileged(
- new PrivilegedAction()
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
{
- public Object run()
- {
- SecurityAssociation.pushSubjectContext(subject, principal, credential);
- return null;
- }
+ SecurityAssociation.pushSubjectContext(subject, principal, credential);
+ return null;
}
- );
+ });
}
+
public void dup()
{
- AccessController.doPrivileged(
- new PrivilegedAction()
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
{
- public Object run()
- {
- SecurityAssociation.dupSubjectContext();
- return null;
- }
+ SecurityAssociation.dupSubjectContext();
+ return null;
}
- );
+ });
}
+
public void pop()
{
- AccessController.doPrivileged(
- new PrivilegedAction()
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
{
- public Object run()
- {
- SecurityAssociation.popSubjectContext();
- return null;
- }
+ SecurityAssociation.popSubjectContext();
+ return null;
}
- );
+ });
}
};
@@ -91,10 +85,12 @@
{
SecurityAssociation.pushSubjectContext(subject, principal, credential);
}
+
public void dup()
{
SecurityAssociation.dupSubjectContext();
}
+
public void pop()
{
SecurityAssociation.popSubjectContext();
@@ -102,14 +98,15 @@
};
void push(Principal principal, Object credential, Subject subject);
+
void dup();
+
void pop();
}
- static void pushSubjectContext(Principal principal, Object credential,
- Subject subject)
+ static void pushSubjectContext(Principal principal, Object credential, Subject subject)
{
- if(System.getSecurityManager() == null)
+ if (System.getSecurityManager() == null)
{
PrincipalInfoAction.NON_PRIVILEGED.push(principal, credential, subject);
}
@@ -118,10 +115,10 @@
PrincipalInfoAction.PRIVILEGED.push(principal, credential, subject);
}
}
-
+
static void popSubjectContext()
{
- if(System.getSecurityManager() == null)
+ if (System.getSecurityManager() == null)
{
PrincipalInfoAction.NON_PRIVILEGED.pop();
}
@@ -130,4 +127,61 @@
PrincipalInfoAction.PRIVILEGED.pop();
}
}
- }
+
+ static ClassLoader getTCL()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ static ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return clazz.getClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+
+ }
+
+ static void setTCL(final ClassLoader tcl)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ return null;
+ }
+ });
+ }
+ }
+
+}
Modified: branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -21,7 +21,10 @@
*/
package org.jboss.jms.server.endpoint;
-import java.util.List;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Map;
import java.util.Set;
@@ -44,6 +47,7 @@
import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
+import org.jboss.security.SecurityAssociation;
/**
* Concrete implementation of ConnectionFactoryEndpoint
@@ -209,12 +213,12 @@
* failover. Negative values are ignored (mean regular connection creation attempt).
*/
private ClientConnectionDelegate
- createConnectionDelegateInternal(String username,
- String password,
- int failedNodeID,
- String remotingSessionID, String clientVMID,
- byte versionToUse,
- ServerInvokerCallbackHandler callbackHandler)
+ createConnectionDelegateInternal(final String username,
+ final String password,
+ final int failedNodeID,
+ final String remotingSessionID, final String clientVMID,
+ final byte versionToUse,
+ final ServerInvokerCallbackHandler callbackHandler)
throws Exception
{
log.trace("creating a new connection for user " + username);
@@ -224,7 +228,28 @@
// up thread local immediately after we used the information, otherwise some other people
// security my be screwed up, on account of thread local security stack being corrupted.
- serverPeer.getSecurityManager().authenticate(username, password);
+ if (System.getSecurityManager() == null)
+ {
+ serverPeer.getSecurityManager().authenticate(username, password);
+ }
+ else
+ {
+ try
+ {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ serverPeer.getSecurityManager().authenticate(username, password);
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException pe)
+ {
+ throw pe.getException();
+ }
+ }
// We don't need the SubjectContext on thread local anymore, clean it up
SecurityActions.popSubjectContext();
Added: branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SecurityActions.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SecurityActions.java (rev 0)
+++ branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SecurityActions.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.jms.wireformat;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/** A collection of privileged actions for this package
+ * @author Clebert Suconic
+ */
+class SecurityActions
+{
+ static ClassLoader getTCL()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ static ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return clazz.getClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+
+ }
+
+ static void setTCL(final ClassLoader tcl)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ return null;
+ }
+ });
+ }
+ }
+
+}
Modified: branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SerializedPacket.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SerializedPacket.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/jms/wireformat/SerializedPacket.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -28,6 +28,7 @@
import org.jboss.remoting.loading.ObjectInputStreamWithClassLoader;
+
/**
* For carrying a remoting non JBM invocation across the wire. Also used for internal invocation
* request return values e.g. PONG. This would be used for pings, disconnect, addlistener,
@@ -67,7 +68,7 @@
// need to use the thread context class loader, otherwise deserialization of various
// remoting and messaging things will fail in a scoped domain
ObjectInputStream ois =
- new ObjectInputStreamWithClassLoader(is, Thread.currentThread().getContextClassLoader());
+ new ObjectInputStreamWithClassLoader(is, SecurityActions.getTCL());
payload = ois.readObject();
}
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/util/JBMExecutor.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/util/JBMExecutor.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/util/JBMExecutor.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -22,10 +22,6 @@
package org.jboss.messaging.util;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-
/** Any Executor being used on client side has to clean its contextClassLoader, as that could cause leaks.
* This class encapsulates the necessary cleanup to avoid that leak.
*
@@ -51,7 +47,7 @@
private boolean needToSetClassLoader = true;
- public JBMExecutor(String name)
+ public JBMExecutor(final String name)
{
super(name);
}
@@ -59,22 +55,15 @@
class TCLRunnable implements Runnable
{
- private Runnable realRunnable;
+ private final Runnable realRunnable;
+
private ClassLoader tcl;
- public TCLRunnable(Runnable realRunnable)
+ public TCLRunnable(final Runnable realRunnable)
{
if (needToSetClassLoader)
{
- tcl = AccessController.doPrivileged(
- new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- }
- );
+ tcl = SecurityActions.getTCL();
}
this.realRunnable = realRunnable;
@@ -86,52 +75,44 @@
if (needToSetClassLoader)
{
needToSetClassLoader = false;
-
- AccessController.doPrivileged(
- new PrivilegedAction()
- {
- public Object run()
- {
- Thread.currentThread().setContextClassLoader(tcl);
- return null;
- }
- }
- );
+ SecurityActions.setTCL(tcl);
}
realRunnable.run();
}
}
-
- public void execute(Runnable runnable) throws InterruptedException
+ @Override
+ public void execute(final Runnable runnable) throws InterruptedException
{
super.execute(new TCLRunnable(runnable));
}
-
+
public void clearClassLoader() throws InterruptedException
{
super.execute(new Runnable()
- {
- @SuppressWarnings("unchecked")
- public void run()
- {
- needToSetClassLoader = true;
- }
- });
-
+ {
+ @SuppressWarnings("unchecked")
+ public void run()
+ {
+ needToSetClassLoader = true;
+ }
+ });
+
}
-
public void clearAllExceptCurrentTask()
{
try
{
- while (queue_.poll(0) != null);
+ while (queue_.poll(0) != null)
+ {
+ ;
+ }
}
catch (InterruptedException ex)
{
- Thread.currentThread().interrupt();
+ Thread.currentThread().interrupt();
}
}
-
+
}
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/util/ObjectInputStreamWithClassLoader.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -59,7 +59,7 @@
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
{
String name = desc.getName();
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ ClassLoader loader = SecurityActions.getTCL();
try
{
Class clazz = loader.loadClass(name);
Modified: branches/Branch_1_4/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java 2008-11-14 17:44:40 UTC (rev 5365)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/util/OrderedExecutorFactory.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -22,8 +22,6 @@
package org.jboss.messaging.util;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
@@ -80,13 +78,7 @@
{
if (needToSetClassLoader)
{
- tcl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
- {
- public ClassLoader run()
- {
- return Thread.currentThread().getContextClassLoader();
- }
- });
+ tcl = SecurityActions.getTCL();
}
synchronized (tasks)
{
@@ -108,14 +100,8 @@
{
needToSetClassLoader = false;
- AccessController.doPrivileged(new PrivilegedAction()
- {
- public Object run()
- {
- Thread.currentThread().setContextClassLoader(tcl);
- return null;
- }
- });
+ SecurityActions.setTCL(tcl);
+
}
for (;;)
Added: branches/Branch_1_4/src/main/org/jboss/messaging/util/SecurityActions.java
===================================================================
--- branches/Branch_1_4/src/main/org/jboss/messaging/util/SecurityActions.java (rev 0)
+++ branches/Branch_1_4/src/main/org/jboss/messaging/util/SecurityActions.java 2008-11-14 21:46:28 UTC (rev 5366)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.messaging.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/** A collection of privileged actions for this package
+ * @author Clebert Suconic
+ */
+class SecurityActions
+{
+ static ClassLoader getTCL()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+
+ static ClassLoader getClassLoader(final Class<?> clazz)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return clazz.getClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return clazz.getClassLoader();
+ }
+ });
+ }
+
+ }
+
+ static void setTCL(final ClassLoader tcl)
+ {
+ if (System.getSecurityManager() == null)
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ }
+ else
+ {
+ AccessController.doPrivileged(new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ Thread.currentThread().setContextClassLoader(tcl);
+ return null;
+ }
+ });
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list