Chinaunix首页 | 论坛 | 博客
  • 博客访问: 251922
  • 博文数量: 65
  • 博客积分: 2026
  • 博客等级: 大尉
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-12 14:34
文章分类

全部博文(65)

文章存档

2012年(1)

2011年(1)

2010年(1)

2009年(2)

2008年(7)

2007年(6)

2006年(47)

我的朋友

分类:

2008-04-26 13:24:52

一、导入包
包名: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) |
0

上一篇:学习使用LOG4J的心得体会

下一篇:

给主人留下些什么吧!~~