강의

멘토링

커뮤니티

Cộng đồng Hỏi & Đáp của Inflearn

Hình ảnh hồ sơ của nbc058298756
nbc058298756

câu hỏi đã được viết

Phát triển ứng dụng web dựa trên Spring và JPA

Màn hình đăng ký

지원중단

Đã giải quyết

Viết

·

2.2K

1

- 학습 관련 질문을 남겨주세요. 상세히 작성하면 더 좋아요!
- 먼저 유사한 질문이 있었는지 검색해보세요.
- 서로 예의를 지키며 존중하는 문화를 만들어가요.
- 잠깐! 인프런 서비스 운영 관련 문의는 1:1 문의하기를 이용해주세요.
public class SecurityConfig extends WebSecurityConfigurerAdapter
에서
WebSecurityConfigurerAdapter
 
이게 지원중단이라떠서 더이상 진행이 불가능한데 어떻게 해결할 수 있나요?
 
 
 
 
 
springspring-bootjavaJPAthymeleaf

Câu trả lời 2

3

스프링 시큐리티 5.7.x 부터 WebSecurityConfigurerAdapter 는 Deprecated 되었습니다.

찾아보니 상황에 따라 SecurityFilterChain 과 WebSecurityCustomizer 를 빈으로 등록해 사용하는 방식을 권장하는 것 같아 저는 아래 코드처럼 사용하고 있습니다.

 

https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final AccountService accountService;
private final DataSource dataSource;

/**
* Spring Security 5.7.x 부터 WebSecurityConfigurerAdapter Deprecated.
* -> SecurityFilterChain, WebSecurityCustomizer 를 상황에 따라 빈으로 등록해 사용한다.
*/
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.authorizeRequests()
.mvcMatchers("/", "/login", "/sign-up", "/check-email", "/check-email-token",
"/email-login", "/check-email-login", "login-link", "/profile/*").permitAll()
.mvcMatchers(HttpMethod.GET, "/profile/*").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().logoutSuccessUrl("/")
.and()
.rememberMe().userDetailsService(accountService).tokenRepository(tokenRepository())
.and().build();
}

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring()
.mvcMatchers("/node_modules/**")
.requestMatchers(PathRequest.toStaticResources().atCommonLocations());
}
}
whiteship님의 프로필 이미지
whiteship
Người chia sẻ kiến thức

감사합니다. WebSecurityConfigurerAdapter 문서에서도 이 방법을 권장하고 있습니다.

https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.html

0

저도 궁금합니다!

Hình ảnh hồ sơ của nbc058298756
nbc058298756

câu hỏi đã được viết

Đặt câu hỏi