LDAP认证的两种方式
[第一种]
、
FastBindLdapAuthenticationHandler
这种认证处理器一般用于DN是由用户名直接组成的,比如:uid=%u,ou=dev,dc=micmiu.com,dc=com ,其中 %u 就是CAS登录的用户名。
修改web的配置文件 WEB-INF\
deployerConfigContext.xml
:
首先在<beans>
跟节点下增加
bean
:
ContextSource
的配置:
- <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
- <property name="pooled" value="false"/>
- <property name="url" value="ldap://127.0.0.1:389" />
- <property name="userDn" value="cn=Manager"/>
- <property name="password" value="secret"/>
- <property name="baseEnvironmentProperties">
- <map>
- <entry key="com.sun.jndi.ldap.connect.timeout" value="3000" />
- <entry key="com.sun.jndi.ldap.read.timeout" value="3000" />
- <entry key="java.naming.security.authentication" value="simple" />
- </map>
- </property>
- </bean>
在<bean id=”authenticationManager” />
下找到
SimpleTestUsernamePasswordAuthenticationHandler
的配置,修改成如下:
- <bean class="org.jasig.cas.adaptors.ldap.FastBindLdapAuthenticationHandler">
- <property name="filter" value="uid=%u,ou=Developer,dc=micmiu,dc=com" />
- <property name="contextSource" ref="contextSource" />
- </bean>
[第二种]
、
BindLdapAuthenticationHandler
这种认证处理器一般用于需要验证的用户名是DN的其他的属性比如email,而不是上面第一种处理器中的uid(当然uid属性同样适用,下面我们配置的示例是用mail)。
修改web的配置文件 WEB-INF\
deployerConfigContext.xml
:
同样在<beans>
跟节点下增加
bean
:
ContextSource
的配置:
- <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
- <property name="anonymousReadOnly" value="false" />
- <property name="password" value="secret" />
- <property name="pooled" value="true" />
- <property name="urls">
- <list>
- <value>ldap://127.0.0.1:389</value>
- </list>
- </property>
- <property name="userDn" value="cn=Manager,dc=micmiu,dc=com" />
- <property name="baseEnvironmentProperties">
- <map>
- <!-- LDAP SSL访问配置
- <entry key="java.naming.security.protocol" value="ssl" />
- -->
- <entry key="java.naming.security.authentication" value="simple" />
- </map>
- </property>
- </bean>
在<bean id=”Manaauthenticationger” />
修改认证
bean
的配置,修改成如下:
- <bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler">
- <property name="filter" value="mail=%u" />
- <property name="searchBase" value="dc=micmiu,dc=com" />
- <property name="contextSource" ref="contextSource" />
- <!-- 允许多个账号-->
- <property name="allowMultipleAccounts" value="true" />
- </bean>