0

Languages like C++ and C# allow one to spawn a thread and set the user principal for that thread. Essentially, one can run the new thread as a user that is different from the user that created the thread.

Java does not support for this.

I assume something like this can be done with Java using JNI? If so, can anyone provide an example.

NOTE: Solutions like Windows runas or PSTools psexec can allow you to impersonate process from java, but are insecure. I am not looking for these types of solutions.

cmd
  • 11,622
  • 7
  • 51
  • 61
  • possible duplicate of [Impersonating a user from a Java Servlet](http://stackoverflow.com/questions/2316063/impersonating-a-user-from-a-java-servlet) – cmd Feb 10 '15 at 18:57

1 Answers1

0

You won't be able to do it in pure Java.

Doing it through the JNI will force you to have platform specific code, so the solution won't be portable and will rely on specific platforms mechanisms to handle the user impersonation.

Moreover, keep in mind that impersonation works with multiple processes (not threads). Inside a JVM there are multiple threads but one process (=> one user). To have other users, you will have to spawn another process (=> another JVM). And RPC won't be easy ...

superbob
  • 1,628
  • 13
  • 24