These are the imports that I am using:
import com.novell.ldap.*;
import java.io.UnsupportedEncodingException;
and I am trying to do a very simple password validation that I found at:
http://developer.novell.com/documentation开发者_Python百科/samplecode/jldap_sample/index.htm
and I can't seem to get the bind to work. Does anyone have a better way of doing this with grails or java. I am finding myself really lost and any examples or guidance would help.
Thanks.
This Java example uses the UnboundID LDAP SDK to connect and bind to a directory server. Run it like:
$ java -cp YOUR_CLASSPATH BindExample hostname port bindDn password
BindExample.java:
import com.unboundid.ldap.sdk.BindRequest;
import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.Control;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.ldap.sdk.SimpleBindRequest;
public final class BindExample {
public static void main(String... args) {
if(args.length == 4) {
final String hostname = args[0];
final String dn = args[2];
final String password = args[3];
int port;
LDAPConnection ldapConnection;
try {
port = Integer.parseInt(args[1]);
} catch(NumberFormatException nfx) {
System.err.println(args[1] + " is not an integer, using 389");
port = 389;
}
try {
ldapConnection =
new LDAPConnection(hostname,port);
} catch(final LDAPException lex) {
System.err.println("failed to connect to "
+ hostname + " " +
lex.getMessage());
return;
}
try {
final BindRequest bindRequest =
new SimpleBindRequest(dn,password);
BindResult bindResult =
ldapConnection.bind(bindRequest);
if(bindResult.getResultCode() == ResultCode.SUCCESS) {
System.out.println("authentication successful");
}
if(bindResult.hasResponseControl()) {
Control[] controls =
bindResult.getResponseControls();
// handle response controls ...
}
ldapConnection.close();
} catch(final LDAPException lex ) {
System.err.println("bind failed");
ldapConnection.close();
return;
}
}
}
}
精彩评论