zoukankan      html  css  js  c++  java
  • oauth2 feign 报401的错误

    oauth2 feign 报401的错误

    报错

    feign.FeignException: status 401 reading UserFeign#queryUser(Long,String,String,String,Integer,Integer,Integer)
    

    解决方法

    import feign.RequestInterceptor;
    import feign.RequestTemplate;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.security.core.Authentication;
    import org.springframework.security.core.context.SecurityContext;
    import org.springframework.security.core.context.SecurityContextHolder;
    import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
    
    @Configuration
    public class FeignOauth2RequestInterceptor implements RequestInterceptor {
        private final String AUTHORIZATION_HEADER = "Authorization";
        private final String BEARER_TOKEN_TYPE = "Bearer";
        @Override
        public void apply(RequestTemplate requestTemplate) {
            SecurityContext securityContext = SecurityContextHolder.getContext();
            Authentication authentication = securityContext.getAuthentication();
            if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) {
                OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
                requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue()));
            }
    
        }
    }
    
    
  • 相关阅读:
    初识ambari
    MySQL Split 函数
    行存储和列存储
    Hbase安装和错误
    mysql 常用自定义函数解析
    mysq l错误Table ‘./mysql/proc’ is marked as crashed and should be repaired
    MySql提示:The server quit without updating PID file(…)失败
    mysql 自定义函数
    hive 调优总结
    [css] line boxes
  • 原文地址:https://www.cnblogs.com/szls-666/p/12494158.html
Copyright © 2011-2022 走看看