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
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM