0
我正在編寫一個攔截Restful API調用的過濾器,提取一個承載令牌並調用授權服務器進行驗證。Spring Boot Oauth2驗證資源所有者的訪問令牌密碼憑據授予
我在Spring Boot中找不到一個可以開箱即用的軟件,但我確信有一個更簡潔的方法可以做到這一點。 這裏是我有(僞代碼):
public class SOOTokenValidationFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {
String xAuth = request.getHeader("Authorization");
// validate the value in xAuth
if(isValid(xAuth) == false){
throw new SecurityException();
}
// Create our Authentication and set it in Spring
Authentication auth = new Authentication();
SecurityContextHolder.getContext().setAuthentication(auth);
filterChain.doFilter(request, response);
}
private boolean isValid (String token){
// make a call to SSO passing the access token and
// return true if validated
return true;
}
}