[Spring] This method cannot decide whether these patterns are Spring MVC patterns or not.

노유성·2023년 7월 27일
1
post-thumbnail
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http
            // token을 사용하는 방식이기 때문에 csrf를 disable합니다.
            .csrf(csrf -> csrf.disable())
            .authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests
                    // 문제 부분
                    .requestMatchers("/api/hello", "/api/authenticate", "/api/signup").permitAll()
                            .anyRequest().authenticated()
            )
            // enable h2-console
            .headers(headers ->
                    headers.frameOptions(options ->
                            options.sameOrigin()
                    )
            );
    return http.build();
}

Caused by: java.lang.IllegalArgumentException: This method cannot decide whether these patterns are Spring MVC patterns or not. If this endpoint is a Spring MVC endpoint, please use requestMatchers(MvcRequestMatcher); otherwise, please use requestMatchers(AntPathRequestMatcher).
at org.springframework.util.Assert.isTrue(Assert.java:122)

뭐 대충 이런 에러 메세지였다.

https://spring.io/security/cve-2023-34035

에서 해결책을 찾았고

.authorizeHttpRequests(authorizeHttpRequests -> authorizeHttpRequests
                .requestMatchers(new AntPathRequestMatcher("/api/hello")
                        , new AntPathRequestMatcher("/api/authenticate")
                        , new AntPathRequestMatcher("/api/signup")).permitAll()
//                        .requestMatchers("/api/hello", "/api/authenticate", "/api/signup").permitAll()
                .anyRequest().authenticated()

문제 되는 코드를 이렇게 바꾸는 것이다. 에러메세지를 직역하면은 mvc패턴에 맞는지, endpoint 가 맞는지를 확인할 수 없다고 얘기하는 것 같다.

profile
풀스택개발자가되고싶습니다:)

0개의 댓글