Hello, when creating your own login form, a problem arose: when you try to log in, an error appears with the message bad credentials (although if you log in through the form, everything passes)

web.xml

<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> </filter-mapping> <security:http pattern="/admin/**" use-expressions="true" name="securityFilterChain" create-session="stateless"> <security:http-basic/> <security:intercept-url pattern="/**" access="hasRole('ADMIN')" /> </security:http> <security:http use-expressions="true"> <security:intercept-url pattern="/login" access="permitAll()"/> <security:intercept-url pattern="/**" access="isAuthenticated()"/> <security:form-login login-page="/login" default-target-url="/restaurants" authentication-failure-url="/login?error=true" login-processing-url="/spring_security_check"/> <security:logout logout-success-url="/login"/> </security:http> <security:authentication-manager> <security:authentication-provider> <security:user-service> <security:user name="anatoly@mail.ru" password="pastol" authorities="ADMIN"/> </security:user-service> <!--<security:jdbc-user-service data-source-ref="dataSource" users-by-username-query="SELECT email, password FROM users WHERE email = ?" authorities-by-username-query="SELECT u.email, r.role FROM users u, roles r WHERE u.id=r.userid AND u.email = ?"/>--> </security:authentication-provider> </security:authentication-manager> 


Login form

  <form:form class="navbar-form navbar-right" role="form" action="spring_security_check" method="post"> <div class="form-group"> <input type="text" placeholder="Email" class="form-control" name='username'> </div> <div class="form-group"> <input type="password" placeholder="Password" class="form-control" name='password'> </div> <button type="submit" class="btn btn-success">Войти</button> </form:form> 

    1 answer 1

    You did not specify field names in the input form.

     <security:form-login login-page="/login" default-target-url="/restaurants" authentication-failure-url="/login?error=true" username-parameter="username" password-parameter="password" /> 

    Secondly, why a login-processing-url ? When specifying this parameter, a method with this URL is needed, which will process this request. What for? You can also use the standard. Actually, the error is precisely because there is no this URL.

     <c:url var="loginUrl" value="/login" /> <form action="${loginUrl}" method="post"> 

    Third, if you have Spring Security 4, pay attention to my answer .

    Good luck!