1. WebSecurity
@Bean
public WebSecurityCustomizer webSecurityCustomizer(){
return (web) ->{
web.ignoring().requestMatchers(PathRequest.toStaticResources().atCommonLocations());
web.ignoring().antMatchers("/favicon.ico", "/resources/**", "/error");
};
}
- antMatchers의 endPoint에 대한 Spring Security Filter Chain을 거치지 않기 때문에 인증과 인가를 거치지 않는다.
- Security Context를 설정하지 않고, Security Features(Secure headers, CSRF protecting 등)가 사용되지 않는다.
- Cross-Site-Scripting(XSS), content-sniffing에 대한 endpoints 보호가 제공되지 않는다.
→ 인증, 인가 서비스가 필요하지 않은 정적자원("/favicon.ico", "/resources/**", "/error")이나 로그인 페이지, public페이지에 사용한다.
2. HttpSecurity
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/user").hasRole("USER")
.antMatchers("/manager").hasRole("MANAGER")
.anyRequest().authenticated()
.and()
.formLogin();
return http.build();
}
antMatchers의 endPoint에 대한 인증을 무시한다.
→ 취약점에 대한 보안이 필요할 때 사용한다.
우선순위
WebSecurity가 우선적으로 동작된다.
***** 아래 게시글을 참고하여 작성했습니다. *****
[Spring] HttpSecurity, WebSecurity의 차이
[Spring] HttpSecurity, WebSecurity의 차이
HttpSecurity와 WebSecurity의 차이점에 대해 찾아본 내용을 정리한 글입니다.antMatchers에 파라미터로 넘겨주는 endpoints는 Spring Security Filter Chain을 거치지 않기 때문에 '인증' , '인가' 서비스가 모두 적용
velog.io
'Spring' 카테고리의 다른 글
@AllArgsConstructor 사용 지양에 따른 리팩토링 (1) | 2023.04.19 |
---|---|
테스트 단 @Transactinal 롤백 (5) | 2023.03.30 |
SpringBoot3.0 Entity생성오류 (0) | 2023.03.30 |
SpringBoot 트랜잭션 직접 다루기 (0) | 2023.03.29 |
jwt인증 403(forbidden)에러 (1) | 2023.03.08 |