Я разрабатываю код с пружинной защитой с конфигурацией на основе аннотаций.
Но после нажатия на URL обработки входа в систему, определенный в configure метод WebSecurityConfig Class (которыйрасширяет WebSecurityConfigurerAdapter ) со страницы входа, всегда перенаправляя на .failureHandler () метод httpSecurity вместо .successHandler () , даже если он правильный имя пользователя и пароль .
Ниже приведен метод configure и метод configureGlobal класса WebSecurityConfig .
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.authorizeRequests()
.antMatchers("/login.success").access("hasRole('ROLE_USER')")
.and()
.formLogin()
.loginPage("/login.home")
.usernameParameter("username")
.passwordParameter("password")
.loginProcessingUrl("/login.do")
.successHandler(applicationLoginSuccessHandler)
.failureHandler(applicationLoginFailureHandler)
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"));
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
authenticationManagerBuilder.inMemoryAuthentication().withUser("user").password("pass").roles("USER");
}
здесь приведен фрагмент login.jsp
<c:url value="login.do" var="loginUrl"/>
<form action="${loginUrl}" method="POST">
<c:if test="${param.error != null}">
<p>
Invalid username and password.
</p>
</c:if>
<c:if test="${param.logout != null}">
<p>
You have been logged out.
</p>
</c:if>
<p>
<label for="username">Username</label>
<input type="text" id="username" name="username"/>
</p>
<p>
<label for="password">Password</label>
<input type="password" id="password" name="password"/>
</p>
<input type="hidden"
name="${_csrf.parameterName}"
value="${_csrf.token}"/>
<button type="submit" class="btn">Log in</button>
</form>
Чего мне не хватает?
Я использую Spring Security 5.1.2. Release