2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
.core
;
18 import java
.util
.concurrent
.Callable
;
19 import java
.util
.concurrent
.Executors
;
20 import java
.util
.concurrent
.Future
;
21 import java
.util
.concurrent
.FutureTask
;
23 import org
.argeo
.ArgeoException
;
24 import org
.argeo
.security
.SystemExecutionService
;
27 * Implementation of a {@link SystemExecutionService} using a key-based
28 * {@link InternalAuthentication}
30 public class KeyBasedSystemExecutionService
extends AbstractSystemExecution
31 implements SystemExecutionService
{
32 public void execute(Runnable runnable
) {
34 wrapWithSystemAuthentication(Executors
.callable(runnable
)).call();
35 } catch (RuntimeException e
) {
37 } catch (Exception e
) {
38 throw new ArgeoException(
39 "Exception when running system authenticated task", e
);
43 public <T
> Future
<T
> submit(Callable
<T
> task
) {
44 FutureTask
<T
> future
= new FutureTask
<T
>(
45 wrapWithSystemAuthentication(task
));
50 protected <T
> Callable
<T
> wrapWithSystemAuthentication(
51 final Callable
<T
> runnable
) {
52 return new Callable
<T
>() {
54 public T
call() throws Exception
{
55 authenticateAsSystem();
57 return runnable
.call();
59 // deauthenticateAsSystem();