Я пишу фильтр, который перехватит вызов 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;
}
}