Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#35] 로그인한 유저 인증 기능 추가 #38

Merged
merged 11 commits into from
Oct 18, 2024
Merged

[#35] 로그인한 유저 인증 기능 추가 #38

merged 11 commits into from
Oct 18, 2024

Conversation

Srltas
Copy link
Collaborator

@Srltas Srltas commented Oct 9, 2024

📌 Summary

Access Token을 통해 사용자 인증 후, 인증된 사용자 정보를 HttpSession에 저장하여 Controller에서 사용할 수 있도록 하는 로직을 추가했습니다.

📝 Description

AuthenticationFilter

  • Authorization 헤더에서 Bearer 토큰을 추출하여, 이를 SessionStorage에서 조회하여 사용자 정보를 가져옵니다.
  • 조회된 사용자 정보(UserSessionDTO)를 HttpSession에 저장하여 이후 요청에서 사용할 수 있도록 설정합니다.
  • 헤더에 Authorization 또는 저장되어 있는 세션이 조회되지 않으면, 더 이상 요청 작업을 진행하지 않고 에러를 내면서 종료합니다.

SessionStorage

  • 인터페이스로 분리하여 구현한 이유는 추후 Redis와 같은 외부 저장소를 도입할 때 기존 코드를 최소한으로 변경하면서도 손쉽게 확장할 수 있도록 했습니다.
  • 현재는 구체적인 구현 없이 인터페이스만 정의해 두었고, 이후 Redis를 학습한 뒤 이를 기반으로 구현할 계획입니다.

Controller

  • HttpSession을 통해 사용자 정보를 받아 사용할 수 있도록 수정했습니다.

✅ Checklist

  • 코딩 스타일 가이드를 준수했습니다.
  • 새로운 기능이나 수정된 기능에 대해 충분한 테스트를 작성했습니다.
  • 문서(주석, README 등)가 필요하다면 업데이트했습니다.

@Srltas Srltas added the feature Task to add new features label Oct 9, 2024
@Srltas Srltas self-assigned this Oct 9, 2024
- Header에 인증과 키워드들을 상수 클래스로 정의하여 사용
 - AuthenticationFilter는 해당 요청이 로그인된 사용자의 요청인지 확인하는 필터입니다
 - 해당 필터는 요청 당 한 번만 실행되면 되므로 한 번만 실행될 수 있도록 AuthenticationFileter를 상속했습니다.
- filter에서 token이 null인 경우 더 이상 요청을 진행하지 않고 에러를 반환합니다.
- controller에서는 filter에서 인증 처리를 했기 때문에, 더 이상 null 체크는 하지 않습니다.
@Srltas Srltas marked this pull request as ready for review October 12, 2024 16:22
@Srltas Srltas added the needs review Code review required label Oct 13, 2024
@Srltas Srltas marked this pull request as draft October 14, 2024 12:55
- Controller와 Filter 두 곳에 URL 관리의 편의성을 위해 constant 클래스를 만들어 한 곳에서 관리합니다
- 로그인 기능을 개발하기 전까지 테스트용으로 사용할 SessionStorage 구현체입니다
@Srltas Srltas marked this pull request as ready for review October 14, 2024 14:43
@Srltas
Copy link
Collaborator Author

Srltas commented Oct 14, 2024

로그인 기능을 개발하기 전까지 테스트용으로 사용할 임시 SessionStorage 구현체를 만들어 적용했습니다.

Copy link
Collaborator

@f-lab-bradley f-lab-bradley left a comment

Choose a reason for hiding this comment

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

수고하셨습니다~

- 저장소에서 유저가 존재하는지 확인하는 메소드(authenticateUser)가 확인 뿐만 아니라 request에 유저 정보를 넣는 역할까지 맞고 있어 책임 분리
- 역할을 명확하게 하기 위해 기존 메소드의 이름을 authenticateUser -> isNullUserSessionDTO로 변경
- doFilterInternal에서 request에 유저 정보를 넣어 Controller에게 전달하는 역할 수행
- 토큰이 null인 경우 저장소에서 유저를 확인하지 않고, 바로 예외 처리를 할 수 있도록 로직 수정
@Srltas Srltas merged commit 3cf7c41 into main Oct 18, 2024
1 check passed
@Srltas Srltas deleted the issue_35 branch October 18, 2024 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Task to add new features needs review Code review required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants