Spring LDAP 是一个用于操作 LDAP 的 Java 框架。它是基于 Spring 的 JdbcTemplate 模式。这个框架能够帮助开发人员简化 looking up,closing contexts,looping through NamingEnumerations,encoding/decoding values与 filters 等操作。(理论上市面所有目录产品都适用,什么?你不知道ldap目录,请建议绕行)
下面是我搭建的一个简单的java测试目录的环境,只是试下能不能连上ldap,以及能否进行简单操作。功能比较简单
所需jar包:见附件工程
applicationContext.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="contextSource"
class="org.springframework.ldap.core.support.LdapContextSource">
<property name="url" value="ldap://10.201.4.*:389" />
<property name="base" value="o=*" />
<property name="userDn" value="cn=*"/>
<property name="password" value="***" />
</bean>
<bean id="ldapTemplate"
class="org.springframework.ldap.core.LdapTemplate">
<constructor-arg ref="contextSource" />
</bean>
<bean id="personDao" class="springLdapContext.PersonDaoImpl">
<property name="ldapTemplate">
<ref bean="ldapTemplate" />
</property>
</bean>
</beans>
另外就是一个简单的操作类了PersonDaoImpl
public class PersonDaoImpl implements PersonDao {
private LdapTemplate ldapTemplate;
public static void main(String[] args) {
ApplicationContext cxt = new ClassPathXmlApplicationContext("applicationContext.xml");
PersonDaoImpl personDao = (PersonDaoImpl)cxt.getBean("personDao");
List users = personDao.getAllPersonNames();
System.out.println(users.size());
}
/*
* @see PersonDao#getAllPersonNames()
*/
public List getAllPersonNames() {
EqualsFilter filter = new EqualsFilter("objectclass", "person");
return ldapTemplate.search(DistinguishedName.EMPTY_PATH, filter.encode(), new AttributesMapper() {
public Object mapFromAttributes(Attributes attrs) throws NamingException {
return attrs.get("cn").get();
}
});
}
public void setLdapTemplate(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
}
如果你查询的路径设置正确且下面有用户,应该就能输出用户数量了。注
<property name="base" value="o=*" /> base即查找的根路径
分享到:
相关推荐
Spring LDAP。 官网 Spring LDAP API。 Spring LDAP 开发文档。
Practical Spring LDAP is your guide to developing Java-based enterprise applications using the Spring LDAP Framework. This book explains the purpose and fundamental concepts of LDAP before giving a ...
rar包:一个Web工程, 主要有,利用Spring-ldap对LDAP的基本操作(查询,增删改);Extjs实现的对Ldap的树状结构的显示,结构有点类似Softerra LDAP;一个测试类。 pdf:spring-ldap-reference.pdf Extjs.pdf ...
使用spring-ldap-core测试链接ldap com.ldap.test.service包下为Junit测试类
学习SpringSecurity时,看到LDAP认证,不了解LDAP...所以转头学习了一下LDAP,搭建了一个DEMO,仅作记录。 LDAP(Lightweight Directory Access Protocol) 轻量级目录访问协议,LDAP目录以树状的层次结构来存储数据。
spring ldap的使用
spring ldap 1.3.0的全部jar包下载
Spring Data LDAP API。 Spring Data LDAP 开发文档。 官网 Spring Data LDAP API。
spring-ldap1.3.1,一种框架技术用来实现对ldap服务器增删改查数据的工具包。
基于springldap的增删改查,以及通过ldap的用户名、密码进行验证
spring_ldap spring_ldap spring_ldap
进阶-使用Spring Security3.2搭建LDAP认证授权和Remember-me
SpringLDAP和JNDI增删改查的入门级例子 能够通过编译和运行 已经包含了需要的包,用eclipse导入即可
Spring 实现LDAP 域认证,内有个人项目的实例分析,,希望大家参考,也可以给意见
spring_ldap1.3的chm格式api
去掉JAR包了。Spring+LDAP实现单点登录SSO 单点登录 LDAP SPRING
本项目为测试使用Spring操作LDAP 主要POM依赖 <groupId>org.springframework <artifactId>spring-context <version>3.2.9.RELEASE <groupId>org.springframework.ldap <artifactId>spring-...
ldap+mysql+gerrit环境搭建,简单介绍如何搭建gerrit代码检视系统
Practical Spring LDAP英文原版