我们使用的是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.html
和IndexController
。在IndexController
中,我想要获取用于失败的登录尝试的username
。我该怎么做呢?
https://stackoverflow.com/questions/8676206
复制相似问题