Results 1 to 2 of 2
  1. #1
    fxRichard is offline Member
    Join Date
    Dec 2008
    Rep Power

    Default 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 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 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....

  2. #2
    toadaly is offline Senior 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.

Similar Threads

  1. multiple threads access the same method.
    By bhanu in forum New To Java
    Replies: 3
    Last Post: 02-16-2009, 07:54 AM
  2. FileLock and file access from concurrent threads..
    By fxRichard in forum Advanced Java
    Replies: 5
    Last Post: 01-02-2009, 09:08 PM
  3. [SOLVED] Extracting Tokens Help
    By Hunkpapa in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 02:17 AM
  4. tokens
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 12-03-2007, 12:30 AM
  5. tokens
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-25-2007, 03:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts