(151) - 数据添加Ehcache缓存支持, tokenStore
							parent
							
								
									0db70daa4e
								
							
						
					
					
						commit
						f2172697ba
					
				| 
						 | 
				
			
			@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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";
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -92,7 +92,7 @@
 | 
			
		|||
 | 
			
		||||
    <!--Config token services-->
 | 
			
		||||
    <!--<beans:bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore"/>-->
 | 
			
		||||
    <beans:bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.store.JdbcTokenStore">
 | 
			
		||||
    <beans:bean id="tokenStore" class="com.monkeyk.sos.domain.oauth.CustomJdbcTokenStore">
 | 
			
		||||
        <beans:constructor-arg index="0" ref="dataSource"/>
 | 
			
		||||
    </beans:bean>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue