Well, what I am trying to do is just connect to the AD using LDAP. I just want to be able to login with one of the users from the AD. I'm going to be using the database for authentication and security, but I just want to use LDAP to connect. I'm sure I'm overcomplicating this, though.
I have changed some things in my code, as I found a kind of tutorial. This is what I have now. But there are no errors, but it still doesn't let me log in using a user from the AD.
public class LDAPAuth {
public Hashtable<String, String> env = null;
public Control[] connCtls = null;
Context ctx;
DirContext dirContext;
public LdapContext ldapContext = null;
String baseName = ",cn=users,dc=ssc,dc=mycompany,dc=com";
String modelUsername = "template";
String serverIP = "ssc-dc-01.ssc.mycompany.com";
public LDAPAuth(String ldapurl) {
ldapurl = "ldap://" + serverIP + ":389";
try {
env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.PROVIDER_URL, ldapurl);
env.put(Context.SECURITY_PRINCIPAL, "cn=Heather" + baseName);
env.put(Context.SECURITY_CREDENTIALS, "mysecret" + baseName);
env.put(Context.SECURITY_PROTOCOL, "ssl");
ctx = new InitialContext(env);
} catch (Exception e) {
System.out.println(" bind error: " + e);
e.printStackTrace();
}
try {
ldapContext = new InitialLdapContext(env, connCtls);
} catch (AuthenticationException e) {
System.out.println("Authentication exception " + e);
} catch (NamingException e) {
System.out.println("Naming exception " + e);
}
}
public Attributes fetch(String username) {
Attributes attributes = null;
try {
System.out.println("fetching: " + username);
Object obj = ctx.lookup("cn=" + username
+ baseName);
System.out.println("cn=" + username + baseName + "is bound to: " + obj);
//attributes = obj.getAttributes("");
for (NamingEnumeration<?> ae = attributes.getAll(); ae
.hasMoreElements()

{
Attribute attr = (Attribute) ae.next();
String attrId = attr.getID();
for (NamingEnumeration<?> vals = attr.getAll(); vals.hasMore()

{
String value = vals.next().toString();
System.out.println(attrId + ": " + value);
}
}
} catch (NamingException e) {
System.out.println(" Problem looking up " + username + baseName + ". " + e);
}
return attributes;
}
public void finito() {
try {
ldapContext.close();
System.out.println("Context is closed");
} catch (NamingException e) {
System.out.println("Context close failure " + e);
}
}
}
I have another class that I call the fetch method right before it returns "logged in" true and that's how it gets here.
[ August 29, 2008: Message edited by: Heather Rose ]