一、导入包
包名:ldapjdk.jar
二、LDAP连接
public static LDAPConnection getConnection() {
LDAPConnection conn = LdapUtils.getConnectionPool().getConnection();
try {
conn.authenticate(USER_ID, PASSWORD);
} catch (LDAPException e) {
String message = "Failed to authen the system ldap user";
if (log.isErrorEnabled()) {
log.error(message, e);
}
}
return conn;
}
三、增、删、改
public boolean create(UserEntity entity){
String dn = "uid=" + user + "," + machineryPath;
LDAPAttributeSet AttrSet = new LDAPAttributeSet();
AttrSet.add(new LDAPAttribute("uid", user));
...
LDAPEntry newEntry = new LDAPEntry(dn, AttrSet);
conn.add(newEntry);
}
public boolean delete(String machineryPath, String user) {
if (user == null || user.trim().length() == 0) {
return false;
}
try {
conn.delete("ou=Role,uid=" + user + "," + machineryPath);
conn.delete("uid=" + user + "," + machineryPath);
System.out.println("删除成功。。");
return true;
} catch (LDAPException e) {
e.printStackTrace();
}
return false;
}
阅读(4561) | 评论(0) | 转发(0) |