1 package org
.argeo
.security
.core
;
3 import java
.util
.concurrent
.Callable
;
4 import java
.util
.concurrent
.Executors
;
5 import java
.util
.concurrent
.Future
;
6 import java
.util
.concurrent
.FutureTask
;
8 import org
.argeo
.ArgeoException
;
9 import org
.argeo
.security
.SystemExecutionService
;
12 * Implementation of a {@link SystemExecutionService} using a key-based
13 * {@link InternalAuthentication}
15 public class KeyBasedSystemExecutionService
extends AbstractSystemExecution
16 implements SystemExecutionService
{
17 public void execute(Runnable runnable
) {
19 wrapWithSystemAuthentication(Executors
.callable(runnable
)).call();
20 } catch (Exception e
) {
21 throw new ArgeoException(
22 "Exception when running system authenticated task", e
);
26 public <T
> Future
<T
> submit(Callable
<T
> task
) {
27 FutureTask
<T
> future
= new FutureTask
<T
>(
28 wrapWithSystemAuthentication(task
));
33 protected <T
> Callable
<T
> wrapWithSystemAuthentication(
34 final Callable
<T
> runnable
) {
35 return new Callable
<T
>() {
37 public T
call() throws Exception
{
38 authenticateAsSystem();
40 return runnable
.call();
42 deauthenticateAsSystem();