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());
String userName = "10010a";
String passWord = "2039729";
String userDn = personDao.getDnForUser(userName);
System.out.println("userDn:" + userDn);
boolean bl=personDao.authenticate(userDn, passWord);
System.out.println("验证结果:" + bl);
}
/**
* 根据CN属性取得用户DN(当然你可以根据自己情况换成别的属性来操作)
* @param cn
* @return
*/
private String getDnForUser(String cn) {
EqualsFilter f = new EqualsFilter("cn", cn);
List result = ldapTemplate.search(DistinguishedName.EMPTY_PATH, f
.toString(), new AbstractContextMapper() {
protected Object doMapFromContext(DirContextOperations ctx) {
return ctx.getNameInNamespace();
}
});
if (result.size() != 1) {
throw new RuntimeException("User not found or not unique");
}
return (String) result.get(0);
}
/**
* 根据用户名密码验证
* @param userDn
* @param credentials
* @return
*/
public boolean authenticate(String userDn, String credentials) {
DirContext ctx = null;
try {
ctx = ldapTemplate.getContextSource().getContext(userDn,
credentials);
return true;
} catch (Exception e) {
// Contextcreationfailed-authenticationdidnotsucceed
return false;
} finally {
// ItisimperativethatthecreatedDirContextinstanceisalwaysclosed
LdapUtils.closeContext(ctx);
}
}
分享到:
相关推荐
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 ...
学习SpringSecurity时,看到LDAP认证,不了解LDAP根本无从下手。所以转头学习了一下LDAP,搭建了一个DEMO,仅作记录。 LDAP(Lightweight Directory Access Protocol) 轻量级目录访问协议,LDAP目录以树状的层次结构...
spring ldap的使用
基于springldap的增删改查,以及通过ldap的用户名、密码进行验证
使用spring-ldap-core测试链接ldap com.ldap.test.service包下为Junit测试类
spring ldap 1.3.0的全部jar包下载
rar包:一个Web工程, 主要有,利用Spring-ldap对LDAP的基本操作(查询,增删改);Extjs实现的对Ldap的树状结构的显示,结构有点类似Softerra LDAP;一个测试类。 pdf:spring-ldap-reference.pdf Extjs.pdf ...
SpringLDAP和JNDI增删改查的入门级例子 能够通过编译和运行 已经包含了需要的包,用eclipse导入即可
Spring Data LDAP API。 Spring Data LDAP 开发文档。 官网 Spring Data LDAP API。
spring-ldap1.3.1,一种框架技术用来实现对ldap服务器增删改查数据的工具包。
Spring 实现LDAP 域认证,内有个人项目的实例分析,,希望大家参考,也可以给意见
spring_ldap spring_ldap spring_ldap
spring_ldap1.3的chm格式api
Practical Spring LDAP英文原版
springldap增删改查的源码 适合初学者下载学习 写的很简答 注释中加入了自己写代码遇到的问题解决方案和心得
Spring LDAP is a Java library for simplifying LDAP operations, based on the pattern of Spring's JdbcTemplate. The framework relieves the user of common chores, such as looking up and closing contexts,...
去掉JAR包了。Spring+LDAP实现单点登录SSO 单点登录 LDAP SPRING
最新spring Ldap jar包 The following distinct jar files are included in the distribution. This list specifies the respective contents and third-party dependencies.
NULL 博文链接:https://zhangzhenting.iteye.com/blog/622311