From 4139796afe785e5a3cc00d1be3326acabff02f87 Mon Sep 17 00:00:00 2001
From: monkeyk7
Date: Thu, 4 Jul 2019 19:40:44 +0800
Subject: [PATCH 1/6] 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
+
--
Gitee
From ce482add9cc03ee7967232af7553536361b3c81c Mon Sep 17 00:00:00 2001
From: monkeyk7
Date: Thu, 4 Jul 2019 19:56:37 +0800
Subject: [PATCH 2/6] Add redis config
---
.../monkeyk/sos/config/OAuth2ServerConfiguration.java | 9 ++++++++-
src/main/resources/application.properties | 2 +-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java b/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
index 4080d76..a1bd554 100644
--- a/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
+++ b/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
@@ -7,6 +7,7 @@ import com.monkeyk.sos.service.UserService;
import com.monkeyk.sos.web.oauth.OauthUserApprovalHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -131,6 +132,10 @@ public class OAuth2ServerConfiguration {
private AuthenticationManager authenticationManager;
+ @Value("${spring.application.name:sos}")
+ private String applicationName;
+
+
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
@@ -151,7 +156,9 @@ public class OAuth2ServerConfiguration {
*/
@Bean
public TokenStore tokenStore(RedisConnectionFactory connectionFactory) {
- return new RedisTokenStore(connectionFactory);
+ final RedisTokenStore redisTokenStore = new RedisTokenStore(connectionFactory);
+ redisTokenStore.setPrefix(applicationName);
+ return redisTokenStore;
}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index a832593..ed0cf47 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -34,7 +34,7 @@ spring.jmx.enabled=false
#
spring.redis.host=localhost
spring.redis.port=6379
-spring.redis.database=2
+spring.redis.database=0
spring.redis.password=
#spring.redis.timeout=2000
#spring.redis.ssl=false
--
Gitee
From 9d4f3846b8dda2dfffee247b784434326977c5aa Mon Sep 17 00:00:00 2001
From: monkeyk7
Date: Thu, 4 Jul 2019 22:42:11 +0800
Subject: [PATCH 3/6] Update
2.3.4.RELEASE
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 782645b..3d15f7e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,7 +23,7 @@
UTF-8
1.8
- 2.3.0.RELEASE
+ 2.3.4.RELEASE
false
--
Gitee
From 0c07fc986c8a232d7b848235592ad409e0b6da5b Mon Sep 17 00:00:00 2001
From: monkeyk7
Date: Thu, 4 Jul 2019 22:51:55 +0800
Subject: [PATCH 4/6] Update config
---
.../monkeyk/sos/config/OAuth2ServerConfiguration.java | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java b/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
index a1bd554..d6fc674 100644
--- a/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
+++ b/src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
@@ -7,7 +7,6 @@ import com.monkeyk.sos.service.UserService;
import com.monkeyk.sos.web.oauth.OauthUserApprovalHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -29,7 +28,6 @@ import org.springframework.security.oauth2.provider.code.AuthorizationCodeServic
import org.springframework.security.oauth2.provider.code.JdbcAuthorizationCodeServices;
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;
@@ -132,10 +130,6 @@ public class OAuth2ServerConfiguration {
private AuthenticationManager authenticationManager;
- @Value("${spring.application.name:sos}")
- private String applicationName;
-
-
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
@@ -157,7 +151,8 @@ public class OAuth2ServerConfiguration {
@Bean
public TokenStore tokenStore(RedisConnectionFactory connectionFactory) {
final RedisTokenStore redisTokenStore = new RedisTokenStore(connectionFactory);
- redisTokenStore.setPrefix(applicationName);
+ //prefix
+ redisTokenStore.setPrefix(RESOURCE_ID);
return redisTokenStore;
}
--
Gitee
From c8a7a77928af65841d48597071fce0e3ab426228 Mon Sep 17 00:00:00 2001
From: monkeyk7
Date: Thu, 4 Jul 2019 23:00:54 +0800
Subject: [PATCH 5/6] Update readme
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index ebf8579..c30636f 100644
--- a/README.md
+++ b/README.md
@@ -165,7 +165,7 @@ Base on Spring-Boot
增加使用代码生成AccessToken功能
- 增加将AccessToken存入Redis的配置参考
+ 增加将AccessToken存入Redis的配置参考
修改ROLE的错误配置
Use spring-boot 2.0.2.RELEASE
--
Gitee
From 578f2deee89a3090ba7d1c8650d65f5847654b13 Mon Sep 17 00:00:00 2001
From: monkeyk7
Date: Thu, 4 Jul 2019 23:12:14 +0800
Subject: [PATCH 6/6] Update readme
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index c30636f..362b605 100644
--- a/README.md
+++ b/README.md
@@ -166,6 +166,7 @@ Base on Spring-Boot
增加使用代码生成AccessToken功能
增加将AccessToken存入Redis的配置参考
+ 升级Spring Security OAuth版本为2.3.4.RELEASE
修改ROLE的错误配置
Use spring-boot 2.0.2.RELEASE
--
Gitee