Привет, я новичок в Spring security, я использую приведенный пример here от Mkyong , я использую пример, основанный на аннотации, представленный в этом учебном курсе, но он всегда через исключение, когда я ввожу значение в форму входа и нажимаю кнопку отправки, как показано ниже.Ошибка HTTP-статуса 403 - Недопустимый токен CSRF «null» был найден в параметре запроса «_csrf» или в заголовке «X-CSRF-TOKEN»
type Status report
message Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-CSRF-TOKEN'.
description Access to the specified resource has been forbidden.
Я попробовал Google, но не нашел подходящего ответа, который решает эту проблему. класс конфигурации безопасности приведен ниже.
SecurityConfig.java
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Qualifier("authenticationProvider")
AuthenticationProvider authenticationProvider;
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/admin/**")
.access("hasRole('ROLE_USER')").and().formLogin()
.loginPage("/login").failureUrl("/login?error")
.usernameParameter("username")
.passwordParameter("password")
.and().logout().logoutSuccessUrl("/login?logout").and().csrf();
}
}
и
форма login.jsp ниже
<form name='loginForm'
action="<c:url value='/login'/>" method='POST' enctype="multipart/form-data">
<table>
<tr>
<td>User:</td>
<td><input type='text' name='username'></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password' /></td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" /></td>
</tr>
</table>
<input type="hidden" name="${_csrf.parameterName}"
value="${_csrf.token}" />
</form>
Пожалуйста, помогите мне выйти из этого проблемы.
показать свой web.xml в вопросе –