책을 보면서 특정 경로에 대한 인증과 권한 제한을 공부하고 있었는데 그 내용으로 mvcMatchers, antMatchers, regexMatchers가 나왔다. mvcMatchers는 스프링에서 자동으로 /abc/ 경로를 /abc로 바꿔주거나 하는 처리를 해주고, antMatchers는 /abc/면 딱 /abc/에 맞는 경로만 처리하도록 한다고 했다. 그래서 가급적이면 mvcMatchers를 사용하는 것이 좋다고 했는데 직접 테스트를 해보려고 하니 어찌된 일인지 사용할 수가 없었다. 그래서 검색을 해보니 직접 위 메서드들을 사용하는 방법은 deprecated되었다고 한다...
대신 requestMatchers를 이용해서 경로를 지정하는 방식으로 바뀌었다고 한다.
다음과 같이 사용하자.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
return http
.authorizeHttpRequests(auth -> auth
.requestMatchers(antMatcher("/login"), antMatcher("/signup")
, antMatcher("/users"), antMatcher("/users/id-check"))
.permitAll()
.anyRequest()
.authenticated()
)
// 이후 코드 생략
}'공부 > Spring Security' 카테고리의 다른 글
| [Spring Security] CSRF 설정하기 (0) | 2024.01.10 |
|---|---|
| [Spring Security] 원하는 Filter 만들어서 사용하기 (0) | 2024.01.09 |
| [Spring Security] AuthenticationProvider 직접 구현하기 (0) | 2024.01.04 |
| [Spring Security] 기본 동작 과정 및 UserDetailsService (0) | 2024.01.03 |
| [Spring Security] HTTP Basic 테스트 (0) | 2024.01.02 |