We're trying to make a credentials manager for authenticating against
LDAP.
We've written some code but we're unsure about what to do next,
or if the code is correct. Any ideas?
Code:
package com.uwyn.rife.authentication.credentialsmanagers;
import com.novell.ldap.*;
import com.uwyn.rife.authentication.*;
import com.uwyn.rife.authentication.Credentials;
import com.uwyn.rife.authentication.CredentialsManager;
import com.uwyn.rife.authentication.credentials.RoleUserCredentials;
import com.uwyn.rife.authentication.exceptions.CredentialsManagerException;
import java.io.UnsupportedEncodingException;
public class LDAPUsers implements CredentialsManager {
static long userid;
public long verifyCredentials(Credentials credentials) {
RoleUserCredentials cred = (RoleUserCredentials)credentials;
String loginDN = "cn=" + cred.getLogin() + ",dc=localhost";
String password = cred.getPassword();
return authenticate(loginDN, password);
}
public static long authenticate(String loginDN, String password) {
int ldapPort = LDAPConnection.DEFAULT_PORT;
int ldapVersion = LDAPConnection.LDAP_V3;
String ldapHost = "localhost";
boolean success = false;
LDAPResponseQueue queue = null;
LDAPConnection lc = new LDAPConnection();
int rc = 0;
try {
lc.connect(ldapHost, ldapPort);
queue = lc.bind(ldapVersion,
loginDN,password.getBytes("UTF8"), (LDAPResponseQueue)null );
LDAPResponse rsp = (LDAPResponse)queue.getResponse();
String msg;
rc = rsp.getResultCode();
msg = rsp.getErrorMessage();
if(rc == LDAPException.SUCCESS) {
success = true;
} else {
throw new LDAPException( msg, rc, (String)null );
};
lc.disconnect();
} catch (LDAPException e) {
if (e.getResultCode() == LDAPException.NO_SUCH_OBJECT) {
System.err.println("Error: No such user name");
} else if (e.getResultCode() ==
LDAPException.NO_SUCH_ATTRIBUTE) {
System.err.println("Error: No such attribute");
} else {
System.err.println("Error: " + e.toString());
}
} catch (UnsupportedEncodingException e) {
System.out.println("Error: " + e.toString());
}
if(success) {
return userid++;
} else {
return -1;
}
}
}
_______________________________________________
Rife-users mailing list
[EMAIL PROTECTED]
http://lists.uwyn.com/mailman/listinfo/rife-users