Click here to Skip to main content
13,189,324 members (65,757 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,
I am getting this issue of UnsatisfiedLink on calling this native Function
Pls. help me
Below is my code
//Test1.java
import com.sun.jna.ptr.*;
class Test1
{
	int LOGON32_LOGON_NETWORK=0;
	int LOGON32_PROVIDER_DEFAULT=0;
	IntByReference lToken=null; 
   static
    {
        System.out.println("Before loading advapi32.dll");
	System.load("C:\\Windows\\system32\\advapi32.dll"); 
        System.out.println("After loading advapi32.dll");
	
    }
    public static void main(String ar[])
    {
        System.out.println("Hello world from Java");
        Test1 t=new Test1();	
 
t.LogonUser("urms","ICICIBANKLTD","urms",t.LOGON32_LOGON_NETWORK,t.LOGON3
 
2_PROVIDER_DEFAULT,t.lToken);
        // t.inDll();
	
    }
//   public native void inDll();
     public  native static boolean LogonUser(String sUserName,String 
 
sDomainName, String sPassword,int LOGON32_LOGON_NETWRK,int 
 
LOGON32_PROVIDER_DEFAULT,IntByReference lToken);
}
Posted 2-Dec-09 1:26am
Updated 21-Aug-17 12:07pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Looking at the JNA Documentation[^], I cannot see a direct reference for LogonUser(). I suspect you will need to use an alternative method to get the address of the function, possibly the W32APIFunctionMapper class.
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi Manoj,

I am also looking for JNA solution to authenticate the windows NT credientials. When I execute the following program, I am getting unsatisfiedLinkerror. I have added the jna.jar file in the windows CLASSPATH. Have you got a solution for your problem, if please provide me the code. I am using Apache tomcat and windows XP server.

import com.sun.jna.Library;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.Native;
import com.sun.jna.Platform;
 
/** Simple example of JNA interface mapping and usage. */
public class HelloWorld {
 
//    static {
//    	System.load("C:\\Windows\\system32\\advapi32.dll"); 
//    }
	
	// This is the standard, stable way of mapping, which supports extensive
    // customization and mapping of Java to native types.
    public interface CLibrary extends StdCallLibrary {
    	
       CLibrary INSTANCE = (CLibrary)
	  Native.loadLibrary((Platform.isWindows() ? "advapi32" : "c"),  CLibrary.class);
       public boolean LogonUser(String userName, String domain,String password, int dwLogonType, int dwLogonProvider, IntByReference lToken);
       
    }
 
    public static void main(String[] args) {
    	IntByReference lToken=null;  	
       CLibrary.INSTANCE.LogonUser("username","domainName","bangalore",0,0,lToken);	
    }
}

Thanks
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Hi - I realize this post is about two years old, but for those that may be looking at a similar issue - I had a similar issue yesterday, and the answers via Google I found were kind of obtuse.
It looks like in both cases the IntByReference object "lToken" has not been initialized. Set it before calling ...
lToken = new IntByReference();

After a successful login call the return value is "true" and the lToken object will have the token info, for failed login ("false"), the object is not changed.

For the failed-login cases you should code an jna/native instance of "Kernel32" so you can call "GetLastError()" method. This is because the un/pw may be correct, but there will be other reasons to fail. One example is "Not authorized on this machine".
( i.e. some of the codes from microsoft )
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.171016.2 | Last Updated 21 Aug 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100