私はエンドポイントに春のJWTセキュリティを実装する必要があります。私は2つのルートを持っています - 内部は1、外部は2です。私は以下のコードを追加しようとしましたが、両方のフィルタがすべての要求に対して実行されています。 URLに基づいてフィルタにロジックを追加できます。しかし、私は正しいアプローチをしていませんでした。適切なアプローチと解決方法について教えてください。スプリングブート複数のJWTを使用する複数のルート
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/internal/**")
.authenticated()
.and()
.addFilterBefore(jwtAuthenticationInternalFilter(), BasicAuthenticationFilter.class)
.authorizeRequests()
.antMatchers("/external/**")
.authenticated()
.and()
.addFilterBefore(jwtAuthenticationExternalFilter(), BasicAuthenticationFilter.class);
public class ExternalAuthenticationFilter extends OncePerRequestFilter {
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Its hitting here - External");//GET THE Information and build Authentication object..
// SecurityContextHolder.getContext().setAuthentication(token);
filterChain.doFilter(request, response);
}
}
public class InternalAuthenticationFilter extends OncePerRequestFilter {
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
System.out.println("Its hitting here - Internal");//GET THE Information and build Authentication object..
// SecurityContextHolder.getContext().setAuthentication(token);
filterChain.doFilter(request, response);
}
}
任意の要求に対して内部コードと外部コードの両方が実行されています。 サンプル要求 /内部/ ABC、
/外部/ XYZ ..両方のケースの両方のフィルタが呼び出されている。..
次の2つの異なるコンフィギュレーションクラスにセキュリティ設定を分割し、それらをマークすることができ
ザッツはまさに私が -1 投票 ダウン受け入れる..下のリンクで見つけ https://github.com /spring-projects/spring-security-javaconfig/blob/master/samples-web.md#sample-multi-http-web-configuration ..私は自分に答えましたが、誰かがそれを削除しました – KNS