У меня есть приложение Spring Boot с настройкой java. Я только ссылаюсь на spring-boot-starter-jade4j и spring-boot-starter-security в моем файле build.gradle. Я пытаюсь понять, почему я не могу получить токен csrf. Вот мой SecurityConfigspring boot csrf и jade
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource ds;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/signup", "/js/**", "/css/**", "/terms", "/privacy", "/favicon.ico").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.permitAll()
.and()
.csrf();
}
…
}
Вот моя форма Войти. Скрытое поле CSRF отображается в исходном коде, но токен csrf, похоже, не оценивается, и значение пусто.
extends _base
block head
block body
#bodContent.container-fluid
.row
.col-md-4
.col-md-4
br
.panel.panel-default
.panel-body
h1 Please log in
form(method="POST", action="/login")
input(type="hidden", name='_csrf', value='#{_csrf}')
.form-group
label(for="email")
| Email address
input#username.form-control(name="username", type="email", value="")
.form-group
label(for="password")
| Password
input#password.form-control(name="password", type="password", value="")
.checkbox
label
input(type="checkbox")
| Remember me
input.btn.btn-default(type="submit")
| Submit
.col-md-4
Вы пробовали использовать 'input (type =" hidden ", name = '# {_ csrf.parameterName}, value =' # {_ csrf.token} ')' как указано в [официальной документации] (http: // docs.spring.io/spring-security/site/docs/4.0.1.RELEASE/reference/htmlsingle/#csrf-include-csrf-token-form)? – manish
Все эти: # {_} csrf.parameterName # {_} csrf.token # {_} csrf.value # {_ CSRF} – mugua