AuthorizationServerConfig.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:cloud-project 作者:
/**
 * Jwt资源令牌转换器
 * @return accessTokenConverter
 */
@Bean
public JwtAccessTokenConverter accessTokenConverter(){
    return new JwtAccessTokenConverter(){

        /**
         * 重写增强token的方法
         * @param accessToken 资源令牌
         * @param authentication 认证
         * @return 增强的OAuth2AccessToken对象
         */
        @Override
        public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {

            String userName = authentication.getUserAuthentication().getName();
            User user = (User) authentication.getUserAuthentication().getPrincipal();
            Map<String,Object> infoMap = new HashMap<>();
            infoMap.put("userName",userName);
            infoMap.put("roles",user.getAuthorities());
            ((DefaultOAuth2AccessToken)accessToken).setAdditionalInformation(infoMap);
            return super.enhance(accessToken, authentication);
        }
    };
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号