From 44f3f677b3b9083bc38ad14a822c05200cc6c7b1 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Thu, 14 Apr 2011 16:27:29 +0000 Subject: [PATCH] Introduce AsyncSystemTaskExecutor git-svn-id: https://svn.argeo.org/commons/trunk@4433 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../security/SystemExecutionService.java | 8 +--- .../core/AsyncSystemTaskExecutor.java | 40 +++++++++++++++++++ .../core/KeyBasedSystemExecutionService.java | 22 +++------- 3 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/AsyncSystemTaskExecutor.java diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/SystemExecutionService.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/SystemExecutionService.java index eba5d49d9..b67eb27b1 100644 --- a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/SystemExecutionService.java +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/SystemExecutionService.java @@ -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 index 000000000..d6dff46e0 --- /dev/null +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/AsyncSystemTaskExecutor.java @@ -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; + } + +} diff --git a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java index 3235a9602..392371515 100644 --- a/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java +++ b/security/runtime/org.argeo.security.core/src/main/java/org/argeo/security/core/KeyBasedSystemExecutionService.java @@ -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() { -- 2.30.2