0

我刚刚开始深入研究 Vaadin UI 开发,如有任何愚蠢的错误,请见谅。有人可以帮忙吗?

我构建了一个简单的 sbring-boot 应用程序,它将 spring-security 用于基于 ldap 的身份验证,将 vaadin 用于 ui。它有 2 个页面:登录屏幕和主页。

WebSecurityConfig.java

@EnableWebSecurity
public class WebSecurityConfig extends VaadinWebSecurityConfigurerAdapter {
    @Autowired
    LdapDatasource ldapDatasource;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        setLoginView(http, LoginScreen.class);
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/img/**");
        super.configure(web);
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        var provider = ldapDatasource.createAuthProvider();
        auth.authenticationProvider(provider);
    }

}

AppShell.java

@Theme(themeClass = Lumo.class, variant = Lumo.LIGHT)
public class AppShell implements AppShellConfigurator {
}

Application.java

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

build.gradle

plugins {
    id 'org.springframework.boot' version '2.6.0'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
    id 'idea'
    id 'war'
    id 'com.vaadin' version "$vaadinVersion"
}

group = 'com.sample'
version = '0.0.1-SNAPSHOT'

repositories {
    mavenCentral()
    maven { url = "https://maven.vaadin.com/vaadin-addons" }
}

dependencies {
    implementation 'com.vaadin:vaadin-spring-boot-starter'
    implementation 'dev.mett.vaadin:tooltip:2.2.0'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'

    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.security:spring-security-ldap'

    implementation 'org.springframework.session:spring-session-jdbc:2.4.2'
    implementation 'org.postgresql:postgresql:42.3.1'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
}

dependencyManagement {
    imports {
        mavenBom "com.vaadin:vaadin-bom:$vaadinVersion"
        mavenBom 'org.springframework.session:spring-session-bom:2020.0.3'
    }
}


vaadin {
    optimizeBundle = false
    //productionMode = true
}


compileJava {
    options.encoding = 'UTF-8'
}

test {
    useJUnitPlatform()
}

application.properties是空的。

主页有注释:

@Route("")
@PageTitle("Main page")
@PermitAll

登录页面有注释:

@Route("login")
@PageTitle("Login")

此时一切正常。应用程序自动重定向到登录页面未经授权的用户。显示自定义 vaadin 登录页面。通过 ldap 登录非常顺利。登录后,应用程序进入主页面。

但是,一旦我尝试将会话信息存储在 PostgreSQL 数据库中,并添加PostgresConfig.java具有以下内容的文件:

@EnableJdbcHttpSession
public class PostgresConfig {

    @Bean
    public DataSource dataSource() {
        var ds = new PGSimpleDataSource();
        ds.setUrl("jdbc:postgresql://localhost:5432/sample");
        ds.setUser("postgres");
        ds.setPassword("1111");

        return ds;
    }

    @Bean
    public PlatformTransactionManager transactionManager(DataSource dataSource) {
        return new DataSourceTransactionManager(dataSource);
    }
}

vaadin 在应用程序启动后开始无休止地重新加载登录页面。

我试图禁用 vaadin 登录页面,更改:

public class WebSecurityConfig extends VaadinWebSecurityConfigurerAdapter

public class WebSecurityConfig extends WebSecurityConfigurerAdapter

然后标准的spring-security登录页面打开正常,我可以登录。我在我的 postgres 数据库中看到了会话。但是当我登录时,主页会出现“连接丢失”并且永远不会加载。

在无休止的重新加载期间,它在整个项目中没有任何意义,除了每个页面加载AppShell的 'configurePage方法。

我已经设法从开发控制台捕获 Web 请求,每次重新加载页面都会发生这种情况: 在此处输入图像描述

在那一堆请求之后,它一直在重新加载。谷歌没有这样的问题,我认为重新加载发生在 spring/vaadin 请求过滤器或 js 中的某个地方。

什么会导致这种行为?

4

0 回答 0