Browse Source

Add redis config

pull/2/head
monkeyk7 5 years ago
parent
commit
4139796afe
  1. 5
      pom.xml
  2. 17
      src/main/java/com/monkeyk/sos/config/OAuth2ServerConfiguration.java
  3. 10
      src/main/resources/application.properties

5
pom.xml

@ -66,6 +66,11 @@
<version>${spring.security.oauth.version}</version> <version>${spring.security.oauth.version}</version>
</dependency> </dependency>
<!--Redis-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.security</groupId> <groupId>org.springframework.security</groupId>

17
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.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.http.SessionCreationPolicy; 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.request.DefaultOAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.TokenStore; 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.JdbcTokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
import javax.sql.DataSource; 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 @Bean
public TokenStore tokenStore(DataSource dataSource) { public TokenStore tokenStore(RedisConnectionFactory connectionFactory) {
return new JdbcTokenStore(dataSource); return new RedisTokenStore(connectionFactory);
} }

10
src/main/resources/application.properties

@ -29,3 +29,13 @@ logging.level.root=INFO
# #
# Support deploy to a servlet-container # Support deploy to a servlet-container
spring.jmx.enabled=false 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

Loading…
Cancel
Save