์คํ๋ง๋ถํธ ํ๋ก์ ํธ์์ h2 database์ ์น ์ฝ์์ ํ์ฑํํ๋ ค๋ฉด
application.properties์ ์๋ ์ค์ ์ ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค. ( ๐ ์คํ๋ง๋ถํธ-h2-database-h2-console-์ค์ )
spring.h2.console.enabled=true
์คํ๋ง๋ถํธ ํ๋ก์ ํธ์ Spring Security ์์กด์ฑ์ด ์ถ๊ฐ๋์ด ์์ผ๋ฉด,
h2 ์น ์ฝ์์ ์ ์ํ์ฌ๋ ์๋ ์ฌ์ง์ฒ๋ผ "localhost์์ ์ฐ๊ฒฐ์ ๊ฑฐ๋ถํ์ต๋๋ค" ๋ผ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค.
๐ ํด๊ฒฐ๋ฒ
SecurityFilterChain์ ์๋ ์ค์ ๋ค์ ์ถ๊ฐํด์ฃผ๋ฉด ๋๋ค.
http
.csrf(csrf -> csrf.disable()) // 1. csrf ์ค์ disable
.headers(header-> header.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)) // 2. X-Frame-Options ํค๋ ์ ๊ฑฐ
.authorizeHttpRequests(auth -> auth
.requestMatchers("/h2-console/**") // 3. h2-console ๊ฒฝ๋ก๋ ์ธ์ฆ ์์ด ์ ๊ทผ ๊ฐ๋ฅํ๋๋ก ์ค์
.permitAll()
...
(๋ฌผ๋ก 3๋ฒ์ ์๋ต ๊ฐ๋ฅํ๊ธด ํ๋ฐ ๋๋ ์ ๋ ๊ฒ ํ๋ค ๐)
**
H2 ์ฝ์(http://localhost:8080/h2-console)์ ๋ด๋ถ์ ์ผ๋ก <iframe>์ ์ฌ์ฉํ์ฌ UI๋ฅผ ํ์ํ๋ค๊ณ ํ๋ค.
๊ทธ๋ฌ๋ Spring Security๊ฐ ๊ธฐ๋ณธ์ ์ผ๋ก X-Frame-Options: DENY ํค๋๋ฅผ ์ถ๊ฐํ๋ ์ค์ ์ด ์์ด์ H2 ์ฝ์์ด ์ ์์ ์ผ๋ก ๋ก๋๋์ง ์๋๋ค๊ณ ํ๋ค.
๊ทธ๋์ ์ํ๋ฆฌํฐ ํํฐ ์ฒด์ธ์ .frameOptions().disable()์ ์ ์ฉํ๋ฉด, X-Frame-Options ํค๋๊ฐ ์ ๊ฑฐ๋์ด์ <iframe> ํ๊ทธ๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํด์ง๋ค๊ณ ํ๋ค.
์ด ๋ถ๋ถ์ ๋ํด์๋ ์ข ๋ ๊ณต๋ถํด๋ด์ผํจ