Skip to content

Commit

Permalink
Fixes jetty#6396 Threads created by Jetty no longer run as the Subjec…
Browse files Browse the repository at this point in the history
…t that Jetty was started as
  • Loading branch information
stoty committed Jun 11, 2021
1 parent f19b6fa commit cbb7c11
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.function.Supplier;
import javax.security.auth.Subject;

/**
* Convenience class to ensure that a new Thread is created
Expand All @@ -44,12 +45,24 @@ class PrivilegedThreadFactory
*/
static <T extends Thread> T newThread(Supplier<T> newThreadSupplier)
{
// doPriviliged resets the subject
// We need to save the subject, and run a subjext.doAs from inside
// doPrivileged to restore it.
// see https://www.ibm.com/docs/en/was-zos/8.5.5?topic=service-java-authentication-authorization-authorization
Subject subject = Subject.getSubject(AccessController.getContext());
return AccessController.doPrivileged(new PrivilegedAction<T>()
{
@Override
public T run()
{
return newThreadSupplier.get();
return Subject.doAs(subject, new PrivilegedAction<T>()
{
@Override
public T run()
{
return newThreadSupplier.get();
}
});
}
});
}
Expand Down

0 comments on commit cbb7c11

Please sign in to comment.