Spring Security:表单登录特殊字符 [英] Spring security: Form login special characters

查看:373
本文介绍了Spring Security:表单登录特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Spring Security表单登录时,我需要有关问题的帮助.表单登录名将带有转义特殊字符的用户名发送到服务器,但不会取消转义此参数并且在数据库中找不到用户.

I need help with problem when using spring security form login. The form login send username with escape special characters to server but spring not unescape this parameters and not found user in database.

我正在使用自定义UserDetailsS​​ervice,但是带用户名的参数包含换码符.可能是unescape特殊字符吗?

I'm uses custom UserDetailsService but the parameter with username contains scape special characters. It's possible unescape special characters?

我正在尝试对特殊字符进行转义,但更改失败.

i'm trying unescape special characters but fail in changes.

数据: -春天3.1.1发布 -Spring Security 3.1.1.RELEASE -Tomcat 7.X

Data: - Spring 3.1.1.RELEASE - Spring Security 3.1.1.RELEASE - Tomcat 7.X

我认为通过在web.xml文件中放置编码过滤器可以解决问题.

I think what the problem is solved by put enconding filter in web.xml file.

<filter>
    <filter-name>encodingFilter</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>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

推荐答案

您不必做任何复杂的事情,只需使用std spring设置

You shouldn't have to do anythign complex, just use the std spring set up

 <form name="f" id="f" action="<c:url value='/j_spring_security_check'/>" method="POST">
   <label for="j_username">E-mail :&nbsp;</label><input type='text' id='j_username' name='j_username'/><br/>
   <label for="j_password">Password :&nbsp;</label><input type='password' id='j_password' name='j_password'><br>

这篇关于Spring Security:表单登录特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆