Skip to content

10주차 - 로그인 및 회원가입 #14

@minmin02

Description

@minmin02
  1. 실습 1: Spring Security를 활용한 로그인 및 회원가입 구현 = Session 방식
    • 회원가입, 로그인, 로그아웃 기능을 구현하고 DB에 저장되는 과정을 캡처하고 설명하세요.
  • Security Config
  1. SecurityConfig 로 시큐리티 설정

  2. securityFilterChain 메소드에서 HttpSecurity 객체를 인자값으로 받아 http 요청 접근제어

    1. authorizeHttpRequests 에서
      1. requestMatchers.permitAll() : 접근 허용 URL
      2. .requestMatchers("/admin/**").hasRole("ADMIN") : ADMIN 역할만 허용
      3. .anyRequest().authenticated() 그 외 인증 요구
  3. formLogin 메소드에선 로그인 성공 시 defaultSuccessUrl 로 리다이렉

  • 회원가입 로직에 보안추가
  1. Member 엔티티에 Role 필드 추가
  2. DTO와 컨버터도 이와 맞게 수정
  3. 서비스 로직에 PasswordEncode 추가
  • 로그인
  1. 인증이 필요한 인증 객체 UserDetails인 CustomUserDetails

  2. CustomUserDetails 객체를 인증할 CustomUserDetailsService

  • 로그아웃

SecurityContextHolder를 초기화 시킴

  1. 실습 2: Spring Security를 활용한 로그인 및 회원가입 구현 = JWT 방식
    • 회원가입, 로그인을 구현하고 Swagger에서 테스트 및 DB에 저장되는 과정을 캡처하고 설명하세요.
  • 로그인

  • 회원가입

  1. auth에 JWTUtil 생성
    1. 토큰생성
    2. 이메일 추출
    3. 토큰 유효성 검증 isValid 메서드
  2. auth에 JwtAuthFilter 생성
    1. 클라이언트가 서버에게 전달되기전 인증과정
    2. doFilterInternal 메서드 실행
      1. Authorization 헤더 읽어서 Bearer 뻄 (정제?)
      2. isValid 메서드로 토큰 타당성 체크
      3. 인증 완료 후 인증 객체 생성 후
      4. SecurityContextHolder에 넣기

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions