• JwtConfiguration关键代码


    配置jwt权限、存取用户访问头信息
    
    package com.tszr.config;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.Resource;
    import org.springframework.security.oauth2.provider.token.TokenStore;
    import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
    import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
    import org.springframework.util.FileCopyUtils;
    
    import java.io.IOException;
    
    @Configuration
    public class JwtConfiguration {
        @Autowired
        JwtAccessTokenConverter jwtAccessTokenConverter;
    
        @Bean
        @Qualifier("tokenStore")
        public TokenStore tokenStore() {
    
            System.out.println("Created JwtTokenStore");
            return new JwtTokenStore(jwtAccessTokenConverter);
        }
    
        @Bean
        protected JwtAccessTokenConverter jwtTokenEnhancer() {
            JwtAccessTokenConverter converter =  new JwtAccessTokenConverter();
            Resource resource = new ClassPathResource("public.cert");
            String publicKey ;
            try {
                publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            converter.setVerifierKey(publicKey);
            return converter;
        }
    }
  • 相关阅读:
    最大组合的数 A
    2106. 求对称字符串的最大长度 A
    内存分配 A
    242. 子串匹配 A
    【LeetCode 1055】形成字符串的最短路径 A
    给定差值的组合 A
    1791 设备编号 A
    最长的指定瑕疵度的元音子串 A
    1898. 【认证试题】遥控小车 A
    1792 服务器集群网络延迟 A
  • 原文地址:https://www.cnblogs.com/tszr/p/16085421.html
Copyright © 2020-2023  润新知