Introduce AsyncSystemTaskExecutor
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 14 Apr 2011 16:27:29 +0000 (16:27 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 14 Apr 2011 16:27:29 +0000 (16:27 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4433 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/SystemExecutionService.java
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/AsyncSystemTaskExecutor.java [new file with mode: 0644]
security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java

index eba5d49d9a1794de14bc0d1b6c4badf5fba689d2..b67eb27b1446bad9275e11b2ff103f555c518052 100644 (file)
@@ -2,17 +2,13 @@ package org.argeo.security;
 
 import java.util.concurrent.Executor;
 
-import org.springframework.core.task.TaskExecutor;
-
 /**
  * Allows to execute code authenticated as a system user (that is not a real
  * person). The {@link Executor} interface interface is not used directly in
  * order to allow future extension of this interface and to simplify its
- * publication (e.g. as an OSGi service) and interception. Support for Spring's
- * {@link TaskExecutor} will be dropped when upgrading to Spring 3, since it is
- * only to ensure compatibility with versions of Java before 1.5.
+ * publication (e.g. as an OSGi service) and interception.
  */
-public interface SystemExecutionService extends Executor, TaskExecutor {
+public interface SystemExecutionService extends Executor {
        /**
         * Executes this Runnable within a system authenticated context.
         * Implementations should make sure that this method is properly secured via
diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/AsyncSystemTaskExecutor.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/AsyncSystemTaskExecutor.java
new file mode 100644 (file)
index 0000000..d6dff46
--- /dev/null
@@ -0,0 +1,40 @@
+package org.argeo.security.core;
+
+import org.argeo.security.SystemExecutionService;
+import org.springframework.core.task.SimpleAsyncTaskExecutor;
+
+/**
+ * Asynchronous Spring TaskExecutor (for use in JMS for example) wrapping a
+ * {@link SystemExecutionService}.
+ */
+public class AsyncSystemTaskExecutor extends SimpleAsyncTaskExecutor {
+       private static final long serialVersionUID = -8035527542087963068L;
+
+       private SystemExecutionService systemExecutionService;
+
+       public AsyncSystemTaskExecutor() {
+               super();
+       }
+
+       public AsyncSystemTaskExecutor(String threadNamePrefix) {
+               super(threadNamePrefix);
+       }
+
+       @Override
+       public Thread createThread(final Runnable runnable) {
+               Runnable systemExecutionRunnable = new Runnable() {
+
+                       public void run() {
+                               systemExecutionService.execute(runnable);
+
+                       }
+               };
+               return super.createThread(systemExecutionRunnable);
+       }
+
+       public void setSystemExecutionService(
+                       SystemExecutionService systemExecutionService) {
+               this.systemExecutionService = systemExecutionService;
+       }
+
+}
index 3235a9602bdad53f8aed8dcfe05765644353fdf1..3923715155dcd314a974984b7ec6d87f5a5750a2 100644 (file)
@@ -6,15 +6,16 @@ import javax.security.auth.Subject;
 
 import org.argeo.ArgeoException;
 import org.argeo.security.SystemExecutionService;
-import org.springframework.core.task.SimpleAsyncTaskExecutor;
-import org.springframework.core.task.TaskExecutor;
 import org.springframework.security.Authentication;
 import org.springframework.security.AuthenticationManager;
 import org.springframework.security.context.SecurityContext;
 import org.springframework.security.context.SecurityContextHolder;
 
-public class KeyBasedSystemExecutionService implements SystemExecutionService,
-               TaskExecutor {
+/**
+ * Implementation of a {@link SystemExecutionService} using a key-based
+ * {@link InternalAuthentication}
+ */
+public class KeyBasedSystemExecutionService implements SystemExecutionService {
        private AuthenticationManager authenticationManager;
        private String systemAuthenticationKey;
 
@@ -22,19 +23,6 @@ public class KeyBasedSystemExecutionService implements SystemExecutionService,
                wrapWithSystemAuthentication(runnable).run();
        }
 
-       public TaskExecutor createSystemAuthenticatedTaskExecutor() {
-               return new SimpleAsyncTaskExecutor() {
-                       private static final long serialVersionUID = -8126773862193265020L;
-
-                       @Override
-                       public Thread createThread(Runnable runnable) {
-                               return super
-                                               .createThread(wrapWithSystemAuthentication(runnable));
-                       }
-
-               };
-       }
-
        protected Runnable wrapWithSystemAuthentication(final Runnable runnable) {
                return new Runnable() {