πνκ²½
IntelliJ Ultimate
Java 17
Spring boot 3.2.3
Gradle - Groovy
Dependencies:
Spring Web
Thymeleaf
Spring Data JPA
lombok
MariaDB 10.11
Spring Dev tool
πλ¬Έμ
2024λ 3μ 16μΌ κΈ°μ€ μ€νλ§ λΆνΈ 3.2.3λ²μ νλ‘μ νΈμμ μ€νλ§ μν리ν°μ μ μ© κ³Όμ λμ€ μ± κ³Ό ꡬκΈλ§μ ν΅ν΄ μ°Έκ³ ν μ½λκ° deprecated λμλ€λ μ€λ₯μ ν¨κ» μμ±λμ§ μλ λΆνΈμ κ²ͺμ΄ ν΄λΉ κΈμ μμ±νλ€.
πν΄κ²°
Spring Security 5.2 μ΄νλ‘ `Configuration` μμ± μ λ©μλ 체μ΄λ λμ λλ€μμ νμ©νκ³ μλ€.
Spring Security 6.0 λ²μ μ΄νλ‘λ κΈ°μ‘΄μ `WebSecurityConfigurerAdapter`λ₯Ό μμνλ λ°©λ² λμ κ°λ°μκ° μ§μ `@Bean`μ λ±λ‘νμ¬ μ¬μ©νλλ‘ λ³κ²½λμλ€.
spring docsμμλ λ€μκ³Ό κ°μ΄ μ€λͺ νκ³ μλ€.
- μ΄μ λ°©μμμλ λ°ν μ νμ΄ λ¬΄μμΈμ§ μμ§ λͺ»ν μ± μ΄λ€ κ°μ²΄κ° ꡬμ±λκ³ μλμ§ λͺ ννμ§ μμμ΅λλ€. μ€μ²©μ΄ κΉμ΄μ§μλ‘ νΌλμ€λ¬μμ‘μ΅λλ€. μλ ¨λ μ¬μ©μλΌλ μμ μ ꡬμ±μ΄ μ€μ λ‘λ λ€λ₯Έ μμ μ μννκ³ μμΌλ©΄μλ νλμ μμ μ μννκ³ μλ€κ³ μ€ν΄ν μ μμ΅λλ€.
- λ§μ μ½λ λ² μ΄μ€κ° λ μ€νμΌ μ¬μ΄μμ μ νλμ΄ κ΅¬μ±μ μ΄ν΄νκΈ° μ΄λ ΅κ² λ§λ€κ³ μ’ μ’ μλͺ»λ ꡬμ±μΌλ‘ μ΄μ΄μ‘μ΅λλ€.
λ©μλ 체μ΄λ λμ λλ€μμ νμ©νλ©΄ κ΄νΈ λ΄μ ν΄λΉ μ€μ μ μμ±ν¨μΌλ‘μ¨ μ΄λ€ μ€μ μ ꡬμ±νκ³ μλμ§ λͺ ννκ² νμ ν μ μλ€.
// before
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests()
.requestMatchers("/blog/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.rememberMe();
return http.build();
}
}
κΈ°μ‘΄μ λ©μλ 체μ΄λ λ°©μ
// after
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/blog/**").permitAll()
.anyRequest().authenticated()
)
.formLogin(formLogin -> formLogin
.loginPage("/login")
.permitAll()
)
.rememberMe(Customizer.withDefaults());
return http.build();
}
}
λ³κ²½ ν λλ€μμ μ΄μ©ν λ°©μ
μλλ κΈ°μ‘΄ λ©μλ 체μ΄λμ λλ€μμΌλ‘ λ³κ²½νμ¬ μμ±ν μμλ€.
(μ°Έκ³ : μλ° μΉ κ°λ° μν¬λΆ p.719)
@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
log.info("-----------security configure------------");
//
// Deprecated
// httpSecurity.formLogin().loginPage("/member/login");
// httpSecurity.csrf().disable();
// httpSecurity.rememberMe()
// .tokenRepository(persistentTokenRepository())
// .userDetailsService(userDetailService)
// .tokenValiditySeconds(60 * 60 * 24 * 30))// μΏ ν€ μ ν¨ μκ° 30μΌ
// httpSecurity.oauth2Login().loginPage("/member/login").successHandler(authenticationSuccessHandler()));
httpSecurity
.formLogin(formLogin -> formLogin
.loginPage("/member/login")) // 컀μ€ν
λ‘κ·ΈμΈ νμ΄μ§
.csrf(AbstractHttpConfigurer::disable)
.rememberMe(rememberMe -> rememberMe // μλ λ‘κ·ΈμΈ μ²λ¦¬
.key("12345678")
.tokenRepository(persistentTokenRepository())
.userDetailsService(userDetailService)
.tokenValiditySeconds(60 * 60 * 24 * 30))// μΏ ν€ μ ν¨ μκ° 30μΌ
.oauth2Login(oauth2Login -> oauth2Login.loginPage("/member/login").successHandler(authenticationSuccessHandler()));
return httpSecurity.build();
}
πμ°Έκ³
μλ° μΉ κ°λ° μν¬λΆ - ꡬλ©κ°κ² μ½λ©λ¨
Configuration Migrations :: Spring Security
The Lambda DSL is present in Spring Security since version 5.2, and it allows HTTP security to be configured using lambdas. You may have seen this style of configuration in the Spring Security documentation or samples. Let us take a look at how a lambda co
docs.spring.io
[μνμ°©μ€] ν! SpringSecurity deprecated λ κ²λ€μ΄ μ€μΌ λ§μ?
μ? Deprecated?? λΉμ!!!! μ°μ°ν ν μ± μ μ€μ΅μ λ°λΌνλ€κ° λ¬Έμ κ° λ°μνλ€! μ¬κΈ°μμ λ§ μ¬λ¬ λΆλΆμμ λ§ deprecated λ¬λ€κ³ λλ¦¬κ° λλ²λ Έλ€. μ΄λ κ² λ§μ΄λ€. μ΄κ² λ¬΄μ¨ λ§μΈμ§ μΆμ΄μ μ΄λ€ μ€λ₯
velog.io
μ΅μ Spring Security μ¬μ©λ² - SecurityFilterChain
Spring Security 5.7.0-M2 λΆν° WebSecurityConfigurerAdapterκ° Deprecated λμκ³ κΈ°μ‘΄μ security μμΈ urlμ μ€μ νλ antMatchersλ μμ μμ λμλ€. νμ§λ§ μμ§κΉμ§ μλ§μ λΈλ‘κ·Έλ€μ μμ Spring security λ²μ μ κΈ°
samori.tistory.com