On Vaadin's site they state that:
在Vaadin的网站上,他们说:
All requests between the client and the server are included with a user session specific CSRF token
However, I'm unable to fetch this token programmatically. I tried System.out.println(VaadinRequest.getCurrent().getAttribute("_csrf"));
但是,我无法以编程方式获取该令牌。我试过System.out.println(VaadinRequest.getCurrent().getAttribute(“_csrf”));
and
和
System.out.println(VaadinRequest.getCurrent().getHeader("X-CSRF-TOKEN"));
System.out.println(VaadinRequest.getCurrent().getHeader(“X-CSRF-TOKEN”));
In order to somehow see if the request really contains this token. In both cases, the returned value is null
.
为了以某种方式查看请求是否真的包含这个令牌。在这两种情况下,返回值都是null。
In my SecurityConfig.java
, I have disabled the CSRF token, as the Vaadin breaks if it is enabled. I assume that there may be some overlap going on.
在我的SecurityConfig.java中,我禁用了CSRF令牌,因为如果启用了Vaadin,它就会中断。我认为可能会有一些重叠发生。
I also do have SecurityVaadinConfig.java
which is pretty default, as it looks like this:
我也有SecurityVaadinConfig.java,这是非常默认的,如下所示:
@Configuration
@EnableWebSecurity
public class SecurityVaadinConfig extends VaadinWebSecurity {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((auth) -> auth
.requestMatchers(new AntPathRequestMatcher("/**")).permitAll());
super.configure(http);
setLoginView(http, LoginView.class);
}
@Override
protected void configure(WebSecurity web) throws Exception {
super.configure(web);
}
}
How can I ensure that this token is really passed in "all requests between the client and the server"?
我如何才能确保这个令牌真正在“客户端和服务器之间的所有请求”中传递?
更多回答
优秀答案推荐
OK. I found this issue from 2 years ago (https://github.com/vaadin/web-components/issues/201). The CSRF token is passed as a meta tag of page. I was able to retrieve, and ensure myself that CSRF is enabled, CSRF token through UI.getCurrent().getCsrfToken()
.
好的。我在2年前发现了这一期(https://github.com/vaadin/web-components/issues/201).CSRF令牌作为页面的元标记传递。我能够通过UI.getCurrent().getCsrfToken()检索并确保启用了CSRF令牌。
更多回答
我是一名优秀的程序员,十分优秀!