我使用了spring security 3,当我这样做时,我决定将它升级到Spring security 4我遇到问题。问题是当我从登录表单将我的用户名和密码发布到我的自定义userDetailService时,用户名为null。
<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"/>
答案 0 :(得分:0)
您的encType不正确。默认情况下,Spring不支持登录页面上的多部分请求。