[Spring Security] RequestMatcher

정명진·2023년 9월 18일
3

Spring Security 3점대 버전을 사용하면서 h2-console을 enable 하면 이전처럼 requestMatcher 적용시 어떤 서블렛을 사용하는지 명시하라고 오류가 발생한다.

그래서 시큐리티에서 사용하는 requestMatcher의 종류를 찾아봤다.

  1. AntPathRequestMatcher
  • 해당 Matcher는 주로 시큐리티에서 사용합니다.
  • 주료 URL 매핑을 통제할때 유용하게 사용된다.
  • 이 매처는 Spring Security에서 주로 사용됩니다.
  • Ant 스타일 패턴을 사용하여 URL 경로를 비교합니다. 이는 와일드카드 문자를 허용합니다.
  1. MvcRequestMatcher
  • Spring Security에서도 사용되지만, 주로 Spring Web MVC에서 사용됩니다.
  • MvcRequestMatcher는 요청의 HTTP 메소드, URL, 및 다른 조건에 따라 요청을 매칭하는 데 사용됩니다.
  • 예를 들어, 특정 URL과 HTTP 메소드 (GET, POST 등)를 기반으로 요청을 통제할 수 있습니다.

최종적으로 비교하자면 일반적으로 MvcRequestMatcher 가 AntPathRequestMatcher 보다 안정적이라고 합니다.

다음과 같은 상황에서
antMatchers("/secured") matches only the exact /secured URL
mvcMatchers("/secured") matches /secured as well as /secured/, /secured.html, /secured.xyz
그래서 사람의 실수를 방지할 수 있고 이러한 오류에 대해서 조금더 안정적이란 평가를 받습니다.

profile
개발자로 입사했지만 정체성을 잃어가는중... 다시 준비 시작이다..

0개의 댓글