-
Notifications
You must be signed in to change notification settings - Fork 44
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 e7c4bac
Showing
3 changed files
with
100 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
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
# | ||
# Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2016-2021 | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
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} |