Spring + LDAP
来源:互联网 发布:php调取数据库 编辑:程序博客网 时间:2024/05/22 23:49
这两天做了一个日报系统,是用LDAP实现登录的,现把一些重要的地方记录如下:
1.Spring xml配置:
<bean id="ldapContextSource" class="org.springframework.ldap.core.support.LdapContextSource"><property name="referral" value="follow"></property><property name="url" value="ldap://127.0.0.1:389" /><!-- --><property name="base" value="ou=user,dc=cq,dc=cst,dc=com" /><property name="userDn" value="cn=Manager,dc=cst,dc=com" /><property name="password" value="secret" /><property name="baseEnvironmentProperties"><map><entry key="java.naming.security.authentication" value="simple" /></map></property></bean><bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate"><property name="contextSource" ref="ldapContextSource" /></bean>
注意:base:"ou=user,dc=cq,dc=cst,dc=com"的顺序,它是从右到左的,我们操作的是user这个节点下的数据;
2.LDAP用户的登录校验:
/** * LDAP的登录 * @param userId * @param password * @return */ public boolean authUser(String userId, String password) { boolean flag = false; try {flag =ldapTemplate.authenticate("", "(uid="+userId+")",password);} catch (Exception e) {} return flag; }
3.用户信息查询
public User find(String username) { String rdn = ("uid="+username); return (User)ldapTemplate.lookup(rdn, new UserAttributesMapper()); } /** * 根据用户名查询用户信息 * @author Administrator * */ private class UserAttributesMapper implements AttributesMapper { public Object mapFromAttributes(Attributes attrs) throws NamingException { User user = new User(); if(attrs.get("displayName")!=null){ Object displayName = attrs.get("displayName").get(); user.setDisplayName(displayName.toString()); } if(attrs.get("uid")!=null){ Object uid = attrs.get("uid").get(); user.setUsername(uid.toString()); } if(attrs.get("title")!=null){ Object title = attrs.get("title").get(); user.setTitle(title.toString()); } return user; } }
0 0
- Spring-ldap 操作LDAP
- Spring-ldap 操作LDAP
- Spring-ldap 操作LDAP
- Spring-ldap 操作LDAP
- spring-ldap
- Spring Ldap
- Spring LDAP
- Spring + LDAP
- LDAP用户验证(Spring-LDAP)
- LDAP用户验证(Spring-LDAP)
- LDAP用户验证(Spring-LDAP)
- spring security LDAP 认证
- Spring LDAP学习
- Spring Ldap 域认证
- spring ldap demo
- spring mvc+ldap
- Spring-ldap Filter
- Spring Ldap 分页
- 【unity3d开发】unity接入unity Ads详细流程
- java基础四:运算符
- 欢迎使用CSDN-markdown编辑器
- $(@:_config=)什么意思?
- C源文件到可执行文件的过程
- Spring + LDAP
- 常见数据库Oracle,sqlserver,mysql字段类型与java.sql.Types的对应
- Android 存储
- 欢迎使用CSDN-markdown编辑器
- svn 命令
- HTTP协议详解与报文解析
- jQuery插件之ajaxFileUpload
- Mysql语句
- 使用信号量进行同步的共享内存机制