-
Notifications
You must be signed in to change notification settings - Fork 0
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 #42 from Orange-Co/main
deploy
- Loading branch information
Showing
34 changed files
with
495 additions
and
53 deletions.
There are no files selected for viewing
Submodule DDANZI_Server_yml
updated
from 08df09 to 891261
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
22 changes: 22 additions & 0 deletions
22
src/main/java/co/orange/ddanzi/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,22 @@ | ||
package co.orange.ddanzi.controller; | ||
|
||
import co.orange.ddanzi.dto.auth.LoginDto; | ||
import co.orange.ddanzi.global.common.response.ApiResponse; | ||
import co.orange.ddanzi.service.AuthService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/auth") | ||
public class AuthController { | ||
private final AuthService authService; | ||
|
||
@PostMapping("/signin/test") | ||
ApiResponse<?> signin(@RequestBody LoginDto requestDto){ | ||
return authService.testSignin(requestDto.getIdToken()); | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/co/orange/ddanzi/dto/auth/AuthResponseDto.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 co.orange.ddanzi.dto.auth; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@Getter | ||
public class AuthResponseDto { | ||
private String accesstoken; | ||
private String nickname; | ||
} |
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 co.orange.ddanzi.dto.auth; | ||
|
||
import co.orange.ddanzi.domain.user.enums.LoginType; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class LoginDto { | ||
private String idToken; | ||
private LoginType type; | ||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/co/orange/ddanzi/dto/setting/EnterAddressResponseDto.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 co.orange.ddanzi.dto.setting; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class EnterAddressResponseDto { | ||
private String name; | ||
private String phone; | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...lobal/common/exception/ErrorResponse.java → ...zi/global/common/error/ErrorResponse.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
18 changes: 18 additions & 0 deletions
18
src/main/java/co/orange/ddanzi/global/common/exception/ApiException.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 co.orange.ddanzi.global.common.exception; | ||
|
||
import co.orange.ddanzi.global.common.error.Error; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ApiException extends RuntimeException { | ||
private final Error error; | ||
|
||
public ApiException(Error error){ | ||
super(error.getMessage()); | ||
this.error = error; | ||
} | ||
|
||
public int getHttpStatus(){ | ||
return error.getHttpStatusCode(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/co/orange/ddanzi/global/common/exception/UnauthorizedException.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 co.orange.ddanzi.global.common.exception; | ||
|
||
import co.orange.ddanzi.global.common.error.Error; | ||
|
||
public class UnauthorizedException extends ApiException{ | ||
public UnauthorizedException(Error error) { | ||
super(error); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/co/orange/ddanzi/global/common/exception/UserNotFoundException.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 co.orange.ddanzi.global.common.exception; | ||
|
||
import co.orange.ddanzi.global.common.error.Error; | ||
|
||
public class UserNotFoundException extends ApiException{ | ||
public UserNotFoundException() { | ||
super(Error.USER_NOT_FOUND); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/co/orange/ddanzi/global/common/response/ApiResponse.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
4 changes: 2 additions & 2 deletions
4
src/main/java/co/orange/ddanzi/global/config/handler/GlobalExceptionHandler.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
52 changes: 52 additions & 0 deletions
52
src/main/java/co/orange/ddanzi/global/config/jwt/AuthUtils.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,52 @@ | ||
package co.orange.ddanzi.global.config.jwt; | ||
|
||
import co.orange.ddanzi.domain.user.User; | ||
import co.orange.ddanzi.global.common.exception.UserNotFoundException; | ||
import co.orange.ddanzi.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class AuthUtils { | ||
private final UserRepository userRepository; | ||
|
||
public User getUser() { | ||
String currentUserNickname = getCurrentUserNickname(); | ||
if (currentUserNickname == null) { | ||
return null; | ||
} | ||
return userRepository.findByLoginId(currentUserNickname) | ||
.orElseThrow(() -> new UserNotFoundException()); | ||
|
||
} | ||
|
||
public Authentication getAuthentication() { | ||
// SecurityContext에서 인증 정보 가져오기 | ||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); | ||
return authentication; | ||
} | ||
|
||
public Object getPrincipal() { | ||
// 현재 사용자의 principal 가져오기 | ||
return getAuthentication().getPrincipal(); | ||
|
||
} | ||
|
||
public String getCurrentUserNickname() { | ||
Object principalObject = getPrincipal(); | ||
|
||
if (principalObject instanceof UserDetails) { | ||
UserDetails userDetails = (UserDetails) principalObject; | ||
log.info("id token -> {}", userDetails.getUsername()); | ||
return userDetails.getUsername(); | ||
} | ||
return null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/co/orange/ddanzi/global/config/jwt/JwtFilter.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,46 @@ | ||
package co.orange.ddanzi.global.config.jwt; | ||
|
||
import jakarta.servlet.FilterChain; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Component | ||
public class JwtFilter extends OncePerRequestFilter { | ||
private final JwtUtils jwtUtils; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
|
||
String token = jwtUtils.resolveJWT(request); | ||
log.info("Request to {}: token={}", request.getRequestURI(), token); | ||
|
||
if (token != null && jwtUtils.validateToken(token)) { | ||
Authentication authentication = jwtUtils.getAuthentication(token); | ||
SecurityContextHolder.getContext().setAuthentication(authentication); | ||
} | ||
else { | ||
log.info("No valid token found, proceeding without authentication"); | ||
} | ||
|
||
filterChain.doFilter(request, response); | ||
} | ||
|
||
@Override | ||
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException { | ||
String path = request.getRequestURI(); | ||
return path.startsWith("/api/v1/auth") | ||
|| path.equals("/api/v1/search") | ||
; | ||
} | ||
} |
Oops, something went wrong.