This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
회원가입 및 로그인 기능 추가 #3
Open
Daniel-Taeyoun
wants to merge
4
commits into
develop
Choose a base branch
from
feature1
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
|
||
import java.time.LocalDateTime; | ||
import me.naming.onlineshoppingmall.domain.ResponseData; | ||
import org.springframework.http.HttpHeaders; | ||
import me.naming.onlineshoppingmall.exception.MessageException; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
@@ -17,18 +16,22 @@ | |
@ControllerAdvice | ||
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler { | ||
|
||
@ExceptionHandler(value = { RuntimeException.class }) | ||
protected ResponseEntity handleConflict(RuntimeException ex, WebRequest request) { | ||
HttpHeaders httpHeaders = new HttpHeaders(); | ||
|
||
httpHeaders.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_VALUE)); | ||
@ExceptionHandler(value = { MessageException.class }) | ||
protected ResponseEntity handleConflict(MessageException messageException, WebRequest request) { | ||
String path = ((ServletWebRequest)request).getRequest().getRequestURI(); | ||
int code; | ||
|
||
if(messageException.getStatusCode() != 0) { | ||
code = messageException.getStatusCode(); | ||
} else { | ||
code = HttpStatus.INTERNAL_SERVER_ERROR.value(); | ||
} | ||
|
||
ResponseData responseData = ResponseData.builder() | ||
.localDateTime(LocalDateTime.now()) | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.statusCode(code) | ||
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. 이렇게하면 status code가 body에 들어가지 않을까요? |
||
.path(path) | ||
.message(ex.getMessage()) | ||
.message(messageException.getMessage()) | ||
.build(); | ||
|
||
return new ResponseEntity<>(responseData, HttpStatus.INTERNAL_SERVER_ERROR); | ||
|
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
public class CommonConstant { | ||
private CommonConstant() {}; | ||
|
||
public static final String LOGIN_INFO = "loginInfo"; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/me/naming/onlineshoppingmall/exception/MessageException.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,23 @@ | ||
package me.naming.onlineshoppingmall.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class MessageException extends RuntimeException{ | ||
|
||
private int statusCode; | ||
|
||
public MessageException(String message) { | ||
super(message); | ||
this.statusCode = HttpStatus.INTERNAL_SERVER_ERROR.value(); | ||
} | ||
|
||
public MessageException(String message, int statusCode) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
} | ||
|
||
public int getStatusCode() { | ||
return statusCode; | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -2,13 +2,8 @@ | |
|
||
import java.io.UnsupportedEncodingException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.InvalidAlgorithmParameterException; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import javax.crypto.BadPaddingException; | ||
import java.security.GeneralSecurityException; | ||
import javax.crypto.Cipher; | ||
import javax.crypto.IllegalBlockSizeException; | ||
import javax.crypto.NoSuchPaddingException; | ||
import javax.crypto.spec.IvParameterSpec; | ||
import javax.crypto.spec.SecretKeySpec; | ||
import org.apache.commons.codec.binary.Base64; | ||
|
@@ -38,20 +33,10 @@ public String encrypt(String plainText) { | |
cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(aesKey.substring(0, 16).getBytes())); | ||
encrypted = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8.name())); | ||
|
||
} catch (IllegalBlockSizeException e) { | ||
logger.error("** IllegalBlockSizeException : {}", e); | ||
} catch (BadPaddingException e) { | ||
logger.error("** BadPaddingException : {}", e); | ||
} catch (GeneralSecurityException e) { | ||
logger.error("** GeneralSecurityException : {}", e); | ||
} catch (UnsupportedEncodingException e) { | ||
logger.error("** UnsupportedEncodingException : {}", e); | ||
} catch (InvalidKeyException e) { | ||
logger.error("** InvalidKeyException : {}", e); | ||
} catch (InvalidAlgorithmParameterException e) { | ||
logger.error("** InvalidAlgorithmParameterException : {}", e); | ||
} catch (NoSuchAlgorithmException e) { | ||
logger.error("** NoSuchAlgorithmException : {}", e); | ||
} catch (NoSuchPaddingException e) { | ||
logger.error("** NoSuchPaddingException : {}", e); | ||
} | ||
return new String(Base64.encodeBase64(encrypted)); | ||
} | ||
|
@@ -68,20 +53,8 @@ public String decrypt(String encryptText) { | |
byte[] byteStr = Base64.decodeBase64(encryptText.getBytes()); | ||
aesDecode = new String(cipher.doFinal(byteStr), StandardCharsets.UTF_8.name()); | ||
|
||
} catch (UnsupportedEncodingException e) { | ||
} catch (Exception e) { | ||
logger.error("** Decode UnsupportedEncodingException : {}", 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. 그냥 아래의 내용들과 메세지만 약간씩 다른것같은데 한번에 처리할 수 있지 않을까요? 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.
피드백 해주신 내용은 현재 |
||
} catch (IllegalBlockSizeException e) { | ||
logger.error("** Decode IllegalBlockSizeException : {}", e); | ||
} catch (BadPaddingException e) { | ||
logger.error("** Decode BadPaddingException : {}", e); | ||
} catch (InvalidKeyException e) { | ||
logger.error("** Decode InvalidKeyException : {}", e); | ||
} catch (InvalidAlgorithmParameterException e) { | ||
logger.error("** Decode InvalidAlgorithmParameterException : {}", e); | ||
} catch (NoSuchAlgorithmException e) { | ||
logger.error("** Decode NoSuchAlgorithmException : {}", e); | ||
} catch (NoSuchPaddingException e) { | ||
logger.error("** Decode NoSuchPaddingException : {}", e); | ||
} | ||
|
||
if(StringUtils.isEmpty(aesDecode)) throw new RuntimeException("복호화 에러"); | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Intellij
지원이면 intellij가 아닌 환경에서는 에러가 나지 않나요??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.
해당 내용은 개인적으로 블로그 글을 잘못 이해했습니다. 스프링 내부(
org.springframework.boot:spring-boot-starter-test
)에서 jupiter를 제공해주고 있으며, 따라서 추가했던 jupiter는 삭제했습니다.