优化oauth2客户端

This commit is contained in:
zhou-hao
2017-12-01 15:38:25 +08:00
parent a9fe22eaeb
commit 2fca75ee4e
5 changed files with 47 additions and 2 deletions

View File

@@ -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%|

View File

@@ -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()

View File

@@ -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());
}

View File

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

View File

@@ -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;
}
}