Spring LDAP身份验证后引用用户名

时间:2012-08-30 08:54:43

标签: spring-security spring-ldap

  

可能重复:
  When using Spring Security, what is the proper way to obtain current username (i.e. SecurityContext) information in a bean?
  spring security how to retrieve username

我使用spring ldap来验证我的网络应用

<ldap-server id="sss" port="389"
             url="ldap://ldap.example.com:389/ou=active,ou=employees,ou=people,o=example.com?uid?sub"/>

<authentication-manager alias="authenticationManager">
    <ldap-authentication-provider
            server-ref="sss"
            role-prefix="ROLE_">
    </ldap-authentication-provider>
</authentication-manager>

它有效,但我不知道如何在登录页面中填写用户名,因为我想在页面顶部显示它。

感谢。

1 个答案:

答案 0 :(得分:5)

我发现了这个:

SecurityContextHolder.getContext().getAuthentication().getPrincipal()

返回搜索条目。