-
Notifications
You must be signed in to change notification settings - Fork 0
π File Directory Refactor #30
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
Changes from all commits
e1eee4b
a56d475
aa51a67
ff09a4e
d6c1d3f
7ea7c93
9bc6dbe
d0db443
15b650b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,14 @@ | ||
| package com.mycom.socket.auth.controller; | ||
|
|
||
| import com.mycom.socket.auth.dto.request.EmailRequestDto; | ||
| import com.mycom.socket.auth.dto.request.EmailVerificationRequestDto; | ||
| import com.mycom.socket.auth.dto.request.LoginRequestDto; | ||
| import com.mycom.socket.auth.dto.request.RegisterRequestDto; | ||
| import com.mycom.socket.auth.dto.response.EmailVerificationCheckResponseDto; | ||
| import com.mycom.socket.auth.dto.response.EmailVerificationResponseDto; | ||
| import com.mycom.socket.auth.dto.response.LoginResponseDto; | ||
| import com.mycom.socket.auth.dto.request.EmailRequest; | ||
| import com.mycom.socket.auth.dto.request.EmailVerificationRequest; | ||
| import com.mycom.socket.auth.dto.request.LoginRequest; | ||
| import com.mycom.socket.auth.dto.request.RegisterRequest; | ||
| import com.mycom.socket.auth.dto.response.EmailVerificationResponse; | ||
| import com.mycom.socket.auth.dto.response.LoginResponse; | ||
| import com.mycom.socket.auth.dto.response.RegisterResponse; | ||
| import com.mycom.socket.auth.service.AuthService; | ||
| import com.mycom.socket.auth.service.MailService; | ||
| import com.mycom.socket.auth.service.RateLimiter; | ||
| import com.mycom.socket.global.exception.BaseException; | ||
| import jakarta.servlet.http.HttpServletResponse; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
@@ -23,44 +21,31 @@ public class AuthController { | |
|
|
||
| private final AuthService authService; | ||
| private final MailService mailService; | ||
| private final RateLimiter rateLimiter; | ||
|
|
||
| @PostMapping("/login") | ||
| public LoginResponseDto login(@Valid @RequestBody LoginRequestDto request, | ||
| HttpServletResponse response) { | ||
| public LoginResponse login(@Valid @RequestBody LoginRequest request, | ||
| HttpServletResponse response) { | ||
| return authService.login(request, response); | ||
| } | ||
|
|
||
| @PostMapping("/register") | ||
| public RegisterResponse register(@Valid @RequestBody RegisterRequest request) { | ||
| return authService.register(request); | ||
| } | ||
|
|
||
| @PostMapping("/logout") | ||
| public void logout(HttpServletResponse response) { | ||
| authService.logout(response); | ||
| } | ||
|
|
||
| @PostMapping("/register") | ||
| public Long register(@Valid @RequestBody RegisterRequestDto request) { | ||
| return authService.register(request); | ||
| } | ||
|
|
||
| @PostMapping("/verification") | ||
| public EmailVerificationResponseDto mailSend(@Valid @RequestBody EmailRequestDto emailRequestDto) { | ||
| try { | ||
| boolean isSuccess = mailService.sendMail(emailRequestDto.email()); | ||
| return isSuccess ? EmailVerificationResponseDto.createSuccessResponse() : EmailVerificationResponseDto.createFailureResponse("μ΄λ©μΌ μ μ‘μ μ€ν¨νμ΅λλ€."); | ||
| } catch (BaseException e) { | ||
| return EmailVerificationResponseDto.createFailureResponse(e.getMessage()); | ||
| } | ||
| public EmailVerificationResponse sendVerificationEmail(@Valid @RequestBody EmailRequest request) { | ||
| return mailService.sendMail(request.email()); | ||
| } | ||
|
|
||
| @PostMapping("/email/verify") | ||
| public EmailVerificationCheckResponseDto mailCheck(@Valid @RequestBody EmailVerificationRequestDto emailRequestDto) { | ||
| try{ | ||
| rateLimiter.checkRateLimit(emailRequestDto.email());// μλ νμ μ ν | ||
| boolean isVerified = mailService.verifyCode(emailRequestDto.email(), emailRequestDto.code()); | ||
| return isVerified ? EmailVerificationCheckResponseDto.createSuccessResponse() : | ||
| EmailVerificationCheckResponseDto.createFailureResponse("μ΄λ©μΌ μΈμ¦μ μ€ν¨νμ΅λλ€."); | ||
| }catch (BaseException e){ | ||
| return EmailVerificationCheckResponseDto.createFailureResponse(e.getMessage()); | ||
| } | ||
| public EmailVerificationResponse verifyEmail(@Valid @RequestBody EmailVerificationRequest request) { | ||
| return mailService.verifyCode(request.email(), request.code()); | ||
|
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion μμΈ μ²λ¦¬λ₯Ό μΆκ°νμ¬ μμ μ±μ ν₯μμν€μμμ€.
|
||
| } | ||
|
|
||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.mycom.socket.auth.dto.response; | ||
|
|
||
| public record EmailVerificationResponse( | ||
| String message | ||
| ) { | ||
| public static EmailVerificationResponse of(String message) { | ||
| return new EmailVerificationResponse(message); | ||
| } | ||
| } | ||
|
|
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.mycom.socket.auth.dto.response; | ||
|
|
||
| public record LoginResponse( | ||
| String email, | ||
| String nickname | ||
| ) { | ||
| public static LoginResponse of(String email, String nickname) { | ||
| return new LoginResponse(email, nickname); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.mycom.socket.auth.dto.response; | ||
|
|
||
| public record RegisterResponse( | ||
| Long memberId, | ||
| String email, | ||
| String nickname, | ||
| String message | ||
| ) { | ||
| public static RegisterResponse of(Long memberId, String email, String nickname) { | ||
| return new RegisterResponse(memberId, email, nickname, "νμκ°μ μ΄ μλ£λμμ΅λλ€."); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||||
| package com.mycom.socket.auth.jwt; | ||||||||
| import lombok.Getter; | ||||||||
| import lombok.Setter; | ||||||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||||||||
| import org.springframework.stereotype.Component; | ||||||||
|
|
||||||||
| @Getter | ||||||||
| @Setter | ||||||||
| @Component | ||||||||
| @ConfigurationProperties(prefix = "jwt") | ||||||||
| public class JWTProperties { | ||||||||
| private String secret; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JWT secret νλμ λν μ ν¨μ± κ²μ¬ νμ JWT secretμ νμ κ°μ΄λ―λ‘ - private String secret;
+ @NotEmpty(message = "JWT secretμ νμ κ°μ
λλ€.")
+ private String secret;π Committable suggestion
Suggested change
|
||||||||
| private long accessTokenValidityInSeconds = 1800; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π οΈ Refactor suggestion ν ν° μ ν¨ κΈ°κ°μ λν μ΅μκ° κ²μ¦ νμ ν ν° μ ν¨ κΈ°κ°μ΄ λ무 μ§§μ§ μλλ‘ μ΅μκ° κ²μ¦μ΄ νμν©λλ€. - private long accessTokenValidityInSeconds = 1800;
+ @Min(value = 300, message = "ν ν° μ ν¨ κΈ°κ°μ μ΅μ 5λΆ μ΄μμ΄μ΄μΌ ν©λλ€.")
+ private long accessTokenValidityInSeconds = 1800;π Committable suggestion
Suggested change
|
||||||||
| private String cookieName = "Authorization"; | ||||||||
| private String issuer = "go_socket"; | ||||||||
| private boolean secureCookie = false; | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π‘ Codebase verification 보μ μΏ ν€ μ€μ λ¬Έμ νμΈλ¨ νμ¬ κ΅¬μ±μμ λ€μκ³Ό κ°μ μ¬κ°ν 보μ λ¬Έμ κ° νμΈλμμ΅λλ€:
νλ‘λμ νκ²½μ 보μμ μν΄ λ°λμ secureCookieλ₯Ό trueλ‘ μ€μ ν΄μΌ ν©λλ€. π Analysis chain보μ μΏ ν€ μ€μ κ²ν νμ νλ‘λμ
νκ²½μμλ 보μ μΏ ν€λ₯Ό νμ±νν΄μΌ ν©λλ€. νμ¬ κΈ°λ³Έκ°μ΄ π Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check if secureCookie is properly configured in different environments
# Check application properties files for secure cookie configuration
echo "Checking application properties files for secure cookie configuration..."
rg -l "jwt\.secure-cookie"
Length of output: 183 Script: #!/bin/bash
# Search for various possible property naming patterns
echo "Checking different property naming patterns..."
rg -l "jwt\.(secure-?cookie|cookie\.secure|secureCookie)"
echo -e "\nChecking for application properties/yml files..."
fd -e properties -e yml
echo -e "\nChecking for security configuration classes..."
fd -e java -x grep -l "SecurityConfig\|WebSecurityConfig"
Length of output: 730 Script: #!/bin/bash
echo "Checking application.yml content..."
cat src/main/resources/application.yml
echo -e "\nChecking application-dev.yml content..."
cat src/main/resources/yaml/application-dev.yml
echo -e "\nChecking SecurityConfig.java for cookie configurations..."
cat src/main/java/com/mycom/socket/auth/config/SecurityConfig.java
Length of output: 2900 |
||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,10 @@ | ||
| package com.mycom.socket.auth.jwt; | ||
|
|
||
| import io.jsonwebtoken.Claims; | ||
| import io.jsonwebtoken.Jwts; | ||
| import io.jsonwebtoken.security.Keys; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| import javax.crypto.SecretKey; | ||
| import java.nio.charset.StandardCharsets; | ||
|
|
@@ -16,42 +15,60 @@ | |
| public class JWTUtil { | ||
|
|
||
| private final SecretKey secretKey; | ||
| private final JWTProperties jwtProperties; | ||
|
|
||
| public JWTUtil(@Value("${jwt.secret}") String secret) { | ||
| this.secretKey = Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8)); | ||
| public JWTUtil(JWTProperties jwtProperties) { | ||
| this.jwtProperties = jwtProperties; | ||
| this.secretKey = Keys.hmacShaKeyFor( | ||
| jwtProperties.getSecret().getBytes(StandardCharsets.UTF_8) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * JWT ν ν° μμ± | ||
| */ | ||
| public String createToken(String email) { | ||
| Claims claims = Jwts.claims().subject(email).build(); | ||
| Date now = new Date(); | ||
| // 30λΆ | ||
| long accessTokenValidityInMilliseconds = 1000 * 60 * 30; | ||
| Date validity = new Date(now.getTime() + accessTokenValidityInMilliseconds); | ||
| Date validity = new Date(now.getTime() + | ||
| (jwtProperties.getAccessTokenValidityInSeconds() * 1000)); | ||
|
|
||
| return Jwts.builder() | ||
| .claims(claims) | ||
| .issuer(jwtProperties.getIssuer()) | ||
| .subject(email) | ||
| .issuedAt(now) | ||
| .expiration(validity) | ||
| .signWith(secretKey) | ||
| .compact(); | ||
| } | ||
|
|
||
| /** | ||
| * ν ν° μ ν¨μ± κ²μ¦ | ||
| */ | ||
| public boolean validateToken(String token) { | ||
| try { | ||
| if (!StringUtils.hasText(token)) { | ||
| return false; | ||
| } | ||
|
|
||
| Jwts.parser() | ||
| .verifyWith(secretKey) | ||
| .requireIssuer(jwtProperties.getIssuer()) | ||
| .build() | ||
| .parseSignedClaims(token); | ||
| return true; | ||
| } catch (Exception e) { | ||
| log.warn("JWT ν ν° κ²μ¦ μ€ μλ¬ λ°μ: {}", e.getMessage()); | ||
| log.warn("JWT ν ν° κ²μ¦ μ€ν¨", e); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. μμΈ λ©μμ§μ λ―Όκ°ν μ λ³΄κ° ν¬ν¨λμ§ μλλ‘ λ‘κ·Έλ₯Ό κ°μ νμμμ€.
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * ν ν°μμ μ΄λ©μΌ μΆμΆ | ||
| */ | ||
| public String getEmail(String token) { | ||
| return Jwts.parser() | ||
| .verifyWith(secretKey) | ||
| .requireIssuer(jwtProperties.getIssuer()) | ||
| .build() | ||
| .parseSignedClaims(token) | ||
| .getPayload() | ||
|
|
||
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
μμΈ μ²λ¦¬λ₯Ό μΆκ°νμ¬ μμ μ±μ ν₯μμν€μμμ€.
sendVerificationEmailλ©μλμμ μ΄λ©μΌ μ μ‘ μ€ λ°μν μ μλ μμΈμ λν μ²λ¦¬κ° μμ΅λλ€. μ΄λ©μΌ μ μ‘ μ€ν¨ μ μ¬μ©μμκ² μ μ ν νΌλλ°±μ μ 곡ν μ μλλ‘ μμΈ μ²λ¦¬λ₯Ό μΆκ°νλ κ²μ΄ μ’μ΅λλ€.