์๋
ํ์ธ์, Spring Security์ ๊ดํ ์ค๋์ ๋ธ๋ก๊ทธ ๊ธ์์๋ Spring Security ์ค์ ์ค ๋ฐ์ํ ์ ์๋ ์ผ๋ฐ์ ์ธ ์ค๋ฅ์ ์ด๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ด์ผ๊ธฐํด๋ณด๋ ค ํฉ๋๋ค. ํนํ, AntPathRequestMatcher
์ MvcRequestMatcher
์ ์ฌ์ฉ๊ณผ ๊ด๋ จ๋ UnsatisfiedDependencyException
์ค๋ฅ ํด๊ฒฐ์ ์ด์ ์ ๋ง์ถ ๊ฒ์
๋๋ค.
์ํฉ ์ค๋ช
Spring Security๋ฅผ ๊ตฌ์ฑํ๋ ๊ณผ์ ์์ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ๋ฌธ์ผ๋ก ๋ณด์ ์ค์ ์ ์ ์ํ์ต๋๋ค:
.authorizeHttpRequests(auth -> auth
.requestMatchers("/login", "/user/register", ... ) // ์งง์ ๋ฒ์
.permitAll()
)
์ด๋ฌํ ์ค์ ์ AntPathRequestMatcher
๋์ ์ง์ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ๋ ๊ฐ๊ฒฐํ ๋ฐฉ์์
๋๋ค. ํ์ง๋ง ์ด ๊ตฌ์ฑ์ ์ ์ฉํ ํ, ๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค:
UnsatisfiedDependencyException: Error creating bean with name 'WebSecurityConfiguration': ...
... Factory method 'filterChain' threw exception with message: This method cannot decide ...
์ค๋ฅ์ ์์ธ
์ด ์ค๋ฅ๋ Spring Security๊ฐ ์์ฒญ ๋งค์ฒ๋ฅผ ํด์ํ๋ ๊ณผ์ ์์ ๋ฐ์ํฉ๋๋ค. requestMatchers()
๋ฉ์๋๋ฅผ ์ฌ์ฉํ ๋, Spring์ ์ ๊ณต๋ ํจํด์ด Spring MVC ํจํด์ธ์ง ์๋๋ฉด ์ผ๋ฐ Ant ์คํ์ผ์ ํจํด์ธ์ง ์๋์ผ๋ก ํ๋จํ๊ธฐ ์ด๋ ต์ต๋๋ค. ์ด๋ก ์ธํด, MvcRequestMatcher
๋ฅผ ์ฌ์ฉํด์ผ ํ๋ ์ํฉ์์ AntPathRequestMatcher
๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์๋ ๋ช
์์ ์ผ๋ก AntPathRequestMatcher
๊ฐ์ฒด๋ฅผ ์ฌ์ฉํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด:
.authorizeHttpRequests(auth -> auth
.requestMatchers(new AntPathRequestMatcher("/login")).permitAll()
.requestMatchers(new AntPathRequestMatcher("/user/register")).permitAll()
// ์ถ๊ฐ ๊ฒฝ๋ก...
)
์ด ๋ฐฉ์์ Spring Security์๊ฒ ๋ช
ํํ Ant ์คํ์ผ์ ๊ฒฝ๋ก ๋งค์นญ์ ์ฌ์ฉํ๊ณ ์์์ ์๋ฆฝ๋๋ค, ๋ฐ๋ผ์ UnsatisfiedDependencyException
์ค๋ฅ๋ฅผ ํด๊ฒฐํ ์ ์์ต๋๋ค.
์ฐธ๊ณ ์๋ฃ
- Spring Security ๊ณต์๋ฌธ์
https://docs.spring.io/spring-security/reference/migration-7/configuration.html