嗨,我是 Spring 安全的新手,
我的任务是通过匹配从 x509 客户端证书中检索到的用户名来针对活动目录对用户进行身份验证。到目前为止,我所做的是启用 ssl 相互身份验证
上面的部分工作正常,现在我有 security.xml 文件,我在其中配置了与 x509 参考和 Active Directory 配置相关的所有内容
<global-method-security secured-annotations="enabled" />
<http >
<intercept-url pattern="/**" access="ROLE_USER,ROLE_ANONYMOUS" requires- channel="https"/>
<intercept-url pattern="/UserLogin/*" access="ROLE_ADMIN,ROLE_USER" requires-channel="https"/>
<x509 subject-principal-regex="CN=(.*?)," user-service-ref="ldapUserService" />
</http>
<authentication-manager>
<authentication-provider user-service-ref="ldapUserService" />
</authentication-manager>
<bean:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<bean:constructor-arg value="ldap://ActiveDirectoryURL:389/CN=example,DC=net"/>
<bean:property name="userDn" value="mkanaka@example.local"/>
<bean:property name="password" value="secuera1SMK"/>
</bean:bean>
<bean:bean name="ldapUserService" class="org.springframework.security.ldap.userdetails.LdapUserDetailsService">
<bean:constructor-arg ref="ldapUserSearch"/>
<bean:constructor-arg ref="ldapAuthoritiesPopulator"/>
</bean:bean>
<bean:bean name="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<bean:constructor-arg value=""/>
<bean:constructor-arg value="(&(sAMAccountName={0})(objectclass=Users))"/>
<bean:constructor-arg ref="contextSource" />
</bean:bean>
<bean:bean name="ldapAuthoritiesPopulator"
class="org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator">
<bean:constructor-arg ref="contextSource" />
<bean:constructor-arg value="" />
<bean:property name="groupSearchFilter" value="member={0}" />
<bean:property name="searchSubtree" value="true" />
</bean:bean>
现在我面临的问题是当我尝试检索 SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 它的返回类型是字符串而不是 userDetails(记录时使用的证书详细信息), getPrincipal() 的字符串输出是anonymousUser并且它给出的权限是ROLE_ANONYMOUS但是当我调用 getAuthentication.isAuthenticated() 它返回true。我正在使用tomcat 7,Spring security 3.1
可能是什么问题请在这方面帮助我