0

I used spring security 3 and I decided to upgrade it to Spring security 4 when I do it I face to a problem. the problem is when I POST my username and password to my custom userDetailService from login form , the username is 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>

and here is my 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"/>

1 Answers1

0

Your encType is incorrect. Spring doesn't support multipart request at the login page by default.

  1. If you dont want the multipart request then just remove it.
  2. If you want multipart support then you have to add multipart filter in your web.xml file. and you need to configure Apache commons multipart resolver.

Please take a look at this spring security multipart

Sangam Belose
  • 4,262
  • 8
  • 26
  • 48