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
--- /dev/null
+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;
+ }
+
+}
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;
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() {