class ContextExecutorService {

    public <T> Future<T> runWithContext(UUID contextUuid, final Callable<T> callable) {
        final SecurityContext context = SecurityContextHolder.getContext();
        // we are wrapping source callable in order to forward security context to a target thread.
        final Future<T> future = executor.submit(new Callable<T>() {
            @Override
            public T call() throws Exception {
                SecurityContextHolder.setContext(context);
                return callable.call();
            }
        });
        attachToContext(contextUuid, future);
        return future;
    }

}