-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DelegatingSecurityContextTaskExecutor / DelegatingSecurityContextRunnable / DelegatingSecurityContextCallable should provide extension points #14911
Comments
@tkrah, thanks for the suggestion.
Executor base = ExecutorService...
TaskExecutor executor = new TaskExecutorAdapter(base);
executor.setTaskDecorator((runnable) -> {
// ... do additional tasks
runnable.run();
// ... do clean up
});
DelegatingSecurityContextTaskExecutor security = new DelegatingSecurityContextTaskExceutor(executor); Does that meet your needs? |
Hi, that's a nice suggestion, totally did miss that. But I also use the DelegatingSecurityContextCallable and Runnable classes as a wrapper for a custom ForkJoinPool to wrap submitted tasks there too, the TaskDecorator does not help here - any idea how to handle this with the current code or does those need some actual work to reuse them there too? |
If you already have a custom // ...
@Override
public void execute(Runnable task) {
// ... do additional tasks
task.run();
// ... do clean up
}
// ... perhaps you could reuse the // ...
@Override
public void execute(Runnable task) {
this.decorator.decorate(task).run();
}
// ... |
Had time to look at the
Decorator:
When I run that, the runnable provided is a
and here is the problem for me. At the moment I am achieving this by duplicating the
And those are protected final, if they were not final I could provide my own wrappers by overriding them but as they are final I have to copy and modify the whole class hierarchy to provide my wrappers. I'll hope I did make my problem clear, if not just tell me, thanks. |
Thanks, @tkrah, for the extra detail. I think at this point it would be ideal for you to share a minimal GitHub sample. I can go through and either provide a pull request to that repo or use the sample to see what kind of change is best to Spring Security. Can you please provide a minimal sample? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Ok, I'll try to provide an example, may take a little bit time though. |
Hi,
I am using the DelegatingSecurityContextTaskExecutor and the DelegatingSecurityContextRunnable / Callable stack in a custom ForkJoinPool to make sure, my SecurityContext is transported on the various scheduled / submitted Tasks in the selected pool.
That works find so far but I need to hook those wrappers so I can modify the execution environment to do additional tasks before the runnable / callable is called (like the setup of the context does) and to cleanup things after the original runnable / callable comes back.
At the moment as the code is written (package protected, private, final stuff) I need to / I am forced to copy the whole code for my custom ForkJoinPool and TaskExecutor and provide also custom wrapper classes to meet that requirement, because the whole code written now, does not have a strong focus on being extended / customized / enriched.
It would be nice if you could just provide e.g. protected methods / wrappers or some functional interfaces for setup / finished callbacks I could provide when creating the pool so that I can just use your classes, enriched by my provided callbacks which are called on the correct time in the lifecycle, so that I am not forced to mimic the context saving / restoring behavior and have my addon glue executed too.
Thanks for considering.
The text was updated successfully, but these errors were encountered: