Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 21-Aug-17 12:07pm
v2

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.
 
Share this answer
 
v2
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
 
Share this answer
 
v2
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 )
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900