Active directory Auth
Vi er nogle studerende der er i færd med at udvikle et system, hvor logon bekræftelse skal ske igennem Active Directory..Vores problem er så at få brugeren automatisk identificeret uden at han skal gentage sit brugernavn og password..
Nederstående eksempel virker ved at skrive brugernavnet og adgangskoden, men disse informationer burde jo tilgåes automatisk igennem Windows Auth for klienten på en eller anden måde?
------
import java.util.*;
import javax.naming.*;
import javax.naming.directory.*;
public class Auth
{
public static void main(String[] args)
{
try
{
Hashtable env = new Hashtable();
env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory" );
env.put( Context.PROVIDER_URL, "LDAP://smdgdcodksgd001:389" );
// Only DIGEST-MD5 works with our Windows Active Directory
env.put( Context.SECURITY_AUTHENTICATION, "DIGEST-MD5" );
// No other SALS worked with me
env.put(Context.SECURITY_PRINCIPAL, "brugernavn" );
// Specify the username ONLY to let Microsoft Happy
env.put( Context.SECURITY_CREDENTIALS, "adgangskode" );
// The password
DirContext ctx = new InitialDirContext( env );
ctx.close();
}
catch(NamingException ne)
{
System.out.println("Error authenticating user:");
System.out.println(ne.getMessage());
return;
}
//if no exception, the user is already authenticated.
System.out.println("OK, successfully authenticating user");
}
}
