HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
📝
남득윤 학습 저장소
/
Spring Security
Spring Security
/
Spring Security Authorization Flow
Spring Security Authorization Flow
Spring Security Authorization Flow

Spring Security Authorization Flow

 
💡
스프링 시큐리티의 인가 과정을 학습해보자!
 
시프링 시큐리티는 총 세가지 계층에 권한제어 기능을 제공한다.
  • 웹 계층
    • URL 요청에 따른 메뉴 혹은 화면 단위
  • 서비스 계층
    • 메소드와 같은 기능 단위
  • 도메인 계층
    • 객체 단위

Spring Security Authorization Flow
Spring Security Authorization Flow

FilterSecurityInterceptor

  • 마지막에 위치한 필터
  • 인증 된 사용자의 요청에 대한 승인/거부 여부를 최종적으로 결정
  • 인증 객체가 없다면 AuthenticationException
  • 인가 시도
  • 사용자의 권한이 없다면 AccessDeniedException
  • HTTP 자원의 보안을 처리
  • 권한 처리를 AccessDecisionManager에게 위임
 
인증처리_필터_적용() { 필요한_인증정보 (attributes) = securityMetadataSource.필요한정보(req, resp, chain) if(attributes : Emtpy){ return; }else{ 인증객체 = SecurityContextHolder.인증객체_꺼내기(); if(인증객체 == null){ 인증예외 빵 } 인가_시도( ); 대충_후처리 return; } }
인가 처리 수도 코드 - FilterSecurityInterceptor.doFilter가 호출 된 이후 코드 흐름
 
인가_시도( ) { this.인가매니저.decide(req, resp, attributes, 현재_인증_정보); }
 

SecurityMetadataSource

  • 요청 자원의 권한 정보를 조회 하여 전달
  • 권한이 필요없을 경우 바로 자원 접근 허용함
 

AccessDecisionManager

  • AccessDecisionVoter를 통해 사용자의 권한에 대한 심의
  • 최종적으로 심의를 결정함
class 인가매니저 { void decide(req, resp, attributes, 현재 인증 정보) throws AccessDeniedException { 제주껏 ( - Voter를 활용 할 수 있음) 인가 승인 및 거부 } }
  • 3가지 기본 구현체
    • AffirmativeBased - List<AccessDecisionVoter>중 하나 이상 찬성 하면 승인
    • ConsensusBased - List<AccessDecisionVoter>간의 다수결 (동표일 경우 설정 가능)
    • UanimousBased - List<AccessDecisionVoter>가 만장일치로 간성 일경우 승인