(151) - 数据添加Ehcache缓存支持, tokenStore
parent
f2172697ba
commit
05c8f65410
|
@ -3,12 +3,13 @@ package com.monkeyk.sos.domain.oauth;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
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 org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
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
|
* 2016/7/26
|
||||||
|
@ -23,17 +24,27 @@ public class CustomJdbcTokenStore extends JdbcTokenStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Cacheable(value = OAUTH2_AUTHENTICATION_CACHE, key = "#token.getValue()")
|
@Cacheable(value = ACCESS_TOKEN_CACHE, key = "#tokenValue")
|
||||||
public OAuth2Authentication readAuthentication(OAuth2AccessToken token) {
|
public OAuth2AccessToken readAccessToken(String tokenValue) {
|
||||||
return super.readAuthentication(token);
|
return super.readAccessToken(tokenValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Cacheable(value = OAUTH2_AUTHENTICATION_CACHE, key = "#token")
|
@CacheEvict(value = ACCESS_TOKEN_CACHE, key = "#tokenValue")
|
||||||
public OAuth2Authentication readAuthentication(String token) {
|
public void removeAccessToken(String tokenValue) {
|
||||||
return super.readAuthentication(token);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,9 @@ public abstract class CacheConstants {
|
||||||
public static final String ACCESS_TOKEN_CACHE = "accessTokenCache";
|
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
|
* authorization Code Cache, key is code
|
||||||
|
|
|
@ -70,4 +70,16 @@
|
||||||
memoryStoreEvictionPolicy="LRU"/>
|
memoryStoreEvictionPolicy="LRU"/>
|
||||||
|
|
||||||
|
|
||||||
|
<cache name="refreshTokenCache"
|
||||||
|
maxElementsInMemory="10000"
|
||||||
|
eternal="false"
|
||||||
|
timeToIdleSeconds="240"
|
||||||
|
timeToLiveSeconds="240"
|
||||||
|
overflowToDisk="true"
|
||||||
|
maxElementsOnDisk="10000000"
|
||||||
|
diskPersistent="false"
|
||||||
|
diskExpiryThreadIntervalSeconds="240"
|
||||||
|
memoryStoreEvictionPolicy="LRU"/>
|
||||||
|
|
||||||
|
|
||||||
</ehcache>
|
</ehcache>
|
||||||
|
|
Loading…
Reference in New Issue