From 4139796afe785e5a3cc00d1be3326acabff02f87 Mon Sep 17 00:00:00 2001 From: monkeyk7 Date: Thu, 4 Jul 2019 19:40:44 +0800 Subject: [PATCH] Add redis config --- pom.xml | 5 +++++ .../sos/config/OAuth2ServerConfiguration.java | 17 +++++++++++++++-- src/main/resources/application.properties | 10 ++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f5471a7..782645b 100644 --- a/pom.xml +++ b/pom.xml @@ -66,6 +66,11 @@ ${spring.security.oauth.version} + + + org.springframework.boot + spring-boot-starter-data-redis + org.springframework.security diff --git a/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java b/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java index df6d17e..4080d76 100644 --- a/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java +++ b/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.http.SessionCreationPolicy; @@ -28,6 +29,7 @@ import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeSe import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory; import org.springframework.security.oauth2.provider.token.TokenStore; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; +import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore; import javax.sql.DataSource; @@ -136,9 +138,20 @@ public class OAuth2ServerConfiguration { } + /* + * JDBC TokenStore + */ +// @Bean +// public TokenStore tokenStore(DataSource dataSource) { +// return new JdbcTokenStore(dataSource); +// } + + /* + * Redis TokenStore + */ @Bean - public TokenStore tokenStore(DataSource dataSource) { - return new JdbcTokenStore(dataSource); + public TokenStore tokenStore(RedisConnectionFactory connectionFactory) { + return new RedisTokenStore(connectionFactory); } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3b9130d..a832593 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -29,3 +29,13 @@ logging.level.root=INFO # # Support deploy to a servlet-container spring.jmx.enabled=false +# +# Redis +# +spring.redis.host=localhost +spring.redis.port=6379 +spring.redis.database=2 +spring.redis.password= +#spring.redis.timeout=2000 +#spring.redis.ssl=false +