package am.ik.categolj2.infra.token;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.TokenStore;
import java.util.Collection;
public class CachingTokenStore implements TokenStore {
private final TokenStore delegate;
public CachingTokenStore(TokenStore delegate) {
this.delegate = delegate;
}
@Override
@Cacheable(value = "accessTokenAuthentication", key = "#token.value")
public OAuth2Authentication readAuthentication(OAuth2AccessToken token) {
return delegate.readAuthentication(token);
}
@Override
@Cacheable("accessTokenAuthentication")
public OAuth2Authentication readAuthentication(String token) {
return delegate.readAuthentication(token);
}
@Override
public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
delegate.storeAccessToken(token, authentication);
}
@Override
@Cacheable("accessToken")
public OAuth2AccessToken readAccessToken(String tokenValue) {
return delegate.readAccessToken(tokenValue);
}
@Override
@CacheEvict(value = {"accessToken", "accessTokenAuthentication"}, key = "#token.value")
public void removeAccessToken(OAuth2AccessToken token) {
delegate.removeAccessToken(token);
}
@Override
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
delegate.storeRefreshToken(refreshToken, authentication);
}
@Override
public OAuth2RefreshToken readRefreshToken(String tokenValue) {
return delegate.readRefreshToken(tokenValue);
}
@Override
public OAuth2Authentication readAuthenticationForRefreshToken(OAuth2RefreshToken token) {
return delegate.readAuthenticationForRefreshToken(token);
}
@Override
public void removeRefreshToken(OAuth2RefreshToken token) {
delegate.removeRefreshToken(token);
}
@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
delegate.removeAccessTokenUsingRefreshToken(refreshToken);
}
@Override
public OAuth2AccessToken getAccessToken(OAuth2Authentication authentication) {
return delegate.getAccessToken(authentication);
}
@Override
public Collection<OAuth2AccessToken> findTokensByClientIdAndUserName(String clientId, String userName) {
return delegate.findTokensByClientIdAndUserName(clientId, userName);
}
@Override
public Collection<OAuth2AccessToken> findTokensByClientId(String clientId) {
return delegate.findTokensByClientId(clientId);
}
}