我正在使用spring security 3.2.6.RELEASE,我已经实现了自己的自定义身份验证提供程序,以便处理不同类型的失败登录。我需要在用户名中启用特殊字符。但是,我无法将其付诸实践。
这是我的登录表单:
<form method="POST" action="<c:url value='j_spring_security_check'/>" accept-charset="utf-8" enctype="application/x-www-form-urlencoded">
<!-- Table -->
<table class="table">
<tr>
<td><msg:message code="label.username"/></td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td><msg:message code="label.password"/></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
我还在我的web.xml中包含了org.springframework.web.filter.CharacterEncodingFilter,如下所示:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<servlet-name>/*</servlet-name>
</filter-mapping>
就在弹簧安全过滤器之前:
<!-- spring security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
那我在这里错过了什么?登录页面是utf-8编码的,当我查看FF Developers Tools / Firebug时,用户名参数就会正确发送 - userä。在我的CustomAuthenticationProvider中进行调试:
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
UsernamePasswordAuthenticationToken token = null;
UsernamePasswordAuthenticationToken auth = (UsernamePasswordAuthenticationToken) authentication;
// credentials given by the user
String username = (String)auth.getPrincipal();
String password = (String)auth.getCredentials();
我看到用户名为“userä”,登录失败。
谢谢大家的帮助! 人
答案 0 :(得分:3)
<servlet-name>/*</servlet-name>
应该是
<url-pattern>/*</url-pattern>
现在可行。