[Springboot] Spring Security

LV UP·2023년 10월 22일

Backend

목록 보기
5/6

✅Spring Security

  • 스프링 기반 app의 보안(인증, 인가)을 담당하는 스프링 하위 프레임워크
    - 인증 (Authentication) : 사용자의 신원 입증 과정
    - 인가 (Authorization) : 사이트의 특정 부분에 적용 할 수 있는지 권한확인
    • eg) 관리 페이지의 일반 user 접근 제한
  • 필터 기반으로 동작

✅Spring Security Filter

  • 스프링 시큐리티 폼 로그인 인증 흐름 그려보기
필터명설명
SecurityContextPersistenceFilterSecurityContextRepository에서 SecurityContext(접근 주체와 인증에 대한 정보를 담고 있는 객체)를 가져오거나 저장하는 역할을 합니다.
LogoutFilter설정된 로그아웃 url로 오는 요청을 확인해 해당 사용자를 로그아웃 처리합니다.
usernamePasswordAuthenticationFilter인증관리자입니다. 폼 기반 로그인을 할 때 사용되는 필터로 아이디, 패스워드 데이터를 파싱해 인증 요청을 위임합니다. 인증이 성공하면 AuthenticationSuccessHandler를 , 인증에 실패하면 AuthenticationFailureHandler를 실행합니다.
DefaultLoginPageGeneratingFilter사용자가 로그인 페이지를 따로 지정하지 않았을 때 기본으로 설정하는 로그인 페이지 관련 필터입니다.
BasicAuthenticationFilter요청 헤더에 있는 아이디와 패스워드를 파싱해서 인증 요청을 위임합니다. 인증이 성공하면 AuthenticationSuccessHandler를, 인증에 실패하면 AuthenticationFailureHandler 를 실행합니다.
RequestCacheAwareFilter
SecurityContextHolderAwareRequestFilter
AnonymousAuthenticationFilter
SessionManagementFilter
ExceptionTranslationFilter
FilterSecurityInterceptor

✅회원 도메인 만들기

  • 스프링 시큐리티로 인증/인가 기능 구현
  1. 회원 정보 저장할 테이블 만들기
  2. 테이블과 연결할 domain 만들기 (domain이란 데이터 저장 java 객체)
  3. 테이블과 연결할 회원 entity 만들기(DB)
  4. 회원 Entity와 연결되어 데이터를 조회하게 해줄 Repository 만들기
  5. Spring Security에서 사용자 정보를 가져옴
profile
개발 블로그

0개의 댓글