-
Notifications
You must be signed in to change notification settings - Fork 0
π Profile Search #37
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
Conversation
|
Warning Rate limit exceeded@ohyuchan123 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 18 seconds before requesting another review. β How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. π¦ How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. π Files selected for processing (2)
Walkthroughμ΄ ν 리νμ€νΈλ νλ‘ν κ΄λ¦¬ λ° μΈμ¦ λ©μ»€λμ¦μ λν μ€μν λ³κ²½ μ¬νμ ν¬ν¨νκ³ μμ΅λλ€. JWT ν ν° μΈμ¦ λ°©μμ΄ μΏ ν€ κΈ°λ°μμ ν€λ κΈ°λ°μΌλ‘ λ³κ²½λμμΌλ©°, μλ‘μ΄ Changes
Sequence DiagramsequenceDiagram
participant Client
participant JWTFilter
participant AuthenticationManager
participant ProfileController
participant MemberService
Client->>JWTFilter: HTTP Request with Bearer Token
JWTFilter->>JWTFilter: Resolve Token from Header
JWTFilter->>AuthenticationManager: Authenticate Token
AuthenticationManager-->>JWTFilter: Authentication Success
Client->>ProfileController: GET /api/profile
ProfileController->>MemberService: Retrieve Member Details
MemberService-->>ProfileController: Return Member Information
ProfileController-->>Client: Return ProfileResponse
Possibly related PRs
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
π§Ή Nitpick comments (1)
src/main/resources/yaml/application-dev.yml (1)
5-5: νμΌ λμ κ°ν λ¬Έμλ₯Ό μΆκ°ν΄μ£ΌμΈμ.YAML νμΌ νμ€μ λ°λΌ νμΌ λμ κ°ν λ¬Έμκ° νμν©λλ€.
spring: jpa: show-sql: true hibernate: - ddl-auto: update + ddl-auto: update +π§° Tools
πͺ yamllint (1.35.1)
[error] 5-5: no new line character at the end of file
(new-line-at-end-of-file)
π Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
π Files selected for processing (5)
src/main/java/com/mycom/socket/auth/jwt/JWTFilter.java(2 hunks)src/main/java/com/mycom/socket/go_socket/controller/ProfileController.java(1 hunks)src/main/java/com/mycom/socket/go_socket/dto/response/ProfileResponse.java(1 hunks)src/main/java/com/mycom/socket/go_socket/service/MemberService.java(1 hunks)src/main/resources/yaml/application-dev.yml(1 hunks)
π§° Additional context used
πͺ yamllint (1.35.1)
src/main/resources/yaml/application-dev.yml
[error] 5-5: no new line character at the end of file
(new-line-at-end-of-file)
π Additional comments (1)
src/main/resources/yaml/application-dev.yml (1)
5-5: λ°μ΄ν°λ² μ΄μ€ μ€ν€λ§ κ΄λ¦¬ μ λ΅ λ³κ²½μ λν κ²ν κ° νμν©λλ€.
ddl-auto: updateμ€μ μ κΈ°μ‘΄ λ°μ΄ν°λ₯Ό 보쑴νλ©΄μ μ€ν€λ§λ₯Ό μ λ°μ΄νΈνλ―λ‘ κ°λ° κ³Όμ μμ λ°μ΄ν° μ§μμ±μ κ°μ ν©λλ€. νμ§λ§ λ€μ μ¬νμ κ³ λ €ν΄μ£ΌμΈμ:
- μ€ν€λ§ λ³κ²½ μ΄λ ₯ κ΄λ¦¬λ₯Ό μν΄ Flywayλ Liquibase κ°μ λ§μ΄κ·Έλ μ΄μ λꡬ λμ μ κ²ν ν΄λ³΄μΈμ.
- νλ‘λμ νκ²½μμλ
validateλͺ¨λ μ¬μ©μ κΆμ₯λ립λλ€.λ€μ μ€ν¬λ¦½νΈλ‘ νμ¬ νλ‘μ νΈμ νλ‘νλ³ μ€μ μ νμΈν΄λ³΄μΈμ:
β Verification successful
λ°μ΄ν°λ² μ΄μ€ ꡬμ±μ΄ μ μ νκ² μ€μ λμ΄ μμ΅λλ€.
κΈ°λ³Έ νλ‘νμΌμμ
ddl-auto: noneμ μ¬μ©νκ³ κ°λ° νλ‘νμΌμμλ§updateλͺ¨λλ₯Ό νμ±ννλ νμ¬ μ€μ μ μμ νκ³ μ μ ν©λλ€. λ€λ§, μ μ λλ¦° λλ‘ ν₯ν λ°μ΄ν°λ² μ΄μ€ λ§μ΄κ·Έλ μ΄μ λꡬ λμ μ κ³ λ €ν΄λ³΄μλ©΄ μ’κ² μ΅λλ€.π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check database configuration across different profiles echo "Checking database configuration across profiles..." fd -e yml -e yaml . src/main/resources | xargs grep -l "ddl-auto"Length of output: 255
Script:
#!/bin/bash # Check the database configuration in both files echo "=== Default Profile (application.yml) ===" rg -A 5 -B 5 "ddl-auto" src/main/resources/application.yml echo -e "\n=== Dev Profile (application-dev.yml) ===" rg -A 5 -B 5 "ddl-auto" src/main/resources/yaml/application-dev.ymlLength of output: 518
π§° Tools
πͺ yamllint (1.35.1)
[error] 5-5: no new line character at the end of file
(new-line-at-end-of-file)
| public class MemberService { | ||
|
|
||
| private final MemberRepository memberRepository; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλΉμ€ ν΄λμ€μ νμν λ©μλ ꡬνμ΄ λλ½λμμ΅λλ€.
νμ¬ MemberService ν΄λμ€κ° λΉμ΄μμ΅λλ€. νλ‘ν μ‘°ν κΈ°λ₯μ μν΄ λ€μκ³Ό κ°μ λ©μλλ€μ ꡬνμ΄ νμν©λλ€:
- νμ νλ‘ν μ‘°ν
- νμ μ‘΄μ¬ μ¬λΆ νμΈ
- μμΈ μ²λ¦¬ λ‘μ§
λ€μκ³Ό κ°μ λ©μλ ꡬνμ μ μλ립λλ€:
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemberService {
private final MemberRepository memberRepository;
+
+ public Member getMemberByEmail(String email) {
+ return memberRepository.findByEmail(email)
+ .orElseThrow(() -> new EntityNotFoundException("νμμ μ°Ύμ μ μμ΅λλ€."));
+ }
+
+ public boolean existsByEmail(String email) {
+ return memberRepository.existsByEmail(email);
+ }
}Committable suggestion skipped: line range outside the PR's diff.
| public static ProfileResponse of(Member member) { | ||
| return new ProfileResponse( | ||
| member.getEmail(), | ||
| member.getNickname(), | ||
| member.getIntro() | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
ν©ν 리 λ©μλμ μ ν¨μ± κ²μ¬μ λ¬Έμνκ° νμν©λλ€.
of λ©μλμ λ€μ μ¬νλ€μ΄ λλ½λμ΄ μμ΅λλ€:
- null 체ν¬
- JavaDoc λ¬Έμν
- λ―Όκ°ν μ 보 λ ΈμΆ κ°λ₯μ± κ²ν
λ€μκ³Ό κ°μ΄ κ°μ μ μ μλ립λλ€:
+ /**
+ * Member μν°ν°λ‘λΆν° ProfileResponseλ₯Ό μμ±ν©λλ€.
+ *
+ * @param member νλ‘ν μ 보λ₯Ό κ°μ Έμ¬ νμ μν°ν° (nullμ΄ μλμ΄μΌ ν¨)
+ * @return μμ±λ ProfileResponse κ°μ²΄
+ * @throws IllegalArgumentException memberκ° nullμΈ κ²½μ°
+ */
public static ProfileResponse of(Member member) {
+ if (member == null) {
+ throw new IllegalArgumentException("Member must not be null");
+ }
+
return new ProfileResponse(
member.getEmail(),
member.getNickname(),
member.getIntro()
);
}π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| public static ProfileResponse of(Member member) { | |
| return new ProfileResponse( | |
| member.getEmail(), | |
| member.getNickname(), | |
| member.getIntro() | |
| ); | |
| } | |
| /** | |
| * Member μν°ν°λ‘λΆν° ProfileResponseλ₯Ό μμ±ν©λλ€. | |
| * | |
| * @param member νλ‘ν μ 보λ₯Ό κ°μ Έμ¬ νμ μν°ν° (nullμ΄ μλμ΄μΌ ν¨) | |
| * @return μμ±λ ProfileResponse κ°μ²΄ | |
| * @throws IllegalArgumentException memberκ° nullμΈ κ²½μ° | |
| */ | |
| public static ProfileResponse of(Member member) { | |
| if (member == null) { | |
| throw new IllegalArgumentException("Member must not be null"); | |
| } | |
| return new ProfileResponse( | |
| member.getEmail(), | |
| member.getNickname(), | |
| member.getIntro() | |
| ); | |
| } |
| @GetMapping | ||
| public ProfileResponse getProfile(@AuthenticationPrincipal MemberDetails memberDetails) { | ||
| return ProfileResponse.of(memberDetails.getMember()); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
컨νΈλ‘€λ¬μ μμΈ μ²λ¦¬μ API λ¬Έμνκ° νμν©λλ€.
λ€μ μ¬νλ€μ΄ λλ½λμ΄ μμ΅λλ€:
- μλ΅ μν μ½λ λͺ μ
- Swagger/OpenAPI λ¬Έμν
- μμΈ μ²λ¦¬
- λ‘κΉ
λ€μκ³Ό κ°μ΄ κ°μ μ μ μλ립λλ€:
+ private final Logger log = LoggerFactory.getLogger(ProfileController.class);
+
+ /**
+ * νμ¬ μΈμ¦λ μ¬μ©μμ νλ‘ν μ 보λ₯Ό μ‘°νν©λλ€.
+ *
+ * @param memberDetails μΈμ¦λ μ¬μ©μ μ 보
+ * @return μ¬μ©μ νλ‘ν μ 보
+ */
@GetMapping
+ @ResponseStatus(HttpStatus.OK)
+ @Operation(summary = "νλ‘ν μ‘°ν", description = "νμ¬ λ‘κ·ΈμΈν μ¬μ©μμ νλ‘ν μ 보λ₯Ό μ‘°νν©λλ€.")
+ @ApiResponse(responseCode = "200", description = "νλ‘ν μ‘°ν μ±κ³΅")
+ @ApiResponse(responseCode = "401", description = "μΈμ¦λμ§ μμ μ¬μ©μ")
public ProfileResponse getProfile(@AuthenticationPrincipal MemberDetails memberDetails) {
+ log.debug("νλ‘ν μ‘°ν μμ²: {}", memberDetails.getUsername());
+ if (memberDetails == null) {
+ throw new UnauthorizedException("μΈμ¦ μ λ³΄κ° μμ΅λλ€.");
+ }
return ProfileResponse.of(memberDetails.getMember());
}Committable suggestion skipped: line range outside the PR's diff.
| // Bearer ν ν° νμΈ | ||
| String bearerToken = resolveTokenFromHeader(request); | ||
| if (StringUtils.hasText(bearerToken) && jwtUtil.validateToken(bearerToken, "ACCESS_TOKEN")) { | ||
| setAuthentication(bearerToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
JWT ν ν° μ²λ¦¬ λ‘μ§ λ³΄μ κ°νκ° νμν©λλ€.
νμ¬ κ΅¬νμμ λ€μκ³Ό κ°μ 보μ κ΄λ ¨ κ°μ μ¬νμ΄ νμν©λλ€:
- Bearer μ λμ¬ μμν
- ν ν° νμ κ²μ¦ κ°ν
- ꡬ체μ μΈ μμΈ μ²λ¦¬
λ€μκ³Ό κ°μ΄ κ°μ μ μ μλ립λλ€:
+ private static final String BEARER_PREFIX = "Bearer ";
+ private static final String TOKEN_TYPE = "ACCESS_TOKEN";
+
try {
- // Bearer ν ν° νμΈ
String bearerToken = resolveTokenFromHeader(request);
- if (StringUtils.hasText(bearerToken) && jwtUtil.validateToken(bearerToken, "ACCESS_TOKEN")) {
+ if (isValidBearerToken(bearerToken)) {
setAuthentication(bearerToken);
}
} catch (Exception e) {private boolean isValidBearerToken(String token) {
return StringUtils.hasText(token) &&
token.matches("^[A-Za-z0-9-_=]+\\.[A-Za-z0-9-_=]+\\.?[A-Za-z0-9-_.+/=]*$") &&
jwtUtil.validateToken(token, TOKEN_TYPE);
}| private String resolveTokenFromHeader(HttpServletRequest request) { | ||
| String bearerToken = request.getHeader("Authorization"); | ||
| if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { | ||
| return bearerToken.substring(7); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
ν ν° μΆμΆ λ©μλμ 보μμ± κ°νκ° νμν©λλ€.
ν ν° μΆμΆ μ λ€μκ³Ό κ°μ 보μ κ²μ¦μ΄ μΆκ°λμ΄μΌ ν©λλ€:
- ν€λ μ‘΄μ¬ μ¬λΆ κ²μ¦
- ν ν° κΈΈμ΄ μ ν
- XSS λ°©μ§λ₯Ό μν λ¬Έμμ΄ μ΄μ€μΌμ΄ν
λ€μκ³Ό κ°μ΄ κ°μ μ μ μλ립λλ€:
private String resolveTokenFromHeader(HttpServletRequest request) {
String bearerToken = request.getHeader("Authorization");
- if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) {
- return bearerToken.substring(7);
+ if (!StringUtils.hasText(bearerToken)) {
+ return null;
+ }
+ if (!bearerToken.startsWith(BEARER_PREFIX)) {
+ log.warn("μλͺ»λ ν ν° νμ: Bearer μ λμ¬ μμ");
+ return null;
+ }
+ String token = bearerToken.substring(BEARER_PREFIX.length());
+ if (token.length() > 1000) { // μ΅λ ν ν° κΈΈμ΄ μ ν
+ log.warn("ν ν° κΈΈμ΄ μ΄κ³Ό");
+ return null;
}
- return null;
+ return HtmlUtils.htmlEscape(token);
}Committable suggestion skipped: line range outside the PR's diff.
π κ΄λ ¨ μ΄μ
#31 μ¬μ©μ νλ‘ν μ‘°ν
β¨ κ³Όμ λ΄μ©
μ¬μ©μλ μμ μ νλ‘νμ μ‘°νν μ μμ΅λλ€.
πΈ μ€ν¬λ¦°μ·(μ ν)
π λ νΌλ°μ€ (λλ μλ‘ μκ² λ λ΄μ©) νΉμ κΆκΈν μ¬νλ€
Summary by CodeRabbit
μλ‘μ΄ κΈ°λ₯
λ²κ·Έ μμ
κΈ°ν λ³κ²½μ¬ν