|
@@ -23,10 +23,15 @@ import org.hswebframework.web.authorization.oauth2.server.entity.OAuth2AccessEnt
|
|
|
import org.hswebframework.web.authorization.oauth2.server.OAuth2AccessToken;
|
|
|
import org.hswebframework.web.authorization.oauth2.server.token.AccessTokenService;
|
|
|
import org.hswebframework.web.commons.entity.factory.EntityFactory;
|
|
|
+import org.hswebframework.web.concurrent.lock.annotation.ReadLock;
|
|
|
+import org.hswebframework.web.concurrent.lock.annotation.WriteLock;
|
|
|
import org.hswebframework.web.dao.oauth2.OAuth2AccessDao;
|
|
|
import org.hswebframework.web.id.IDGenerator;
|
|
|
import org.hswebframework.web.service.DefaultDSLQueryService;
|
|
|
import org.hswebframework.web.service.DefaultDSLUpdateService;
|
|
|
+import org.springframework.cache.annotation.CachePut;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.cache.annotation.Caching;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Assert;
|
|
@@ -54,6 +59,18 @@ public class SimpleAccessTokenService implements AccessTokenService {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Cacheable(cacheNames = "oauth2-access-token", key = "'cgo'+#token.clientId+#token.grantType+#token.ownerId")
|
|
|
+ public OAuth2AccessToken tryGetOldToken(OAuth2AccessToken token) {
|
|
|
+ OAuth2AccessToken old = DefaultDSLQueryService
|
|
|
+ .createQuery(oAuth2AccessDao)
|
|
|
+ .where("clientId", token.getClientId())
|
|
|
+ .and("grantType", token.getGrantType())
|
|
|
+ .and("ownerId", token.getOwnerId())
|
|
|
+ .single();
|
|
|
+ return old;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public OAuth2AccessToken createToken() {
|
|
|
OAuth2AccessEntity accessEntity = entityFactory.newInstance(OAuth2AccessEntity.class);
|
|
@@ -65,6 +82,7 @@ public class SimpleAccessTokenService implements AccessTokenService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
|
|
+ @Cacheable(cacheNames = "oauth2-access-token", key = "'refresh:'+#refreshToken")
|
|
|
public OAuth2AccessToken getTokenByRefreshToken(String refreshToken) {
|
|
|
Assert.notNull(refreshToken, "refreshToken can not be null!");
|
|
|
return DefaultDSLQueryService.createQuery(oAuth2AccessDao)
|
|
@@ -73,6 +91,7 @@ public class SimpleAccessTokenService implements AccessTokenService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
|
|
+ @Cacheable(cacheNames = "oauth2-access-token", key = "'token:'+#accessToken")
|
|
|
public OAuth2AccessToken getTokenByAccessToken(String accessToken) {
|
|
|
Assert.notNull(accessToken, "accessToken can not be null!");
|
|
|
return DefaultDSLQueryService.createQuery(oAuth2AccessDao)
|
|
@@ -81,6 +100,11 @@ public class SimpleAccessTokenService implements AccessTokenService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
|
|
+ @Caching(put = {
|
|
|
+ @CachePut(cacheNames = "oauth2-access-token", key = "'refresh:'+#token.refreshToken"),
|
|
|
+ @CachePut(cacheNames = "oauth2-access-token", key = "'token:'+#token.accessToken"),
|
|
|
+ @CachePut(cacheNames = "oauth2-access-token", key = "'cgo'+#token.clientId+#token.grantType+#token.ownerId")
|
|
|
+ })
|
|
|
public OAuth2AccessToken saveOrUpdateToken(OAuth2AccessToken token) {
|
|
|
Assert.notNull(token, "token can not be null!");
|
|
|
int total = DefaultDSLQueryService
|