ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Spring LDAP Context.REFERRAL遵循

2019-11-20 06:19:29  阅读:525  来源: 互联网

标签:active-directory ldap spring-security spring


如何在Spring Security配置中设置要遵循的LDAP Context.REFERRAL?这与我已经报告过的问题有关,在发现我要寻找的真正解决方案之前,我发现了一个不令人满意的解决方案,其中涉及在LDAP上下文中设置此环境属性以遵循ActiveDirectoryLdapAuthenticationProvider的引用.

这是我原始问题的参考:Spring Security 4.0.0 + ActiveDirectoryLdapAuthenticationProvider + BadCredentialsException PartialResultException

附录:这里似乎没有人有这样的环境.尽管在此问题上保持沉默,但我在这里发布了我的配置,希望有人能够对此提供帮助.我只是不知道该怎么办才能解决这个问题.

这是我的日志中的错误消息:

2015-06-15 10:32:19,810 DEBUG (o.s.s.w.FilterChainProxy$VirtualFilterChain.doFilter) [http-8443-1] /identite.proc at position 7 of 13 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2015-06-15 10:32:19,810 DEBUG (o.s.s.w.u.m.AntPathRequestMatcher.matches) [http-8443-1] Checking match of request : '/identite.proc'; against '/identite.proc'
2015-06-15 10:32:19,810 DEBUG (o.s.s.w.a.AbstractAuthenticationProcessingFilter.doFilter) [http-8443-1] Request is to process authentication
2015-06-15 10:32:19,811 DEBUG (o.s.s.a.ProviderManager.authenticate) [http-8443-1] Authentication attempt using org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider
2015-06-15 10:32:19,811 DEBUG (o.s.s.l.a.AbstractLdapAuthenticationProvider.authenticate) [http-8443-1] Processing authentication request for user: myusername
2015-06-15 10:32:19,841 DEBUG (o.s.s.l.SpringSecurityLdapTemplate.searchForSingleEntryInternal) [http-8443-1] Searching for entry under DN '', base = 'dc=dept,dc=company,dc=com', filter = '(&(userPrincipalName={0})(objectClass=user)(objectCategory=inetOrgPerson))'
2015-06-15 10:32:19,842 DEBUG (o.s.s.w.a.AbstractAuthenticationProcessingFilter.unsuccessfulAuthentication) [http-8443-1] Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
2015-06-15 10:32:19,842 DEBUG (o.s.s.w.a.AbstractAuthenticationProcessingFilter.unsuccessfulAuthentication) [http-8443-1] Updated SecurityContextHolder to contain null Authentication
2015-06-15 10:32:19,842 DEBUG (o.s.s.w.a.AbstractAuthenticationProcessingFilter.unsuccessfulAuthentication) [http-8443-1] Delegating to authentication failure handler org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler@a5d7f2

这是配置:

<b:bean id="monFournisseurAD" class="org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider">
    <b:constructor-arg value="dept.company.com" />
    <b:constructor-arg value="ldap://dept.company.com:3268/" />
    <b:constructor-arg value="dc=dept,dc=company,dc=com" />
    <b:property name="searchFilter" value="(&amp;(userPrincipalName={0})(objectClass=user)(objectCategory=inetOrgPerson))" />
    <b:property name="userDetailsContextMapper">
        <b:bean class="org.springframework.security.ldap.userdetails.InetOrgPersonContextMapper" />
    </b:property>
    <b:property name="authoritiesMapper" ref="grantedAuthoritiesMapper" />
    <b:property name="convertSubErrorCodesToExceptions" value="true" />
</b:bean>

<b:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <b:constructor-arg value="ldap://dept.company.com:3268/dc=dept,dc=company,dc=com" />
    <b:property name="baseEnvironmentProperties">
        <b:map>
            <b:entry key="java.naming.referral" value="follow" />
        </b:map>
    </b:property>
</b:bean>

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

<b:bean id="securityContextPersistenceFilter" class="org.springframework.security.web.context.SecurityContextPersistenceFilter" />
<b:bean id="myDeconnexionHandler" class="com.company.dept.web.my.DeconnexionHandler" />

具有ids contextSource和ldapTemplate的两个bean似乎什么都没有改变.我试图获得推荐跟随行为.这似乎不是配置它的正确方法.另外,这里ldap URL中的端口设置为3268,因为它是常规目录,并且在其他说明中的某个人建议使用该端口.但是,结果与端口389完全相同.

如果我更改bean monFournisseurAD中的第一个构造函数参数以将其设置为单个userPrincipalName域,它将对进入该域的所有用户起作用.虽然我实际上可以使用ldapsearch命令从命令行使用dept.company.com验证任何人,而不是直接与用户关联的userPrincipalName域.实际上,如果我输入了错误的密码,则会收到特定的错误密码消息.这似乎证明该用户实际上已通过AD / LDAP身份验证,但是Spring稍后无法获取该用户的属性.

我怎么解决这个问题?

解决方法:

最后,解决此问题的唯一方法是修改代码,因为方法org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider.searchForUser()已连接为将bindPrincipal传递给SpringSecurityLdapTemplate.searchForSingleEntryInternal(),从而实际恢复了使用XML中定义的搜索过滤器或通过setSearchFilter()设置为用户记录.由于bindPrincipal实际上是username @ domain,因此该值不适用于搜索过滤器中的sAMAccountName,它将始终失败.由于使用userPrincipalName绑定到Active Directory服务器,然后使用bindPrincipal绑定,因此您无法指定到searchForUser(),因此必须仅在搜索中使用用户名,而不使用bindPrincipal(UPN).我通过复制包中的整个类org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider来解决问题,并修改了searchForUser()方法以将用户名而不是bindPrincipal传递给方法searchForSingleEntryInternal().这可行,但是仍然是有线/硬编码解决方案.一个更优雅的解决方案是引入模式列表和一种方法,以构成对searchForSingleEntryInternal()的调用的值,或者一种方法,该方法将检测searchFilter()字符串所需的参数类型.

标签:active-directory,ldap,spring-security,spring
来源: https://codeday.me/bug/20191120/2042040.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有