首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用spring security从失败的登录中获取用户名?

如何使用spring security从失败的登录中获取用户名?
EN

Stack Overflow用户
提问于 2011-12-30 12:36:46
回答 7查看 24.4K关注 0票数 26

我们使用的是spring security 3.0.5,Java 1.6和Tomcat 6.0.32。在我们的.xml配置文件中,我们有:

<form-login login-page="/index.html" default-target-url="/postSignin.html" always-use-default-target="true"
 authentication-failure-handler-ref="authenticationFailureHandler"/>

我们的authenticationFailureHandler定义为:

<beans:bean id="authenticationFailureHandler" class="org.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandler">
   <beans:property name="exceptionMappings">
      <beans:props>
    <beans:prop key="org.springframework.security.authentication.BadCredentialsException">/index.html?authenticationFailure=true</beans:prop>
    </beans:props>
   </beans:property>
</beans:bean>

Java

    @RequestMapping(params={"authenticationFailure=true"}, value ="/index.html")
    public String handleInvalidLogin(HttpServletRequest request) {
       //...  How can I get the username that was used???
       // I've tried:
       Object username = request.getAttribute("SPRING_SECURITY_LAST_USERNAME_KEY");
       Object username = request.getAttribute("SPRING_SECURITY_LAST_USERNAME");  // deprecated
    }

因此,我们将所有BadCredentialsExceptions定向到index.htmlIndexController。在IndexController中,我想要获取用于失败的登录尝试的username。我该怎么做呢?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8676206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档