org.springframework.security.concurrent.DelegatingSecurityContextExecutorService Java Examples

The following examples show how to use org.springframework.security.concurrent.DelegatingSecurityContextExecutorService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkConsumerJobImpl.java    From telekom-workflow-engine with MIT License 6 votes vote down vote up
@Override
public synchronized void start(){
    isStopping.set( false );

    // number of parallel consumer threads
    int numberOfConsumerThreads = config.getNumberOfConsumerThreads();

    // spring security context for executor threads
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    securityContext.setAuthentication(new UsernamePasswordAuthenticationToken("workflow-engine", "[not-used]", AuthorityUtils.createAuthorityList("ROLE_WORKFLOW_ENGINE")));

    // actual executor thread pool
    ExecutorService delegateExecutorService = Executors.newFixedThreadPool( numberOfConsumerThreads, new NamedPoolThreadFactory( "consumer" ) );
    // wrapper executor service that sets the security context for each thread
    executorService = new DelegatingSecurityContextExecutorService(delegateExecutorService, securityContext);

    // start the consuming jobs
    for( int i = 0; i < numberOfConsumerThreads; i++ ){
        executorService.execute( new ConsumerRunnable() );
    }
    log.info( "Scheduled {} consumers", numberOfConsumerThreads );
}
 
Example #2
Source File: ExecutorBeanPostProcessorTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_use_jdk_proxy_when_executor_service_has_final_methods()
		throws Exception {
	ExecutorBeanPostProcessor beanPostProcessor = new ExecutorBeanPostProcessor(
			this.beanFactory);
	ExecutorService executorService = new DelegatingSecurityContextExecutorService(
			Executors.newSingleThreadExecutor());
	ExecutorService wrappedExecutor = (ExecutorService) beanPostProcessor
			.postProcessAfterInitialization(executorService, "executorService");

	then(AopUtils.isJdkDynamicProxy(wrappedExecutor)).isTrue();
	then(AopUtils.isCglibProxy(wrappedExecutor)).isFalse();
	then(wrappedExecutor.submit(() -> "done").get()).isEqualTo("done");
	wrappedExecutor.shutdownNow();
}
 
Example #3
Source File: TestConfiguration.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Bean
Executor asyncExecutor() {
    return new DelegatingSecurityContextExecutorService(Executors.newSingleThreadExecutor());
}
 
Example #4
Source File: ExecutorAutoConfiguration.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @return ExecutorService with security context availability in thread
 *         execution.
 */
@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean
public ExecutorService asyncExecutor() {
    return new DelegatingSecurityContextExecutorService(threadPoolExecutor());
}
 
Example #5
Source File: AmqpTestConfiguration.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Bean
Executor asyncExecutor() {
    return new DelegatingSecurityContextExecutorService(Executors.newSingleThreadExecutor());
}