• spring cloud gateway security oauth2


    申请token

    客户端认证

    GenericFilterBean.java 过滤链
    ClientCredentialsTokenEndpointFilter.java
    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
    throws AuthenticationException, IOException, ServletException {

    if (allowOnlyPost && !"POST".equalsIgnoreCase(request.getMethod())) {
    throw new HttpRequestMethodNotSupportedException(request.getMethod(), new String[] { "POST" });
    }

    String clientId = request.getParameter("client_id");
    String clientSecret = request.getParameter("client_secret");

    // If the request is already authenticated we can assume that this
    // filter is not needed
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication != null && authentication.isAuthenticated()) {
    return authentication;
    }

    if (clientId == null) {
    throw new BadCredentialsException("No client credentials presented");
    }

    if (clientSecret == null) {
    clientSecret = "";
    }

    clientId = clientId.trim();
    UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(clientId,
    clientSecret);

    return this.getAuthenticationManager().authenticate(authRequest);

    }

    生成token

    验证token

    WebFilter.java 调用链
    AuthenticationWebFilter.java
    ReactiveOAuth2ResourceServerJwkConfiguration.java 配置信息
    DefaultJWTProcessor.java
     
  • 相关阅读:
    linux 操作系统 基础
    [HAOI2011]Problem A
    [HNOI2015] 菜肴制作
    [P3676]小清新数据结构题
    [NOI2016]区间
    [BOI2007]Mokia 摩基亚
    [NOI2012]美食节
    [CQOI2015]网络吞吐量
    [六省联考2017]期末考试
    [HNOI2015]亚瑟王
  • 原文地址:https://www.cnblogs.com/whmbky/p/14205974.html
Copyright © 2020-2023  润新知