Ntlm Password Authentication using jCifs


// Dependencies
// (1) jcifs-1.2.9.jar

import java.net.UnknownHostException;

import jcifs.UniAddress;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbAuthException;
import jcifs.smb.SmbException;
import jcifs.smb.SmbSession;

public class Test01 {

public static void main(String[] args) {
	boolean userAuthenticated = false;
	String authenticationMessage = "";
	try {
		String domainController = "subdomain.domain.com";
		UniAddress dc = UniAddress.getByName(domainController, true);
		NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("Domain", "user", "password");
		SmbSession.logon(dc, auth);
		userAuthenticated = true;
	} catch (SmbAuthException sae) {
		authenticationMessage = "SmbAuthException : " + sae.getMessage();
	} catch (UnknownHostException uhe) {
		authenticationMessage = "UnknownHostException : " + uhe.getMessage();
	} catch (SmbException smbe) {
		authenticationMessage = "SmbException : " + smbe.getMessage();
	}
	if (userAuthenticated)
		System.out.println("User Authenticated");
	else
		System.out.println("Authenticated failed : " + authenticationMessage);
}
}

You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

AddThis Social Bookmark Button

Similar Posts

Comments are closed.