Spring
[Spring] Spring Security에서 HttpSecurity와 WebSecurity의 차이
llshl
2022. 2. 16. 17:47
반응형
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/")
.antMatchers("/ping");
}
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/v1/**").authenticated();
}
개발하며 위처럼 파라미터가 다른 두 configure를 재정의해서 사용할 일이 있었다.
HttpSecurity 패턴은 보안처리
WebSecurity 패턴은 보안예외처리 (정적리소스나 health check)
WebSecurity 패턴은 HttpSecurity패턴이 정의되어야 사용할 수 있다.
configure (WebSecurity)
- antMatchers에 파라미터로 넘겨주는 endpoints는 Spring Security Filter Chain을 거치지 않기 때문에 '인증' , '인가' 서비스가 모두 적용되지 않는다.
- 또한 Security Context를 설정하지 않고, Security Features(Secure headers, CSRF protecting 등)가 사용되지 않는다.
- Cross-Site-Scripting(XSS), content-sniffing에 대한 endpoints 보호가 제공되지 않는다.
- 일반적으로 로그인 페이지, public 페이지 등 인증, 인가 서비스가 필요하지 않은 endpoint에 사용한다.
configure (HttpSecurity)
- antMatchers에 있는 endpoint에 대한 '인증'을 무시한다.
- Security Filter Chain에서 요청에 접근할 수 있기 때문에(요청이 security filter chain 거침) 인증, 인가 서비스와 Secure headers, CSRF protection 등 같은 Security Features 또한 사용된다.
- 취약점에 대한 보안이 필요할 경우 HttpSecurity 설정을 사용해야 한다.
참고:
반응형