From 2fca75ee4e39b38efdf3a376d73da59ffcc6095f Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Fri, 1 Dec 2017 15:38:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96oauth2=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hsweb-authorization-oauth2/README.md | 4 +-- .../MemoryOAuth2ServerConfigRepository.java | 6 ++++ .../MemoryOAuth2UserTokenRepository.java | 2 ++ .../simple/OAuth2ServerConfigRepository.java | 2 ++ .../SimpleOAuth2ServerConfigService.java | 35 +++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/hsweb-authorization/hsweb-authorization-oauth2/README.md b/hsweb-authorization/hsweb-authorization-oauth2/README.md index 1c530f6c0..aec6405f5 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/README.md +++ b/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%| \ No newline at end of file +|[hsweb-authorization-oauth2-client](hsweb-authorization-oauth2-client)|OAuth2 客户端API| 90%| +|[hsweb-authorization-oauth2-server](hsweb-authorization-oauth2-server)|OAuth2 服务端API| 90%| \ No newline at end of file diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2ServerConfigRepository.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2ServerConfigRepository.java index b9395f7bb..93a1b89b7 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2ServerConfigRepository.java +++ b/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 servers) { this.servers = servers; repo = servers.stream() diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2UserTokenRepository.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2UserTokenRepository.java index 24e6a8032..3470e1833 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/MemoryOAuth2UserTokenRepository.java +++ b/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()); } diff --git a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/OAuth2ServerConfigRepository.java b/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/OAuth2ServerConfigRepository.java index 65ffb7b2c..8533bf132 100644 --- a/hsweb-authorization/hsweb-authorization-oauth2/hsweb-authorization-oauth2-client/src/main/java/org/hswebframework/web/authorization/oauth2/client/simple/OAuth2ServerConfigRepository.java +++ b/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); } diff --git a/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 b/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 index a4be78c2f..59d4bdba8 100644 --- a/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 +++ b/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 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; + } }