Hello everyone,
I would like to show you guys how to use waffle library for JNA (Java Native Access).
So, coding time...
[Source Code]
package thiago.leoncio;
import com.sun.jna.platform.win32.Sspi;
import com.sun.jna.platform.win32.Sspi.SecBufferDesc;
import waffle.windows.auth.IWindowsSecurityContext;
import waffle.windows.auth.impl.WindowsAuthProviderImpl;
import waffle.windows.auth.impl.WindowsSecurityContextImpl;
/**
* @author THiago
* @Date 10/08/2016
* @Description: How to get details from current machine.
* @libs for JNA(jna.jar;jna-min.jar;jna-platform.jar;guava-18.0.jar;waffle-jna-1.8.0.jar)
*/
public class Authenticator {
public static void main(String args[]) {
IWindowsSecurityContext clientContext = WindowsSecurityContextImpl.getCurrent( "Negotiate", "localhost" );
// create an auth provider and a security context for the client
// on the server
WindowsAuthProviderImpl provider = new WindowsAuthProviderImpl();
IWindowsSecurityContext serverContext = null;
do {
if (serverContext != null) {
byte[] tokenForTheClientOnTheServer = serverContext.getToken();
SecBufferDesc continueToken = new SecBufferDesc(Sspi.SECBUFFER_TOKEN, tokenForTheClientOnTheServer);
clientContext.initialize(clientContext.getHandle(), continueToken, "localhost");
}
byte[] tokenForTheServerOnTheClient = clientContext.getToken();
serverContext = provider.acceptSecurityToken("server-connection", tokenForTheServerOnTheClient, "Negotiate");
} while (clientContext.isContinue());
// client is, only by exchanging byte[] arrays
System.out.println(serverContext.getIdentity().getFqn());
}
}
[Output]
networkName\userID
as I explained in previous blog:
"
On top of JNA exists a library called Waffle which encapsulates all functionality you need to implement user authentication. Get from GitHub at https://github.com/dblock/waffle and also on Maven central. To download the jar files get from here: https://github.com/dblock/waffle/releases/download/Waffle-1.8.0/Waffle.1.8.zip
"
Please, see this JNA and Waffle article also:
http://phonecoding.com/2016/06/how-to-get-details-from-current-machine.html
Happy coding..
Thiago Leoncio.
Thiago - Tech Director, Principal Architect and software developer for many different languages. I am passionate about the development of any kind. I am a developer since 1996, coding for many different styles such as Cold Fusion, Java, PHP, PL-SQL, Objective-C, Nodejs and many others..anything needed we can translate to code.
Saturday, October 8, 2016
Saturday, October 1, 2016
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/CacheBuilder on WindowsAuthProviderImpl class
Hey guys,
Recently I was working with JNA using Waffle to get the user details, and at same time creating a token on client side, in order to create a trust relationship between the targets.. Then i got this issue that I would like to share how to fix:
On top of JNA exists a library called Waffle which encapsulates all functionality you need to implement user authentication. Get from GitHub at https://github.com/dblock/waffle and also on Maven central. To download the jar files get from here: https://github.com/dblock/waffle/releases/download/Waffle-1.8.0/Waffle.1.8.zip
Using waffle project I got this error recently:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/cache/CacheBuilder
at waffle.windows.auth.impl.WindowsAuthProviderImpl.<init>(WindowsAuthProviderImpl.java:68)
at waffle.windows.auth.impl.WindowsAuthProviderImpl.<init>(WindowsAuthProviderImpl.java:58)
at thiago.leoncio.Authenticator.main(Authenticator.java:19)
Caused by: java.lang.ClassNotFoundException: com.google.common.cache.CacheBuilder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
To fix this you must add the library that has all google classes. It's name is guava-18.0.jar and of course the waffle one: waffle-jna-1.8.0.jar
Please, check this JNA and Waffle article also: http://phonecoding.com/2016/10/how-to-use-waffle-library-for-jna-java.html
I hope this helps,
Thiago Leoncio.
Subscribe to:
Posts (Atom)
