Results 1 to 2 of 2
- 02-22-2010, 10:24 PM #1Member
- Join Date
- Dec 2008
- Rep Power
JNI: Java to C ...intermediary threads and access tokens...
...not sure what else to title this but here is the problem...
I have C code running as a windows service that uses JNI to kick off a persistent java process that runs indefinitely. At times the java process needs access to the users desktop to show a gui etc...so use JNI and load a custom DLL file I wrote that has methods to grab the currently logged on users token, impersonate it and assign it to the current thread...no problems....I have done this and kicked off programs in C etc and they run as the currently logged on user. The issue arises that I need some java code to run as the currently logged on user however there are a few issues:
1) I need the native java thread ID (doesn't seem to be possible because 1 java thread != 1 native thread from my understanding)
2) I have tried having the java code call the c code and assign a token to the current thread...the permissions and rights do not flow back to the java code it is still stuck in the local system account....
3) I have also tried having the java code call the c code...give it a call back method and have the c code assign the token to the current thread and run the java method via jni in the current thread.....permissions still don't make it across
Any idea's? Oh and yes I have done ImpersonateLoggedOnUser() along with SetThreadToken() etc in c....everything works fine if I have the c code actually kick off a process IN the c code or perform tasks c code it is a matter of the token not affecting the threads in the jvm....
- 02-23-2010, 06:00 AM #2Senior Member
- Join Date
- Jan 2009
- Rep Power
I think you're going to have to kick off a java thread from native code that is impersonating the user so it will have access as well.
1. From your java code, call a native method that uses your custom dll to grab the currently logged in user toke and impersonate it.
2. From that native code, kick off a second java thread and connect it to your persistent thread via your preferred mechanism (c pipes, RMI, some custom code you write, etc.).
3. The new java thread should inherit the permissions of it's parent, and be able to do what you want. The persistent java process can then use whatever proxy method you chose to cause the 2nd java instance to do whatever you need it to do.
Good luck. This sounds like a challenging/fun problem.
- By bhanu in forum New To JavaReplies: 3Last Post: 02-16-2009, 07:54 AM
- By fxRichard in forum Advanced JavaReplies: 5Last Post: 01-02-2009, 09:08 PM
- By Hunkpapa in forum New To JavaReplies: 2Last Post: 11-04-2008, 02:17 AM
- By Gilgamesh in forum New To JavaReplies: 5Last Post: 12-03-2007, 12:30 AM
- By Gilgamesh in forum New To JavaReplies: 3Last Post: 11-25-2007, 03:39 AM