Reputation: 131
I've just started to dive into Vaadin UI development, please excuse me in case of any silly mistakes. Can someone please help?
I built a simple sbring-boot application, that uses spring-security for ldap based auth and vaadin for ui. It has 2 pages: login screen and main page.
The WebSecurityConfig.java
is:
@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);
}
}
The AppShell.java
is:
@Theme(themeClass = Lumo.class, variant = Lumo.LIGHT)
public class AppShell implements AppShellConfigurator {
}
The Application.java
is:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
The build.gradle
is:
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
is empty.
Main page has annotations:
@Route("")
@PageTitle("Main page")
@PermitAll
And login page has annotation:
@Route("login")
@PageTitle("Login")
Everything works fine at this point. App automatically redirects to login page unauthorized users. Custom vaadin login page is displayed. Login through ldap goes completely well. And after login, app proceeds to main page.
But as soon as i try to store session information in PostgreSQL database, with adding file PostgresConfig.java
with following contents:
@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 starts endless reloading of login page after app startup.
I've tried to disable vaadin login page, changing:
public class WebSecurityConfig extends VaadinWebSecurityConfigurerAdapter
to
public class WebSecurityConfig extends WebSecurityConfigurerAdapter
and then standard spring-security login page opens fine and i can login. I see session in my postgres database. But when i login, main page goes "Connection lost" and never loads.
There is no point in entire project it reaches during endless reload, except AppShell
's configurePage
method on every page load.
And i've managed to capture web requests from development console, which happens every page reload:
After that bunch of requests it goes reload all the time. There is no such problem out in google, and reload happens somewhere inside spring/vaadin request filters or in js in my opinion.
What can lead to this behavior?
Upvotes: 5
Views: 686