Browse Source

!2 token存储支持使用redis

Merge pull request !2 from 李胜钊/config-redis
pull/2/MERGE
monkeyk7 5 years ago committed by Gitee
parent
commit
1b11e86bf9
  1. 3
      README.md
  2. 7
      pom.xml
  3. 21
      src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
  4. 10
      src/main/resources/application.properties

3
README.md

@ -165,7 +165,8 @@ Base on Spring-Boot
</p>
<ol>
<li><p>增加使用代码生成AccessToken功能</p></li>
<li><p>增加将AccessToken存入Redis的配置参考</p></li>
<li><p><del>增加将AccessToken存入Redis的配置参考</del></p></li>
<li><p><del>升级Spring Security OAuth版本为2.3.4.RELEASE</del></p></li>
<li><p><del>修改ROLE的错误配置</del></p></li>
<li><p><del>Use spring-boot 2.0.2.RELEASE</del></p></li>
</ol>

7
pom.xml

@ -23,7 +23,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring.security.oauth.version>2.3.0.RELEASE</spring.security.oauth.version>
<spring.security.oauth.version>2.3.4.RELEASE</spring.security.oauth.version>
<test.skip>false</test.skip>
</properties>
@ -66,6 +66,11 @@
<version>${spring.security.oauth.version}</version>
</dependency>
<!--Redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>

21
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;
@ -27,7 +28,7 @@ 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;
@ -136,9 +137,23 @@ 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) {
final RedisTokenStore redisTokenStore = new RedisTokenStore(connectionFactory);
//prefix
redisTokenStore.setPrefix(RESOURCE_ID);
return redisTokenStore;
}

10
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=0
spring.redis.password=
#spring.redis.timeout=2000
#spring.redis.ssl=false

Loading…
Cancel
Save