-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from twenty-three-23/dev
V 1.1.0 배포
- Loading branch information
Showing
104 changed files
with
2,364 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/twentythree/peech/auth/controller/AuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.twentythree.peech.auth.controller; | ||
|
||
import com.twentythree.peech.auth.service.ReissueAccessAndRefreshTokenService; | ||
import com.twentythree.peech.user.dto.AccessAndRefreshToken; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class AuthController { | ||
|
||
private final ReissueAccessAndRefreshTokenService reissueAccessAndRefreshTokenService; | ||
|
||
@PostMapping("api/v1.1/auth/reissue") | ||
public AccessAndRefreshToken reissueAccessToken(String refreshToken) { | ||
return reissueAccessAndRefreshTokenService.createNewToken(refreshToken); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/twentythree/peech/auth/controller/SwaggerAuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.twentythree.peech.auth.controller; | ||
|
||
import com.twentythree.peech.user.dto.AccessAndRefreshToken; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
public interface SwaggerAuthController { | ||
@ApiResponse(responseCode = "200", description = "성공", content = {@Content(schema = @Schema(implementation = AccessAndRefreshToken.class), mediaType = "application/json")}) | ||
@ApiResponse(responseCode = "401", description = "실패", content = {@Content(schema = @Schema(implementation = Error.class), mediaType = "application/json")}) | ||
AccessAndRefreshToken reissueAccessToken(@RequestBody String refreshToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Deprecated | ||
public @interface LoginUserId { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.twentythree.peech.auth.dto; | ||
|
||
|
||
@Deprecated | ||
public record UserIdDTO(Long userId) { | ||
} |
3 changes: 1 addition & 2 deletions
3
src/main/java/com/twentythree/peech/auth/interceptor/AuthInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/twentythree/peech/auth/service/ReissueAccessAndRefreshTokenService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.twentythree.peech.auth.service; | ||
|
||
import com.twentythree.peech.common.utils.JWTUtils; | ||
import com.twentythree.peech.common.utils.UserRoleConvertUtils; | ||
import com.twentythree.peech.security.exception.JWTAuthenticationException; | ||
import com.twentythree.peech.security.exception.LoginExceptionCode; | ||
import com.twentythree.peech.security.jwt.JWTAuthenticationToken; | ||
import com.twentythree.peech.user.dto.AccessAndRefreshToken; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReissueAccessAndRefreshTokenService { | ||
|
||
private final JWTUtils jwtUtils; | ||
|
||
public AccessAndRefreshToken createNewToken(String refreshToken) { | ||
|
||
try { | ||
JWTAuthenticationToken authentication = (JWTAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); | ||
|
||
Long userId = authentication.getPrincipal().getUserId(); | ||
GrantedAuthority Authority = authentication.getAuthorities() | ||
.stream().findFirst().orElseThrow(() -> new NoSuchElementException("유저의 권한이 부여되지 않았습니다")); | ||
|
||
String newAccessToken = jwtUtils.createAccessToken(userId, UserRoleConvertUtils | ||
.convertStringToUserRole(Authority.getAuthority())); | ||
String newRefreshToken = jwtUtils.createRefreshToken(userId, UserRoleConvertUtils | ||
.convertStringToUserRole(Authority.getAuthority())); | ||
|
||
return new AccessAndRefreshToken(newAccessToken, newRefreshToken); | ||
}catch (Exception e){ | ||
throw new JWTAuthenticationException(LoginExceptionCode.LOGIN_EXCEPTION_CODE); | ||
} | ||
} | ||
} | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
src/main/java/com/twentythree/peech/auth/service/SecurityContextHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.twentythree.peech.auth.service; | ||
|
||
import com.twentythree.peech.security.jwt.JWTAuthentication; | ||
import org.springframework.security.core.Authentication; | ||
|
||
public class SecurityContextHolder { | ||
|
||
public static Long getUserId() { | ||
Authentication authentication = org.springframework.security.core.context.SecurityContextHolder.getContext().getAuthentication(); | ||
JWTAuthentication jwtAuthentication = (JWTAuthentication) authentication.getPrincipal(); | ||
|
||
return jwtAuthentication.getUserId(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/twentythree/peech/common/JwtProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.twentythree.peech.common; | ||
|
||
import lombok.Getter; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Getter | ||
@Component | ||
public class JwtProperties { | ||
|
||
@Value("${jwt.secret.key}") | ||
private String secretString; | ||
|
||
@Value("${jwt.access.key}") | ||
private String accessString; | ||
|
||
@Value("${jwt.refresh.key}") | ||
private String refreshString; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/twentythree/peech/common/app/AppInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.twentythree.peech.common.app; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class AppInfo { | ||
private String appMinVersion; | ||
private boolean appAvailable; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/twentythree/peech/common/app/AppInfoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.twentythree.peech.common.app; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class AppInfoController { | ||
|
||
@Value("${app.version}") | ||
private String appMinVersion; | ||
|
||
@Value("${app.available}") | ||
private boolean appAvailable; | ||
|
||
@GetMapping("api/v1.1/app") | ||
public ResponseEntity<AppInfo> getAppInfo() { | ||
|
||
return ResponseEntity.status(200).body(new AppInfo(appMinVersion, appAvailable)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/twentythree/peech/common/dto/response/WrappedResponseBody.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.twentythree.peech.common.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class WrappedResponseBody<T> { | ||
|
||
private int statusCode; | ||
private T responseBody; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/twentythree/peech/common/exception/AccessTokenExpiredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.twentythree.peech.common.exception; | ||
|
||
public class AccessTokenExpiredException extends RuntimeException { | ||
public AccessTokenExpiredException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/twentythree/peech/common/exception/RefreshTokenExpiredException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.twentythree.peech.common.exception; | ||
|
||
import io.jsonwebtoken.ExpiredJwtException; | ||
|
||
public class RefreshTokenExpiredException extends RuntimeException{ | ||
public RefreshTokenExpiredException(String message) { | ||
super(message); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/twentythree/peech/common/exception/Unauthorized.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.twentythree.peech.common.exception; | ||
|
||
public class Unauthorized extends RuntimeException{ | ||
public Unauthorized(String message) { super(message); } | ||
} |
Oops, something went wrong.