[Spring Boot] Spring Security without the WebSecurityConfigurerAdapter

jieuneeΒ·2022λ…„ 7μ›” 6일
0

πŸ†˜ 문제의 μ‹œμž‘

μ΄λ²ˆμ— μ§„ν–‰ν•˜κ²Œ 된 ν”„λ‘œμ νŠΈ λ‚΄μ—μ„œλ„ νšŒμ›κ°€μž… 및 둜그인 κΈ°λŠ₯ κ΅¬ν˜„μ΄ μžˆμ–΄,
μ €λ²ˆμ— μ§„ν–‰ν–ˆλ˜ λ°©μ‹λŒ€λ‘œ Spring Security와 JWTλ₯Ό μ‚¬μš©ν•˜μ—¬ κ΅¬ν˜„μ„ μ‹œμž‘ν•˜λ €λŠ”λ°

μœ„μ™€ 같이 WebSecurityConfigurerAdapter κ°€ 적용이 μ•ˆλ˜λŠ” ν˜„μƒμ΄ λ°œμƒν–ˆλ‹€.
μ œλŒ€λ‘œ 된 μ½”λ“œλ₯Ό μž‘μ„±ν•˜λ €λ©΄ μ΄λŸ¬ν•œ 상황이 λ°œμƒν•˜λ©΄ μ•ˆ λ˜κΈ°μ— μ—΄μ‹¬νžˆ μ•Œμ•„λ³Έ κ²°κ³Ό!

κ³΅μ‹λ¬Έμ„œλ‘œ μ΄λ™ν•˜κΈ°

곡식 λ¬Έμ„œμ— λ”°λ₯Έ κ²°κ³Όλ‘œλŠ”, Spring Security 5.7.0-M2λΆ€ν„°λŠ” λ‚΄κ°€ μ‚¬μš©ν–ˆλ˜ 방식과 같이 상속을 λ°›μ•„ μ˜€λ²„λΌμ΄λ”© ν•˜λŠ” 것이 μ•„λ‹ˆλΌλŠ” 것이닀.

그러면 μ–΄λ–»κ²Œ ν•΄μ•Όλ κΉŒ ? πŸ€”


πŸ’‘ ν•΄κ²° λ°©μ•ˆ

곡식 λ¬Έμ„œμ— μ–΄λ–»κ²Œ μ½”λ“œλ₯Ό λ³€κ²½ν•΄μ„œ μ‚¬μš©ν•΄μ•Ό 될지 μΉœμ ˆν•˜κ²Œ μ•ˆλ‚΄λ˜μ–΄ μžˆμ—ˆλ‹€.

λ³€κ²½ μ „

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeHttpRequests((authz) -> authz
            .anyRequest().authenticated()
        )
        .httpBasic(withDefaults());
}

λ³€κ²½ ν›„

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http
        .authorizeHttpRequests((authz) -> authz
            .anyRequest().authenticated()
        )
        .httpBasic(withDefaults());
    return http.build();
}

μœ„μ˜ μ½”λ“œμ™€ 같이 λ³€κ²½ ν›„μ—λŠ” SecurityFilterChain Bean을 λ“±λ‘ν•˜μ—¬ μ‚¬μš©ν•˜κΈ°λ₯Ό ꢌμž₯ν•œλ‹€κ³  λ‚˜μ™€μžˆλ‹€.


이번 일을 κ³„κΈ°λ‘œ 버전에 따라 λ³€ν™”λ˜λŠ” 뢀뢄이 λ§ŽκΈ°μ— 더 μ—΄μ‹¬νžˆ κ³΅λΆ€ν•΄μ•Όκ² λ‹€λŠ” 생각이 λ“€μ—ˆλ‹€.

profile
Back-End Developer 🌱

0개의 λŒ“κΈ€