Spring-LDAP
下载地址 :http://www.springframework.org/ldap
用Spring LDAP最小需要:
* spring-ldap(spring-ldap包)
* spring-core(用于框架内部的丰富的工具类)
* spring-beans(方便操作java beans的接口和类)
* spring-context(增加通过一致API为应用对象获取资源的能力)
* spring-dao(使经常性的错误处理跟使用中的数据访问分开的异常处理机制)
* commons-logging(简单的日志处理,内部使用)
UserDaoLdapImpl
Java代码
package cn.com.ldap;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import cn.com.ldap.Preson.Person;
/**
* @author Wangyaodi version 1.0 2008-6-12 | 下午02:55:25
*/
public class UserDaoLdapImpl {
private LdapTemplate ldapTemplate;
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
public List getAllPersonNames() {
return ldapTemplate.search("", "(objectclass=person)",
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get("cn").get();
}
});
}
}
package cn.com.ldap;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.LdapTemplate;
import cn.com.ldap.Preson.Person;
/**
* @author Wangyaodi version 1.0 2008-6-12 | 下午02:55:25
*/
public class UserDaoLdapImpl {
private LdapTemplate ldapTemplate;
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
public List getAllPersonNames() {
return ldapTemplate.search("", "(objectclass=person)",
new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs)
throws NamingException {
return attrs.get("cn").get();
}
});
}
}
preson:
Java代码
package cn.com.ldap;
public class Preson {
public class Person {
private String cn;
private String sn;
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}
}
package cn.com.ldap;
public class Preson {
public class Person {
private String cn;
private String sn;
public String getCn() {
return cn;
}
public void setCn(String cn) {
this.cn = cn;
}
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}
}
applicationContext.xml
Xml代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://192.168.16.XXX:389" />
<property name="base" value="OU=XXX,OU=XXX,OU=XXX,OU=XXX,DC=XXX,DC=XXX,DC=XXX" />
<property name="userName" value="XXX@headquarter" />
<property name="password" value="XXX" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="userDao" class="cn.com.ldap.UserDaoLdapImpl">
<property name="ldapTemplate">
<ref bean="ldapTemplate" />
</property>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://192.168.16.XXX:389" />
<property name="base" value="OU=XXX,OU=XXX,OU=XXX,OU=XXX,DC=XXX,DC=XXX,DC=XXX" />
<property name="userName" value="XXX@headquarter" />
<property name="password" value="XXX" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="userDao" class="cn.com.ldap.UserDaoLdapImpl">
<property name="ldapTemplate">
<ref bean="ldapTemplate" />
</property>
</bean>
</beans>
main
Java代码
public static void main(String[] args) {
ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDaoLdapImpl userDao = (UserDaoLdapImpl)cxt.getBean("userDao");
List users = userDao.getAllPersonNames();
System.out.println(users.size());
}
分享到:
相关推荐
去掉JAR包了。Spring+LDAP实现单点登录SSO 单点登录 LDAP SPRING
Spring-ladp-reference
LADP基础培训,初步了解LADP,基本命令和结构介绍。
LADP服务器安装LADP服务器安装
ladp摘取的网页文件ladp摘取的网页文件ladp摘取的网页文件ladp摘取的网页文件ladp摘取的网页文件
openladp 的windows连接工具(ldapadmin),免安装版,解压后直接使用
java实现对ladp增 删 改 查操作,以及如何按目录遍历节点,其中有一点设计业务的代码,但是不影响对ladp操作的代码,代码很干净
NULL 博文链接:https://xrb2008.iteye.com/blog/650632
这个小软件是用于查看LDAP属性的,非常方便
NULL 博文链接:https://lujin55.iteye.com/blog/1492535
有关于ldap的名词解释 Ldap term on the interpretation of
LADP是不错的数据库组件,大家在开发的时候可能会用到!这是我推荐的啊!
Your JXplorer - A Java Ldap Browser download will start shortly
ldapLeaningLDAP目录中的信息是是按照树型结构组织,具体信息存储在条目(entry)的数据结构中。条目相当于关系数据库中表的记录;条目是具有区别名DN (Distinguished Name)的属性(Attribute),DN是用来引用条目的...
delphi 通过LOAD验证用户信息,具体查看代码
本篇文章主要介绍了Vue+Jwt+SpringBoot+Ldap完成登录认证的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
在linux上利用ldap和CAS实现单点登陆
基于LDAP认证和MOM的分布式会议系统 LDAP:Light Weight Directory Access Protocol 轻量级目录访问协议 MOM:Message-Oriented Middleware 面向消息的中间件
win下非常好用的LDAP查看工具,非常稳定。最新版,64位。
JNDI修改OpenLDAP条目密码,内容包括一个MD5与Base64的转码操作,以及使用JNDI以MD5的方式修改LDAP条目的密码.