forked from indigo-iam/iam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ways to run external session store with JDBC and store session da…
…ta in separate db
- Loading branch information
1 parent
def2c42
commit b21a4ff
Showing
3 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
iam-login-service/src/main/java/it/infn/mw/iam/config/DataSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
iam-login-service/src/main/resources/application-jdbc-session.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |