[Spring Security] WebSecurityConfigurerAdapter란?

sonnie
lucky-sonnie
Published in
3 min readSep 21, 2020

--

WebSecurityConfigurerAdapter

사용자 지정 자체 보안 구성을 원할 때, WebSecurityConfigurerAdapter 을 상속받아 구현하면 된다. 이렇게 하면 기본 자동 구성이 비활성화되고 사용자 지정 보안 구성이 활성화 된다. (spring boot 2 부터 지원)

@EnableWebSecurity 어노테이션과 WebSecurityConfigurerAdapter 는 웹 기반 보안을 제공하기 위해 같이 일한다. WebSecurityConfigurerAdapter 와 몇줄의 코드를 통해 우리는 아래의 기능을 가능하게 한다.

  • 애플리케이션 내의 URL에 액세스하기 전에 사용자가 인증을 받아야합니다.
  • 사용자 이름(username) ‘user’, 비밀번호 ‘password’, ‘ROLE_USER’역할의 사용자를 만든다.
  • HTTP 기본 및 form 기반 인증을 가능하게 한다.
  • spring security가 자동으로 login 페이지와 logout 성공 페이지를 자동으로 제공한다.

Configure(WebSecurity) 메서드와 Configure(HttpSecurity)의 차이

  • WebSecurity : 웹을 위한 Security namespace elements와 비슷하다. 특정 요청들을 무시하고 싶을때 쓴다. 모든 웹 보안에 영향을 주는 항목을 구성할 수 있게 한다.
@Override 
public void configure(WebSecurity web) throws Exception { web.ignoring().mvcMatchers("/node_modules/**") .requestMatchers(PathRequest.toStaticResources().atCommonLocations());
}
  • HttpSecurity : namespace 구성 안에 있는 spring security XML<http> 와 비슷하다. 특정 http 요청에 대해 웹 기반 보안을 구성할 수 있다. 디폴트 값으로 모든 요청에 적용되며 , requestMatcher(RequestMatcher) 나 다른 비슷한 메서드를 사용해 제한할 수 있다.
  • WebSecurityConfigurerAdapter는 WebSecurity 와 HttpSecurity 모두 사용자가 원하는대로 맞춤 변경할 수 있도록 하는 편리한 클래스다. WebSecurityConfigurerAdapter를 개별 객체에서 여러번 확장해, 여러 http 요소를 갖는 작업을 여러번 할 수 있다.

번역체 참고 하시고 읽어주세용 ㅎㅎ 구글 번역기와 소현 번역실력임. CS 번역은 어렵당

참조

https://spring.io/blog/2013/07/03/spring-security-java-config-preview-web-security/

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

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

--

--