From fabb0580bf5d4ad4188ad498e85c64ba4c48a8cf Mon Sep 17 00:00:00 2001 From: zlt Date: Sun, 14 Jul 2019 23:29:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=88=E6=9D=83=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/central/oauth/model/TokenVo.java | 4 ++++ .../service/impl/RedisTokensServiceImpl.java | 15 ++++++++++----- .../resources/static/pages/system/tokens.html | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/zlt-uaa/src/main/java/com/central/oauth/model/TokenVo.java b/zlt-uaa/src/main/java/com/central/oauth/model/TokenVo.java index bb1f2112..3b0ccdd3 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/model/TokenVo.java +++ b/zlt-uaa/src/main/java/com/central/oauth/model/TokenVo.java @@ -29,4 +29,8 @@ public class TokenVo implements Serializable { * 所属应用 */ private String clientId; + /** + * 授权类型 + */ + private String grantType; } diff --git a/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java b/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java index 8916a24e..8a6c81b0 100644 --- a/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java +++ b/zlt-uaa/src/main/java/com/central/oauth/service/impl/RedisTokensServiceImpl.java @@ -12,6 +12,7 @@ import org.apache.commons.collections4.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.provider.OAuth2Authentication; +import org.springframework.security.oauth2.provider.OAuth2Request; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -44,17 +45,21 @@ public class RedisTokensServiceImpl implements ITokensService { if (tokenObjs != null) { for (Object obj : tokenObjs) { DefaultOAuth2AccessToken accessToken = (DefaultOAuth2AccessToken)obj; + //构造token对象 + TokenVo tokenVo = new TokenVo(); + tokenVo.setTokenValue(accessToken.getValue()); + tokenVo.setExpiration(accessToken.getExpiration()); + //获取用户信息 Object authObj = redisRepository.get(SecurityConstants.REDIS_TOKEN_AUTH + accessToken.getValue()); OAuth2Authentication authentication = (OAuth2Authentication)authObj; - //构造token对象 - TokenVo tokenVo = new TokenVo(); - tokenVo.setClientId(clientId); - tokenVo.setTokenValue(accessToken.getValue()); - tokenVo.setExpiration(accessToken.getExpiration()); if (authentication != null) { + OAuth2Request request = authentication.getOAuth2Request(); tokenVo.setUsername(authentication.getName()); + tokenVo.setClientId(request.getClientId()); + tokenVo.setGrantType(request.getGrantType()); } + result.add(tokenVo); } } diff --git a/zlt-web/back-web/src/main/resources/static/pages/system/tokens.html b/zlt-web/back-web/src/main/resources/static/pages/system/tokens.html index 17ba768c..092b2d10 100644 --- a/zlt-web/back-web/src/main/resources/static/pages/system/tokens.html +++ b/zlt-web/back-web/src/main/resources/static/pages/system/tokens.html @@ -46,6 +46,7 @@ }, title: '到期时间' }, {field: 'username',width:180, sort: true, title: '用户名'}, + {field: 'grantType',width:180, sort: true, title: '授权类型'}, {field: 'clientId',width:180, sort: true, title: '所属应用'}, {align: 'center',width:100, toolbar: '#tokens-table-bar', title: '操作'} ]]