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 (RuntimeException e
) {
22 } catch (Exception e
) {
23 throw new ArgeoException(
24 "Exception when running system authenticated task", e
);
28 public <T
> Future
<T
> submit(Callable
<T
> task
) {
29 FutureTask
<T
> future
= new FutureTask
<T
>(
30 wrapWithSystemAuthentication(task
));
35 protected <T
> Callable
<T
> wrapWithSystemAuthentication(
36 final Callable
<T
> runnable
) {
37 return new Callable
<T
>() {
39 public T
call() throws Exception
{
40 authenticateAsSystem();
42 return runnable
.call();
44 deauthenticateAsSystem();