增加授权类型字段

This commit is contained in:
zlt
2019-07-14 23:29:03 +08:00
parent e56880bb79
commit fabb0580bf
3 changed files with 15 additions and 5 deletions
@@ -29,4 +29,8 @@ public class TokenVo implements Serializable {
* 所属应用 * 所属应用
*/ */
private String clientId; private String clientId;
/**
* 授权类型
*/
private String grantType;
} }
@@ -12,6 +12,7 @@ import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.provider.OAuth2Authentication; import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.OAuth2Request;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@@ -44,17 +45,21 @@ public class RedisTokensServiceImpl implements ITokensService {
if (tokenObjs != null) { if (tokenObjs != null) {
for (Object obj : tokenObjs) { for (Object obj : tokenObjs) {
DefaultOAuth2AccessToken accessToken = (DefaultOAuth2AccessToken)obj; 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()); Object authObj = redisRepository.get(SecurityConstants.REDIS_TOKEN_AUTH + accessToken.getValue());
OAuth2Authentication authentication = (OAuth2Authentication)authObj; OAuth2Authentication authentication = (OAuth2Authentication)authObj;
//构造token对象
TokenVo tokenVo = new TokenVo();
tokenVo.setClientId(clientId);
tokenVo.setTokenValue(accessToken.getValue());
tokenVo.setExpiration(accessToken.getExpiration());
if (authentication != null) { if (authentication != null) {
OAuth2Request request = authentication.getOAuth2Request();
tokenVo.setUsername(authentication.getName()); tokenVo.setUsername(authentication.getName());
tokenVo.setClientId(request.getClientId());
tokenVo.setGrantType(request.getGrantType());
} }
result.add(tokenVo); result.add(tokenVo);
} }
} }
@@ -46,6 +46,7 @@
}, title: '到期时间' }, title: '到期时间'
}, },
{field: 'username',width:180, sort: true, title: '用户名'}, {field: 'username',width:180, sort: true, title: '用户名'},
{field: 'grantType',width:180, sort: true, title: '授权类型'},
{field: 'clientId',width:180, sort: true, title: '所属应用'}, {field: 'clientId',width:180, sort: true, title: '所属应用'},
{align: 'center',width:100, toolbar: '#tokens-table-bar', title: '操作'} {align: 'center',width:100, toolbar: '#tokens-table-bar', title: '操作'}
]] ]]