【问题标题】:Using Spring, Basic Auth and LDAP, how can I get the supplied username?使用 Spring、Basic Auth 和 LDAP,如何获取提供的用户名?
【发布时间】:2014-07-18 01:03:32
【问题描述】:

我正在使用 Spring Security 针对 LDAP 对用户进行身份验证。我的 bean 配置看起来像这样

<security:http use-expressions="true" > 
    <security:intercept-url pattern="/secure/**" access="isAuthenticated()"/>
    <security:http-basic/>  
</security:http>

<security:authentication-manager>          
    <security:ldap-authentication-provider user-dn-pattern="cn={0},ou=users"/>
</security:authentication-manager>

<security:ldap-server url="${ldap.url}/${ldap.base}" />

这很好用,但现在我想在代码中访问那个 {0} 用户名。我确实让 Jersey 管理服务接口,并且我找到了一些关于创建过滤器和挖掘请求的教程。但是,我希望有一种更简单的方法来实现它,因为 Spring 已经完成了所有工作,并且拥有纯文本的用户名并准备好发送到 LDAP 服务器。

【问题讨论】:

    标签: java spring-security ldap jersey basic-authentication


    【解决方案1】:

    Authenticationauth = SecurityContextHolder.getContext().getAuthentication();

    auth.getName();

    【讨论】:

    • 奇妙吧。谢谢你,先生,这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-23
    • 2022-08-03
    • 2019-01-09
    • 2017-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多