[jboss-cvs] JBossAS SVN: r82769 - in projects/ejb3/trunk/common: src/main/java/org/jboss/ejb3/common/proxy/plugins/async and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 12 08:16:48 EST 2009


Author: wolfc
Date: 2009-01-12 08:16:47 -0500 (Mon, 12 Jan 2009)
New Revision: 82769

Added:
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/SecurityActions.java
Modified:
   projects/ejb3/trunk/common/pom.xml
   projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java
Log:
EJBTHREE-1682: propagate security context

Modified: projects/ejb3/trunk/common/pom.xml
===================================================================
--- projects/ejb3/trunk/common/pom.xml	2009-01-12 12:48:47 UTC (rev 82768)
+++ projects/ejb3/trunk/common/pom.xml	2009-01-12 13:16:47 UTC (rev 82769)
@@ -92,6 +92,12 @@
     </dependency>
  
     <dependency>
+      <groupId>org.jboss.security</groupId>
+      <artifactId>jboss-security-spi</artifactId>
+      <version>2.0.2.SP1</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.jboss.deployers</groupId>
       <artifactId>jboss-deployers-spi</artifactId>
     </dependency>

Modified: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java	2009-01-12 12:48:47 UTC (rev 82768)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/AsyncProcessor.java	2009-01-12 13:16:47 UTC (rev 82769)
@@ -30,6 +30,7 @@
 
 import org.jboss.ejb3.common.proxy.spi.ChainableProcessor;
 import org.jboss.ejb3.common.proxy.spi.ChainedProcessingInvocationHandler;
+import org.jboss.security.SecurityContext;
 
 /**
  * AsyncProcessor
@@ -88,8 +89,10 @@
       // Get the delegate
       Object delegate = chain.getDelegate();
 
+      SecurityContext sc = SecurityActions.getSecurityContext();
+      
       // Construct the async call
-      Callable<Object> asyncInvocation = new AsyncTask(delegate, method, args);
+      Callable<Object> asyncInvocation = new AsyncTask(delegate, method, args, sc);
 
       // Invoke as async
       Future<Object> asyncResult = EXECUTOR.submit(asyncInvocation);
@@ -151,18 +154,28 @@
 
       private Object args[];
 
-      public AsyncTask(Object proxy, Method method, Object[] args)
+      /** Optional security context */
+      private SecurityContext sc;
+      
+      public AsyncTask(Object proxy, Method method, Object[] args, SecurityContext sc)
       {
          this.proxy = proxy;
          this.method = method;
          this.args = args;
+         this.sc = sc;
       }
 
       public Object call() throws Exception
       {
          // Invoke upon the proxy
+         SecurityContext prevSC = null;
          try
          {
+            if(sc != null)
+            {
+               prevSC = SecurityActions.getSecurityContext();
+               SecurityActions.setSecurityContext(sc);
+            }
             return method.invoke(proxy, args);
          }
          catch(InvocationTargetException e)
@@ -176,6 +189,11 @@
          {
             throw new Exception("Exception encountered in Asynchronous Invocation", t);
          }
+         finally
+         {
+            if(sc != null)
+               SecurityActions.setSecurityContext(prevSC);
+         }
       }
    }
 

Added: projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/SecurityActions.java
===================================================================
--- projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/SecurityActions.java	                        (rev 0)
+++ projects/ejb3/trunk/common/src/main/java/org/jboss/ejb3/common/proxy/plugins/async/SecurityActions.java	2009-01-12 13:16:47 UTC (rev 82769)
@@ -0,0 +1,56 @@
+/*
+ * 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.ejb3.common.proxy.plugins.async;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextAssociation;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+class SecurityActions
+{
+   static SecurityContext getSecurityContext()
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<SecurityContext>() {
+         public SecurityContext run()
+         {
+            return SecurityContextAssociation.getSecurityContext();
+         }
+      });
+   }
+   
+   static void setSecurityContext(final SecurityContext sc)
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Void>() {
+         public Void run()
+         {
+            SecurityContextAssociation.setSecurityContext(sc);
+            return null;
+         }
+      });
+   }
+}




More information about the jboss-cvs-commits mailing list