認証が SSO サービスを使用して既に行われている場合は、Spring Security の事前認証フィルターのいずれかを使用する必要があります。次に、事前認証されたユーザー プリンシパルを使用して GrantedAuthority の
SpringSecurity には、J2eePreAuthenticatedProcessingFilter や RequestHeaderPreAuthenticatedProcessingFilter など、いくつかの事前認証フィルターが含まれています。SSO 実装がデータをリクエストのどこに詰め込むかを知っていれば、自分に合ったものを見つけることもできます。(もちろん、それは実装に依存します。)
Filterインターフェイスを実装し、doFilter メソッドで次のようにします。
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// principal is set in here as a header or parameter. you need to find out
// what it's named to extract it
HttpServletRequest req = (HttpServletRequest) request;
if (SecurityContextHolder.getContext().getAuthentication() == null) {
// in here, get your principal, and populate the auth object with
// the right authorities
Authentication auth = doAuthentication(req);
SecurityContextHolder.getContext().setAuthentication(auth);
}
chain.doFilter(request, response);
}