Skip to content

Conversation

@fakerdeft
Copy link
Contributor

📋 Checklist

  • 🔀 PR 제목의 형식을 잘 작성했나요? (e.g. [APP2-77] feat: 회원 인증 Filter 구현)
  • 💯 테스트는 잘 통과했나요?
  • 🏗️ 빌드에 성공했나요?
  • 🧹 불필요한 코드는 제거했나요?

🎟️ Issue

✅ Tasks
※ 원기옥 죄송합니다 다음엔 분량 적게 PR 하도록 할게여

세션 인증 필터 구현, 회원 엔티티 구현

회원 엔티티

  • PK 값으로 TSID 사용
  • 라이브러리: io.hypersistence:hypersistence-utils-hibernate-63:3.9.0
  • TSID 어노테이션으로 DB에 PK 자동 생성되는 테스트 진행 및 성공 확인

세션 구조

  • key: member tsid (pk)
  • value: json 형태 {"lastAccessTime" : "", "userAgent": "", "clientIp": ""}

세션 스토리지

  • Redis
  • 세션 당 만료 기간: 48시간

세션 인증 필터 동작 순서

  1. 요청이 들어오면 허용 URI 검증
    1-1. 허용 URI는 검증 과정 없이 바로 다음 필터로 진행
  2. 요청에서 헤더의 세션 유무 검증
    2-1. 세션이 없으면 예외 발생
  3. 세션의 회원 id(key)로 Redis에서 조회
    3-1. Redis에 없으면 예외 발생
  4. Redis에 회원 세션 존재하면 유효 기간 검증
    4-1. 유효 기간 만료된 세션은 Redis에서 삭제하고 예외 발생
  5. 기존 세션 유효 기간 갱신
  6. Securiy Context에 회원 인증 정보 저장하고 다음 필터로 진행

클라이언트에서 회원 이상 권한 API 요청 시

  • HTTP Header에 아래와 같이 보내야 함
  • ex. Authorization : Bearer 123456...

추가 작업

  • CORS 설정은 앱 통신 간엔 필요없다고 해서 전부 제거했습니다.

🙋🏻 More

  • Session Authentication Filter Test
    image

  • Session Service Test
    image

  • Member Test
    image
    image


public String authenticate(HttpServletRequest request) {
String authHeader = request.getHeader(AUTHORIZATION_HEADER);
String sessionId;
Copy link
Member

@ymkim97 ymkim97 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아까 초기화가 안되는 것들은 위에 두자고 했지만 그거는 로직상 어쩔 수 없을때만 하고 웬만해서는 중간에 String sessionId = authHeader.substring(SESSION_ID_PREFIX.length());가 더 좋을 것 같긴 합니다 ㅎㅎ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 중간에 다시 수정해서 푸쉬할게요 !!

String queryString = request.getQueryString();

log.info("들어온 요청 - URI: {}, Query: {}, Method: {}", requestUri, queryString != null ? queryString : "쿼리 스트링 없음",
request.getMethod());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log들은 로직에 섞여 보이지 않게 개행 처리로 구분해주는건 어떨까요!? 다른쪽들도 다 마찬가지 입니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 좋습니다 바로 수정 들어가겠습니다 !!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 7, 2025

Copy link
Member

@ymkim97 ymkim97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~~!!!!

@fakerdeft fakerdeft merged commit 9d4e746 into develop Jan 7, 2025
2 checks passed
@fakerdeft fakerdeft deleted the feature/TNT-28 branch January 7, 2025 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔧 config 설정 관련 작업 ✨ feature 새로운 기능 개발 ✅ test 테스트 코드 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

인증 기능 구현하기

3 participants