diff --git a/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java b/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java index 466c4a4..88870a2 100644 --- a/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java +++ b/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java @@ -3,12 +3,13 @@ package com.monkeyk.sos.domain.oauth; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.security.oauth2.common.OAuth2AccessToken; -import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.security.oauth2.common.OAuth2RefreshToken; import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore; import javax.sql.DataSource; -import static com.monkeyk.sos.infrastructure.CacheConstants.*; +import static com.monkeyk.sos.infrastructure.CacheConstants.ACCESS_TOKEN_CACHE; +import static com.monkeyk.sos.infrastructure.CacheConstants.REFRESH_TOKEN_CACHE; /** * 2016/7/26 @@ -23,17 +24,27 @@ public class CustomJdbcTokenStore extends JdbcTokenStore { } - @Cacheable(value = OAUTH2_AUTHENTICATION_CACHE, key = "#token.getValue()") - public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { - return super.readAuthentication(token); + @Cacheable(value = ACCESS_TOKEN_CACHE, key = "#tokenValue") + public OAuth2AccessToken readAccessToken(String tokenValue) { + return super.readAccessToken(tokenValue); } - @Cacheable(value = OAUTH2_AUTHENTICATION_CACHE, key = "#token") - public OAuth2Authentication readAuthentication(String token) { - return super.readAuthentication(token); + @CacheEvict(value = ACCESS_TOKEN_CACHE, key = "#tokenValue") + public void removeAccessToken(String tokenValue) { + super.removeAccessToken(tokenValue); } + @Cacheable(value = REFRESH_TOKEN_CACHE, key = "#token") + public OAuth2RefreshToken readRefreshToken(String token) { + return super.readRefreshToken(token); + } + + @CacheEvict(value = REFRESH_TOKEN_CACHE, key = "#token") + public void removeRefreshToken(String token) { + super.removeRefreshToken(token); + } + } diff --git a/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java b/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java index 8a3721a..3fe0f37 100644 --- a/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java +++ b/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java @@ -22,9 +22,9 @@ public abstract class CacheConstants { public static final String ACCESS_TOKEN_CACHE = "accessTokenCache"; /** - * OAuth2Authentication Cache, key is token + * refresh Token Cache, key is token */ - public static final String OAUTH2_AUTHENTICATION_CACHE = "OAuth2AuthenticationCache"; + public static final String REFRESH_TOKEN_CACHE = "refreshTokenCache"; /** * authorization Code Cache, key is code diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml index c83b680..c18243f 100644 --- a/src/main/resources/ehcache.xml +++ b/src/main/resources/ehcache.xml @@ -70,4 +70,16 @@ memoryStoreEvictionPolicy="LRU"/> + + +