【问题标题】:username null in spring security 4春季安全4中的用户名null
【发布时间】:2018-01-14 14:27:17
【问题描述】:

我使用了 Spring Security 3,我决定将其升级到 Spring Security 4,当我遇到问题时。问题是当我从登录表单将用户名和密码发布到我的自定义 userDetailService 时,用户名为空。

<form action="<c:url value='/j_spring_security_check' />"  
    method='POST' id="login-form1" class="smart-form client-form" enctype="multipart/form-data" >
.
.
.
<section>
    <label class="label">email</label>
    <label class="input"> <i class="icon-append fa fa-user"></i>
    <input type="text" name="username" id="username" data-parsley-trigger="change" required="">
    <b class="tooltip tooltip-top-right"><i class="fa fa-user txt-color-teal"></i> enter email</b></label>
</section>
<section>
    <label class="label">password</label>
    <label class="input"> <i class="icon-append fa fa-lock"></i>
    <input type="password" name="password" id="password">
    <b class="tooltip tooltip-top-right"><i class="fa fa-lock txt-color-teal"></i> password</b> </label>
    <div class="note">
        <a href="forgotpassword.html">forgot password</a>
    </div>
</section>

这是我的 spring-security.xml

    <security:intercept-url pattern="/view/login.jsp*" access="permitAll" />

    <security:intercept-url pattern="/view/**" access="hasRole('ROLE_USER')" />
    <security:intercept-url pattern="/rest/**" access="hasRole('ROLE_USER')" />
    <security:form-login login-page="/view/login.jsp"
                login-processing-url="/j_spring_security_check"
                default-target-url="/view/homepage.jsp"
                password-parameter="password"
                username-parameter="username"/>

【问题讨论】:

    标签: spring security


    【解决方案1】:

    您的 encType 不正确。 Spring 默认不支持登录页面的多部分请求。

    1. 如果您不想要多部分请求,则只需将其删除。
    2. 如果您想要多部分支持,则必须在 web.xml 文件中添加多部分过滤器。并且您需要配置 Apache commons 多部分解析器。

    请看一下这个spring security multipart

    【讨论】:

    • 不客气。你选择了什么选项?如果它解决了您的问题,最终也会接受答案。
    猜你喜欢
    • 2014-04-08
    • 2013-12-22
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    相关资源
    最近更新 更多