Hi all,
Currently my application is authenticating using NTLM authentication. It authenticates using a Domain Contoller which was residing on 2003 server. Now since it is migrated to 2008, my current NTLM authentication is not working.
I suppose that this would require Kerberos authentication. (Correct me if I am wrong)
My current code with NTLM authentication looks like this. If I just try to replace sPDC value with new server name, it doesnt work. I found several code on net, but did not understand the refrrence. Can anyone provide the easiest way to move to Kerberos with minimal changes in below code.
Note:- I have hard coded few values for easier understanding. Though original code take username, password in form of arguements.
import java.io.IOException;
import java.util.Hashtable;
import java.util.Properties;
import com.linar.jintegra.NTLMAuthenticate;
public class ADAuthenticate
{
private static
String sPDC1;
private static String sPDC2;
private static String sPDC3;
public static void main(String[] args)
{
try
{
NTAuthenticate("domainname", "username", "password");
}
catch (SecurityException se)
{
System.out.println(se.getMessage());
}
catch (PDCNotFoundException nfe)
{
System.out.println("Cannot authenticate the user. Unable to find a domain controller.");
}
}
public static void NTAuthenticate(String sDomain, String sUsername, String sPassword) throws SecurityException, ADAuthenticate.PDCNotFoundException
{
try {
sDomain = "domainname";
NTLMAuthenticate.validate(sPDC1, sDomain, sUsername, sPassword);
}
catch (IOException ioe)
{
System.out.println(String.valueOf(new StringBuffer("The First PDC (").append(sPDC1).append(") failed to communicate.")));
try {
NTLMAuthenticate.validate(sPDC2, sDomain, sUsername, sPassword);
}
catch (IOException ioe2)
{
System.out.println(String.valueOf(new StringBuffer("The Second PDC (").append(sPDC2).append(") failed to communicate.")));
try {
NTLMAuthenticate.validate(sPDC3, sDomain, sUsername, sPassword);
}
catch (IOException ioe3)
{
System.out.println(String.valueOf(new StringBuffer("The Third and Final PDC (").append(sPDC3).append(") failed to communicate.")));
throw new PDCNotFoundException();
}
}
}
}
static
{
try
{
Properties p = new Properties();
sPDC1 = "domaincontrollername";
sPDC2 = p.getProperty("auth.pdc2");
sPDC3 = p.getProperty("auth.pdc3");
}
catch (Exception pe)
{
pe.printStackTrace();
System.out.println("Properties file </conf/authenticate/authenticate.properties> not found.");
}
}
public static class PDCNotFoundException extends Exception
{
}
}