Ben Thorner
Ben Thorner

Reputation: 13

Impersonate User On The Current Thread

I'd like to create a Java function that, given a username and password, elevates the associated thread / process 's security context (in Windows) such that other functions can perform e.g. administrative tasks BUT using the original user's context / environment i.e. similar to

runas.exe /env /u:... [/p:...] java.exe ... 

but on the current thread / process.

The closest I've got was by investigating PriviledgedActions, but the classes involved and their interconnections became rather bewildering. Could someone provide me with some pointers to achieve the above?

Thanks in advance,

Ben

Upvotes: 1

Views: 699

Answers (1)

Andrew Duffy
Andrew Duffy

Reputation: 6938

PrivilegedAction won't work for this, unfortunately. If you need to access files, jCIFS can do so as any user. Active Directory access through JNDI is possible, but for other things you will probably need to break out to native code using JNI.

Upvotes: 1

Related Questions