[jboss-cvs] JBossAS SVN: r101083 - branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 17 12:00:09 EST 2010


Author: alessio.soldano at jboss.com
Date: 2010-02-17 12:00:08 -0500 (Wed, 17 Feb 2010)
New Revision: 101083

Added:
   branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/SecurityActions.java
Modified:
   branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentAspectDeployer.java
Log:
[JBWS-2895] Adding proper security actions class


Added: branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/SecurityActions.java
===================================================================
--- branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/SecurityActions.java	                        (rev 0)
+++ branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/SecurityActions.java	2010-02-17 17:00:08 UTC (rev 101083)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.webservices.integration.deployers;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * 
+ * @author alessio.soldano at jboss.com
+ * @since 17-Feb-2010
+ *
+ */
+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 classLoader the classloader
+    */
+   static void setContextClassLoader(final ClassLoader classLoader)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         Thread.currentThread().setContextClassLoader(classLoader);
+      }
+      else
+      {
+         AccessController.doPrivileged(new PrivilegedAction<Object>()
+         {
+            public Object run()
+            {
+               Thread.currentThread().setContextClassLoader(classLoader);
+               return null;
+            }
+         });
+      }
+   }
+
+}


Property changes on: branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/SecurityActions.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentAspectDeployer.java
===================================================================
--- branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentAspectDeployer.java	2010-02-17 16:59:15 UTC (rev 101082)
+++ branches/jaxrpc-cxf/webservices/src/main/java/org/jboss/webservices/integration/deployers/WSDeploymentAspectDeployer.java	2010-02-17 17:00:08 UTC (rev 101083)
@@ -106,17 +106,16 @@
          final Deployment dep = ASHelper.getRequiredAttachment(unit, Deployment.class);
          if (this.aspect.canHandle(dep))
          {
-            //TODO!! Use security action class
             //set the context classloader using the proper one from the deployment aspect
-            ClassLoader deployerClassLoader = Thread.currentThread().getContextClassLoader();
+            ClassLoader deployerClassLoader = SecurityActions.getContextClassLoader();
             try
             {
-               Thread.currentThread().setContextClassLoader(this.aspect.getLoader());
+               SecurityActions.setContextClassLoader(this.aspect.getLoader());
                this.aspect.start(dep);
             }
             finally
             {
-               Thread.currentThread().setContextClassLoader(deployerClassLoader);
+               SecurityActions.setContextClassLoader(deployerClassLoader);
             }
          }
       }
@@ -137,17 +136,16 @@
          final Deployment dep = ASHelper.getRequiredAttachment(unit, Deployment.class);
          if (this.aspect.canHandle(dep))
          {
-            //TODO!! Use security action class
             //set the context classloader using the proper one from the deployment aspect
-            ClassLoader deployerClassLoader = Thread.currentThread().getContextClassLoader();
+            ClassLoader deployerClassLoader = SecurityActions.getContextClassLoader();
             try
             {
-               Thread.currentThread().setContextClassLoader(this.aspect.getLoader());
+               SecurityActions.setContextClassLoader(this.aspect.getLoader());
                this.aspect.stop(dep);
             }
             finally
             {
-               Thread.currentThread().setContextClassLoader(deployerClassLoader);
+               SecurityActions.setContextClassLoader(deployerClassLoader);
             }
          }
       }




More information about the jboss-cvs-commits mailing list