Skip to content

Commit

Permalink
add ways to run external session store with JDBC and store session da…
Browse files Browse the repository at this point in the history
…ta in separate db
  • Loading branch information
DonaldChung-HK committed Aug 15, 2024
1 parent def2c42 commit 9e14814
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package it.infn.mw.iam.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.session.jdbc.config.annotation.SpringSessionDataSource;

import com.zaxxer.hikari.HikariDataSource;

@Configuration
public class DataSourceConfig {
@Bean
@Primary
@ConfigurationProperties("spring.datasource")
@Qualifier("dataSource")
public DataSourceProperties dataSourceProperties() {
return new DataSourceProperties();
}

@Bean
@Primary
public HikariDataSource primaryDataSource(@Qualifier("dataSource") DataSourceProperties dataSourceProperties) {
return dataSourceProperties
.initializeDataSourceBuilder()
.type(HikariDataSource.class)
.build();
}

@Bean
@ConfigurationProperties("session.datasource")
@Qualifier("sessionDataSourceProperties")
@ConditionalOnProperty(name = "spring.session.store-type", havingValue = "jdbc")
public DataSourceProperties sessionDataSourceProperties() {
return new DataSourceProperties();
}
@Bean
@Qualifier("sessionDataSource")
@SpringSessionDataSource
@ConditionalOnProperty(name = "spring.session.store-type", havingValue = "jdbc")
public HikariDataSource sessionDataSource(@Qualifier("sessionDataSourceProperties") DataSourceProperties sessionDataSourceProperties) {
return sessionDataSourceProperties
.initializeDataSourceBuilder()
.type(HikariDataSource.class)
.build();
}
}
11 changes: 11 additions & 0 deletions iam-login-service/src/main/resources/application-jdbc-session.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
spring:
session:
store-type: jdbc
jdbc:
cleanup-cron: 0 */45 * * * *
table-name: SPRING_SESSION
session:
datasource:
url: jdbc:mysql://${IAM_SESSION_DB_HOST:dev.local.io}:${IAM_SESSION_DB_PORT:3306}/${SESSION_DB_NAME:session}?useSSL=${IAM_SESSION_DB_USE_SSL:false}&allowPublicKeyRetrieval=true
username: ${SESSION_DB_USERNAME}
password: ${SESSION_DB_PASSWORD}

0 comments on commit 9e14814

Please sign in to comment.