@EnableGlobalMethodSecurity는 Spring Security 6.0(2022년 11월 릴리즈)부터 더 이상 사용되지 않으며, 대신 새로운 방식으로 변경되었습니다. 이는 스프링 보안 설정을 더욱 직관적이고 간소화하기 위한 변화입니다.
대체: @EnableMethodSecurity
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
@Configuration
@EnableMethodSecurity(prePostEnabled = true)
public class SecurityConfig {
// 보안 설정 관련 코드
}
@EnableMethodSecurity 주요 변경점
- 기능 활성화:
- @EnableGlobalMethodSecurity(prePostEnabled = true)에서 수행하던 작업은 동일합니다.
- prePostEnabled, securedEnabled, jsr250Enabled 속성도 그대로 지원됩니다.
- 유지보수성 향상:
- @EnableMethodSecurity는 기존 @EnableGlobalMethodSecurity의 역할을 개선하고, 새로운 보안 기능과의 호환성을 높이기 위해 설계되었습니다.
사용 예시
메서드 수준 권한 부여 예제
@PreAuthorize, @PostAuthorize를 사용하는 경우:
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
@Service
public class SampleService {
@PreAuthorize("hasRole('ADMIN')")
public String getAdminData() {
return "Admin Data";
}
@PreAuthorize("hasRole('USER')")
public String getUserData() {
return "User Data";
}
}
자바 17 이상 필요
https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
'Spring > Spring Securitiy' 카테고리의 다른 글
6. 인증(Authentication)의 기본 개념과 구조와 Spring Security (0) | 2025.01.23 |
---|---|
5. Spring Security 6 버전 기준 이전 방식(WebSecurityConfigurerAdapter 사용)과 최신 방식(SecurityFilterChain 사용) 비교 (0) | 2025.01.23 |
4. SecurityConfig 기본 사항 (0) | 2025.01.22 |
3. 필터 체인에서 자주 사용되는 시큐리티(보안) 필터 간단하게 정리 (1) | 2025.01.21 |
스프링 시큐리티(Spring Security) 개요 (1) | 2025.01.20 |