(151) - 数据添加Ehcache缓存支持, tokenStore

0.6
LSZ 2016-07-26 22:57:14 +08:00
parent f2172697ba
commit 05c8f65410
3 changed files with 33 additions and 10 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -70,4 +70,16 @@
memoryStoreEvictionPolicy="LRU"/>
<cache name="refreshTokenCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="240"
timeToLiveSeconds="240"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="240"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>