Selaa lähdekoodia

优化oauth2客户端

zhou-hao 7 vuotta sitten
vanhempi
commit
2fca75ee4e

+ 2 - 2
hsweb-authorization/hsweb-authorization-oauth2/README.md

@@ -3,5 +3,5 @@
 # 模块说明
 | 模块       | 说明          |   进度 |
 | ------------- |:-------------:| ----|
-|[hsweb-authorization-oauth2-client](hsweb-authorization-oauth2-client)|OAuth2 客户端API| 10%|
-|[hsweb-authorization-oauth2-server](hsweb-authorization-oauth2-server)|OAuth2 服务端API| 50%|
+|[hsweb-authorization-oauth2-client](hsweb-authorization-oauth2-client)|OAuth2 客户端API| 90%|
+|[hsweb-authorization-oauth2-server](hsweb-authorization-oauth2-server)|OAuth2 服务端API| 90%|

+ 6 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2ServerConfigRepository.java

@@ -23,6 +23,12 @@ public class MemoryOAuth2ServerConfigRepository implements OAuth2ServerConfigRep
         return repo.get(id);
     }
 
+    @Override
+    public OAuth2ServerConfig save(OAuth2ServerConfig config) {
+        repo.put(config.getId(), config);
+        return config;
+    }
+
     public void setServers(List<OAuth2ServerConfig> servers) {
         this.servers = servers;
         repo = servers.stream()

+ 2 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2UserTokenRepository.java

@@ -46,6 +46,8 @@ public class MemoryOAuth2UserTokenRepository implements OAuth2UserTokenRepositor
 
     @Override
     public AccessTokenInfo insert(AccessTokenInfo accessTokenInfo) {
+        accessTokenInfo.setCreateTime(System.currentTimeMillis());
+        accessTokenInfo.setUpdateTime(System.currentTimeMillis());
         if (accessTokenInfo.getId() == null) {
             accessTokenInfo.setId(IDGenerator.MD5.generate());
         }

+ 2 - 0
hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/OAuth2ServerConfigRepository.java

@@ -8,4 +8,6 @@ import org.hswebframework.web.authorization.oauth2.client.OAuth2ServerConfig;
  */
 public interface OAuth2ServerConfigRepository {
     OAuth2ServerConfig findById(String id);
+
+    OAuth2ServerConfig save(OAuth2ServerConfig config);
 }

+ 35 - 0
hsweb-system/hsweb-system-oauth2-client/hsweb-system-oauth2-client-service/hsweb-system-oauth2-client-service-simple/src/main/java/org/hswebframework/web/service/oauth2/client/simple/SimpleOAuth2ServerConfigService.java

@@ -26,9 +26,12 @@ import org.hswebframework.web.service.GenericEntityService;
 import org.hswebframework.web.service.oauth2.client.OAuth2ServerConfigService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheConfig;
+import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * 默认的服务实现
  *
@@ -60,4 +63,36 @@ public class SimpleOAuth2ServerConfigService extends EnableCacheGenericEntitySer
         }
         return entityFactory.newInstance(OAuth2ServerConfig.class, entity);
     }
+
+    @Override
+    @CacheEvict(key = "'id:'+#id")
+    public int updateByPk(String id, OAuth2ServerConfigEntity entity) {
+        return super.updateByPk(id, entity);
+    }
+
+    @Override
+    @CacheEvict(key = "'id:'+#id")
+    public int deleteByPk(String id) {
+        return super.deleteByPk(id);
+    }
+
+    @Override
+    @CacheEvict(allEntries = true)
+    public int updateByPk(List<OAuth2ServerConfigEntity> data) {
+        return super.updateByPk(data);
+    }
+
+    @Override
+    @CacheEvict(key = "'id:'+#result")
+    public String saveOrUpdate(OAuth2ServerConfigEntity entity) {
+        return super.saveOrUpdate(entity);
+    }
+
+    @Override
+    @CacheEvict(key = "'id:'+#result.id")
+    public OAuth2ServerConfig save(OAuth2ServerConfig config) {
+        OAuth2ServerConfigEntity entity = entityFactory.newInstance(OAuth2ServerConfigEntity.class, config);
+        saveOrUpdate(entity);
+        return config;
+    }
 }