본문 바로가기
IT Study/SpringBoot

Spring Security (1)

by Irwin-Kr 2025. 3. 28.

Spring Security란,

인증과 권한 부여, 일반적 공격에 대한 보호를 제공하는 프레임워크

 

👨🏼‍🏫 들어가기 앞서 인증과 권한에 대해 먼저 알아보고 들어가자.

 

인증
    1️⃣인적 증거
    2️⃣인용하여 증거로 삼거나 그 증거
    3️⃣어떠한 문서나 행위가 정당한 절차로 이루어짐을 증명

권한
    ▶️어떤 사람이나 기관의 권리나 권력이 미치는 범위

※ 출처 : 국립국어원 표준국어대사전

 

 

Spring Security에서의 인증은

3️⃣과 같은 표현으로 쓰이고 있음을 염두해 두고

각각의 예시를 작성하였다.

 

인증 : 홈페이지 로그인(=사용자 인증), 본인확인 등
권한 : 멤버쉽에 따른 할인 혜택 부여(Silver, Gold, VIP)
          데이터베이스의 사용자별 접근 부여(A는 a 스키마, B는 b 스키마, C는 a와 b 스키마)

 

Spring Security 특징

👉 통합된 Servlet API

👉 Spring Web MVC와 선택적 통합

👉 인증과 권한에 포괄적이고 확장 가능한 지원

👉 세션고정, 클릭재킹, 사이트 요청 위조 등 공격에 대한 보호

 

Servlet Filter 구조

Servlet Filter를 기반으로 Spring Security의 Servlet을 지원

단일 HTTP 요청에 따른 일반적인 필터 레이어

 

1. Client가 Application에 요청
2. Filter 요소와 Servlet이 포함된 Filter Chain Container 생성
3. 대부분은 1개의 Servlet은 1개의 HttpServletRequest와 HttpServletResponse를 담당하지만, 1개 이상의 필터는
    - Servlet 호출과 Filter 요소의 Downstream을 예방하며, Filter는 HttpServletResponse에 작성
    - Downstream Filter 요소와 Servlet에 사용되는 HttpServletRequest나 HttpServletResponse를 수정

⭐️ Filter는 Downstream Filter 요소와 Servlet에만 영향을 미치기 때문에 호출 순서가 매우 중요하다.

 

DelegatingFilterProxy 구조

Servlet Container의 생명주기와 Spring의 ApplicationContext 연결

표준 Servlet Conatiner 메커니즘을 등록하지만 실행 필터의 모든 동작은 Spring Bean에 위임

Servlet 컨테이너는 자체 표준을 사용해 Filter 요소를 등록하지만 정의된 Spring Bean은 사용불가.

 

Filter요소와 FilterChain 내의 DelegatingFilterProxy

 

 

ApplicationContext로 Bean Filter₀를 조회한 후 실행

public void doFilter(ServletRequest req, SerlvetResponse resp, FilterChain chain){
        // Spring Bean에 등록된 Filter를 지연 조회.
        Filter delegatingF = getFilterBean(<BeanName>);
        // Spring Bean에 작업을 위임.
        delegatingF.doFilter(req, resp);
}

 

다른 이점으로는 Filter Bean 요소를 지연 조회 하는것이다. 이때, Conatiner가 시작전 Filter 요소 등록

일반적으로 Spring은 Spring Bean을 불러오는데 ContextLoderListener 사용하지만,

DelegatingFilterProxy는 Filter 요소를 등록하는 시점까지 완료되지 않음.

 

 

FilterChainProxy 구조

SecurityFilterChain을 통하여 많은 Filter 요소에 위임

FilterChainProxy은 Bean으로써 일반적으로 DelegatingFilterProxy 안에서 동작

FilterChainProxy 순서

 

※ 출처

 

Spring Security

Spring Security is a powerful and highly customizable authentication and access-control framework. It is the de-facto standard for securing Spring-based applications. Spring Security is a framework that focuses on providing both authentication and authoriz

spring.io

 

Servlet Filters and Event Listeners

Servlet filters are used for preprocessing Web application requests and postprocessing responses, as described in the following sections: Overview of Servlet Filters When the servlet container calls a method in a servlet on behalf of the client, the HTTP r

docs.oracle.com

 

'IT Study > SpringBoot' 카테고리의 다른 글

Spring Security 인증 구조 - 2  (0) 2025.06.28
Servlet 인증 구조  (2) 2025.06.14
Spring Security(4)  (1) 2025.05.09
Spring Security(3)  (0) 2025.04.26
Spring Security (2)  (0) 2025.04.11