songining

๊ธฐ์กด์— ํ•˜๋˜ ๊ฒƒ ์ฒ˜๋Ÿผ http.requestMatchers("/h2-console/**").permitAll() ๋กœ h2-console์— ๋Œ€ํ•œ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ด์ฃผ๋ ค๊ณ  ํ–ˆ์ง€๋งŒ ๊ณ„์†ํ•ด์„œ 403(forbidden) ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค.

๊ตฌ๊ธ€๋ง์„ ํ†ตํ•ด ํ•ด๊ฒฐํ•œ ๊ฒฐ๊ณผ

@Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests()
                .requestMatchers("/users/**").permitAll()
                .and()
                .authorizeHttpRequests(auth -> auth
                        .requestMatchers(AntPathRequestMatcher.antMatcher("/h2-console/**")).permitAll()
                )
                .headers(headers -> headers.frameOptions().disable())
                .csrf().disable();

        return http.build();
    }

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

๋ฒ„์ „์ด ์—…๊ทธ๋ ˆ์ด๋“œ ๋˜๋ฉด์„œ authorizeHttpRequests()๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ๋ณ€๊ฒฝ ๋˜์—ˆ๋Š”๋ฐ Spring MVC๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ authorizeHttpRequests() .requestMatchers ๋Š” MvcRequestMatcher๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

ํ•˜์ง€๋งŒ H2 ์ฝ˜์†”์€ Spring MVC์— ์˜ํ•ด ์ œ์–ด๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— AntPathRequestMatcher๋ฅผ ์‚ฌ์šฉํ•ด์•ผ ํ•œ๋‹ค.

๋”ฐ๋ผ์„œ ์œ„์™€ ๊ฐ™์ด AntPathRequestMatcher ๋กœ ๋ณ€ํ™˜ํ•ด์„œ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ด์ฃผ์—ˆ๋‹ค.

 

์ฐธ๊ณ 

https://github.com/spring-projects/spring-security/issues/12546