使用Vaadin 10进行java自定义Spring安全登录
我试图在使用spring boot的同时使用Vaadin,我也在使用spring security。这是我在WebSecurityConfigurerAdapter
类中完成的配置
@Override
protected void configure(final HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/VAADIN/**", "/PUSH/**", "/UIDL/**", "/login", "/login/**", "/error/**", "/accessDenied/**", "/vaadinServlet/**","/myui/**","/test/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().permitAll().defaultSuccessUrl("/myui", true).and()
.sessionManagement().sessionAuthenticationStrategy(sessionControlAuthenticationStrategy());
}
这是我的登录视图
@Route("login")
@Theme(value = Lumo.class, variant = Lumo.DARK)
public class LoginForm extends Div {
public LoginForm(){
init();
}
public void init(){
FormLayout nameLayout = new FormLayout();
TextField username = new TextField();
username.setLabel("UserName");
username.setPlaceholder("username");
PasswordField passwordField = new PasswordField();
passwordField.setLabel("password");
passwordField.setPlaceholder("*****");
Button loginButton = new Button("login");
loginButton.addClickListener(event -> {
});
nameLayout.add(username,passwordField);
add(nameLayout);
}
}
我遇到的问题是,当用户被重定向到/login
时,我总是看到一个空页面,但在检查Html页面后,我可以看到有vaadin元素,但它们没有出现在浏览器中
# 1 楼答案
在将web配置更改为该配置后,我能够修复该问题
# 2 楼答案
这是我的工作配置:
所有请求都会重定向到登录视图,直到通过身份验证。到目前为止,我没有尝试
@Push
,因此可能需要额外的URL才能始终被允许使用Firefox开发者工具,您可以在控制台中检查XHR调用。如果任何XHR调用因403或其他原因失败,您可能需要调整安全配置