如何使用 Spring Ldap 身份验证 [英] How to use Spring Ldap Authentication

查看:45
本文介绍了如何使用 Spring Ldap 身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我当前的项目中,我必须实现 LDAP 身份验证.我正在使用 JSF 2.2、primefaces 和 Spring 4.0 以及 spring-ldap-core 1.3.2 和 spring-security-ldap-3.2.0.以下是我到目前为止所做的工作:

In my current project, I have to implement LDAP authentication. I am using JSF 2.2, primefaces and Spring 4.0 and spring-ldap-core 1.3.2 and spring-security-ldap-3.2.0. Below are the work till now I have done to achieve:

Spring-Ldap.xml

Spring-Ldap.xml

<bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">
 <property name="url" value="ldap://mumcXXXXXXX" />
 <property name="base" value="dc=ad,dc=XXX,dc=com"/>
 <property name="userDn" value="XXXX@ad.XXX.com" />
 <property name="password" value="XXXX" />
 </bean>

 <bean id="ldapTemplate" class="org.springframework.ldap.core.LdapTemplate">
    <constructor-arg ref="contextSource" />
</bean>

<bean id="ldapContact"
    class="com.csap.research.LDAPContactDAO">
    <property name="ldapTemplate" ref="ldapTemplate" />
</bean>

我的 LdapContactDao

My LdapContactDao

public boolean login(String username, String password) {
        AndFilter filter = new AndFilter();
        ldapTemplate.setIgnorePartialResultException(true); 
        filter.and(new EqualsFilter("userPrincipalName", username+"@ad.cXXX.com"));
        return ldapTemplate.authenticate("", filter.toString(), password);
}

这里的用户名和密码来自登录屏幕作为输入.我的问题是它的硬编码.我不想在 Spring-Ldap.xml 中硬编码 usernamepassword ,所以这里建议使用 Spring-security-Ldap Spring LdapAuthentication 并从本地数据库加载角色 但我无法明白了.

Here username and password are coming from Login screen as inputs. My problem is its very hardcoded. I dont want to hardcode username and password in Spring-Ldap.xml , So there was a suggestion to use Spring-security-Ldap here Spring LdapAuthentication and Load roles from local database but I was unable to understand it.

我的问题是如何实现 Ldap 与我用作前端控制器的 spring 和 corse JSF 的动态集成.任何帮助都会很棒.

My question was how I can achieve dynamic integration of Ldap with spring and corse JSF i am using as a front-end controller. Any help would be great.

推荐答案

我发现这些文章有助于使用 Spring Security 设置登录表单,但是它们不使用 jsf:

I found these article helpful for setting up login form with spring security, however, they do not use jsf:

http://www.mkyong.com/spring-security/spring-security-hello-world-example/http://www.mkyong.com/spring-security/spring-security-form-login-example/

发现这篇文章对使用ldap作为身份验证提供者很有帮助,它没有使用ldapTemplate,而是使用spring-security配置(文章中的spring-security.xml)

and found this article helpful for using ldap as authentication provider, it does not use ldapTemplate, but uses the spring-security configurations (spring-security.xml in the article)

http://krams915.blogspot.com/2011/01/spring-security-mvc-using-ldap.html

这篇关于如何使用 Spring Ldap 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆