diff --git a/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java b/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java new file mode 100644 index 0000000..466c4a4 --- /dev/null +++ b/src/main/java/com/monkeyk/sos/domain/oauth/CustomJdbcTokenStore.java @@ -0,0 +1,39 @@ +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.provider.token.store.JdbcTokenStore; + +import javax.sql.DataSource; + +import static com.monkeyk.sos.infrastructure.CacheConstants.*; + +/** + * 2016/7/26 + * + * @author Shengzhao Li + */ +public class CustomJdbcTokenStore extends JdbcTokenStore { + + + public CustomJdbcTokenStore(DataSource dataSource) { + super(dataSource); + } + + + @Cacheable(value = OAUTH2_AUTHENTICATION_CACHE, key = "#token.getValue()") + public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { + return super.readAuthentication(token); + } + + + @Cacheable(value = OAUTH2_AUTHENTICATION_CACHE, key = "#token") + public OAuth2Authentication readAuthentication(String token) { + return super.readAuthentication(token); + } + + + +} diff --git a/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java b/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java index 502e6ea..8a3721a 100644 --- a/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java +++ b/src/main/java/com/monkeyk/sos/infrastructure/CacheConstants.java @@ -12,22 +12,27 @@ package com.monkeyk.sos.infrastructure; public abstract class CacheConstants { /** - * client Details Cache + * client Details Cache, key is clientId */ public static final String CLIENT_DETAILS_CACHE = "clientDetailsCache"; /** - * access Token Cache + * access Token Cache, key is token */ public static final String ACCESS_TOKEN_CACHE = "accessTokenCache"; /** - * authorization Code Cache + * OAuth2Authentication Cache, key is token + */ + public static final String OAUTH2_AUTHENTICATION_CACHE = "OAuth2AuthenticationCache"; + + /** + * authorization Code Cache, key is code */ public static final String AUTHORIZATION_CODE_CACHE = "authorizationCodeCache"; /** - * user Cache + * user Cache, key is username */ public static final String USER_CACHE = "userCache"; diff --git a/src/main/resources/spring/security.xml b/src/main/resources/spring/security.xml index 760d3ea..012c00a 100644 --- a/src/main/resources/spring/security.xml +++ b/src/main/resources/spring/security.xml @@ -92,7 +92,7 @@ - +