Skip to content
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

Security Context propgation into Runnables #5

Open
mez5001 opened this issue Oct 13, 2016 · 1 comment
Open

Security Context propgation into Runnables #5

mez5001 opened this issue Oct 13, 2016 · 1 comment

Comments

@mez5001
Copy link

mez5001 commented Oct 13, 2016

I was using porcupine to create an ExecutorService in my project. When I would send in my first round of Runnables into the executor everything worked as expected. I then tried added another round of Runnables into the executor and was running into permissions issues. I checked the logs and the second round of runnables were running as the original user. I had to use a ManagedExecutorService instead to get the SessionContext to properly propagate into the Runnables. I wrote a stackoverflow question that provides a more clear example: http://stackoverflow.com/questions/40002010/how-to-avoid-executorservice-from-overridding-security-principal-of-a-runnable

Are the ExecutorService and the generated threads supposed to be container manager or is that an invalid assumption that I made?

@M0rious
Copy link

M0rious commented Jul 3, 2019

I think this is a flaw that prevents procupine from being used in alot of cases.
Citing ManagedThreadFactory Javadoc:

"The Runnable task ... will run with the application component context of the component instance that created (looked-up) this ManagedThreadFactory instance."

Porcupine seems to assume the context to be capured from the thread that invokes managedThreadFactory.newThread(runnable), which is not the case - the context is captured form the point at which the ManagedThreadFactory was looked up or injected. The same context is applied to each new thread created by the ManagedThreadFactory.

So this code, executed inside a thread from ManagedThreadFactory,

    @Resource
    private SessionContext sessionContext;
...
    private String getLoginName() {
        final Principal principal = this.sessionContext.getCallerPrincipal();
}

will always return the name of the user that first invoked the ManagedThreadFactory, even if currently another user uses the ManagedThreadFactory.

The only solution i know of is to use ManagedExecutorService as you already stated - but then you do not need porcupine, since these can not be configured during runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants