sourcecode

antMatcher와 mvcMatcher의 차이

codebag 2023. 8. 16. 22:14
반응형

antMatcher와 mvcMatcher의 차이

무엇이 다른가?HttpSecurityantMatcher()그리고.mvcMatcher()함수?

언제 그것들을 사용해야 하는지 설명해 줄 수 있는 사람이 있습니까?

방법의 서명이 공식 문서에도 명시되어 있음을 분명히 알 수 있듯이,

antMatcher(String antPattern)를 구성할 수 있습니다.HttpSecurity제공된 개미 패턴과 일치하는 경우에만 호출됩니다.

mvcMatcher(String mvcPattern)를 구성할 수 있습니다.HttpSecurity제공된 Spring MVC 패턴과 일치하는 경우에만 호출됩니다.

일반적으로.mvcMatcher보다 안전합니다.antMatcher예를 들어,

  • antMatchers("/secured") 정확한 것만 일치합니다. /securedURL
  • mvcMatchers("/secured") 성냥/secured게다가/secured/,/secured.html,/secured.xyz

따라서 보다 일반적이며 몇 가지 가능한 구성 오류도 처리할 수 있습니다.

mvcMatcherSpring MVC가 매칭에 사용하는 것과 동일한 규칙을 사용합니다(사용 시).@RequestMapping주석).

Spring MVC에서 현재 요청이 처리되지 않을 경우 패턴을 개미 패턴으로 사용하는 합리적인 기본값이 사용됩니다.출처

라고 덧붙일 수도 있습니다.mvcMatchersAPI(4.1.1 이후)가 다음보다 최신입니다.antMatchersAPI(3.1 이후).

AntMatcher()는 Ant-style 경로 패턴에 대한 구현입니다.이 매핑 코드의 일부는 Apache Ant에서 친절하게 차용되었습니다.

MvcMatcher()Spring MVC 사용HandlerMappingIntrospector경로를 일치시키고 변수를 추출합니다.

그래서 그들은 둘 다RequestMatcher인터페이스를 사용하지만 후드 아래에서 다른 표현 언어를 사용합니다.

antMatcher("/users/**") matches any path starting with /users
antMatchers("/users") matches only the exact /users URL
mvcMatchers("/users") matches /users, /users/, /users.html

public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
  .authorizeRequests()
  .antMatchers("/users/movie/**") // matches any path starting with /users/movie
  .hasRole("ADMIN") ...
  }
}

언급URL : https://stackoverflow.com/questions/50536292/difference-between-antmatcher-and-mvcmatcher

반응형