-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/JNU-econovation/econo-error …
…into FE
- Loading branch information
Showing
78 changed files
with
1,995 additions
and
11 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
56 changes: 56 additions & 0 deletions
56
BE/error/src/main/java/com/example/demo/auth/application/config/LoginConfig.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,56 @@ | ||
package com.example.demo.auth.application.config; | ||
|
||
|
||
import com.example.demo.auth.application.model.token.TokenResolver; | ||
import com.example.demo.auth.application.support.CookieTokenExtractor; | ||
import com.example.demo.auth.application.support.HeaderTokenExtractor; | ||
import com.example.demo.auth.application.support.MemberArgumentResolver; | ||
import com.example.demo.auth.presentation.interceptor.AuthInterceptor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class LoginConfig implements WebMvcConfigurer { | ||
private final MemberArgumentResolver memberArgumentResolver; | ||
private final TokenResolver tokenResolver; | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry | ||
.addInterceptor(memberAuthInterceptor()) | ||
.addPathPatterns("/api/**") | ||
.excludePathPatterns("/api/guest/**", "/api/auth/**", "/api/health-check","/api/programs/**"); | ||
registry | ||
.addInterceptor(reissueAuthInterceptor()) | ||
.addPathPatterns("/auth/reissue") | ||
.excludePathPatterns("/api/guest/**", "/api/auth/**", "/api/health-check"); | ||
} | ||
|
||
@Override | ||
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) { | ||
resolvers.add(memberArgumentResolver); | ||
} | ||
|
||
@Bean | ||
public AuthInterceptor memberAuthInterceptor() { | ||
return AuthInterceptor.builder() | ||
.tokenExtractor(new HeaderTokenExtractor()) | ||
.tokenResolver(tokenResolver) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public AuthInterceptor reissueAuthInterceptor() { | ||
return AuthInterceptor.builder() | ||
.tokenExtractor(new CookieTokenExtractor()) | ||
.tokenResolver(tokenResolver) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
BE/error/src/main/java/com/example/demo/auth/application/dto/TokenResponse.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.example.demo.auth.application.dto; | ||
|
||
import com.example.demo.common.support.dto.AbstractDto; | ||
import com.example.demo.common.support.dto.AbstractResponseDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder(toBuilder = true) | ||
public class TokenResponse implements AbstractResponseDto { | ||
private String accessToken; | ||
private Long accessExpiredTime; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
BE/error/src/main/java/com/example/demo/auth/application/event/DeletedMemberEvent.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,25 @@ | ||
package com.example.demo.auth.application.event; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class DeletedMemberEvent { | ||
private final Long memberId; | ||
private final String token; | ||
|
||
private DeletedMemberEvent(Long memberId, String token) { | ||
this.memberId = memberId; | ||
this.token = token; | ||
} | ||
|
||
/** | ||
* 멤버 탈퇴 이벤트를 발행한다. | ||
* | ||
* @param memberId 회원 탈퇴를 원하는 멤버 id | ||
* @param token 회원 탈퇴 시 사용한 토큰 | ||
* @return | ||
*/ | ||
public static DeletedMemberEvent of(Long memberId, String token) { | ||
return new DeletedMemberEvent(memberId, token); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ror/src/main/java/com/example/demo/auth/application/exception/AuthorizationException.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,10 @@ | ||
package com.example.demo.auth.application.exception; | ||
|
||
import com.example.demo.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class AuthorizationException extends BusinessException { | ||
public AuthorizationException(String code, HttpStatus httpStatus) { | ||
super(code, httpStatus); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/example/demo/auth/application/exception/InvalidNameFormatException.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,20 @@ | ||
package com.example.demo.auth.application.exception; | ||
|
||
import com.example.demo.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** 멤버의 이름 형식이 올바르지 않을 떄 발생하는 예외 */ | ||
public class InvalidNameFormatException extends BusinessException { | ||
private static final String FAIL_CODE = "4006"; | ||
private final String name; | ||
|
||
public InvalidNameFormatException(String name) { | ||
super(FAIL_CODE, HttpStatus.BAD_REQUEST); | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("%s 멤버의 이름이 형식과 일치하지 않습니다.", name); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rror/src/main/java/com/example/demo/auth/application/exception/InvalidTokenException.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.example.demo.auth.application.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
/** 토큰이 유효하지 않을 때 발생하는 예외 */ | ||
public class InvalidTokenException extends AuthorizationException { | ||
private static final String FAIL_CODE = "4003"; | ||
|
||
public InvalidTokenException() { | ||
super(FAIL_CODE, HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return "유효하지 않은 토큰입니다."; | ||
} | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
...or/src/main/java/com/example/demo/auth/application/exception/NotFoundCookieException.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.example.demo.auth.application.exception; | ||
|
||
import com.example.demo.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** 토큰이 쿠키에 존재하지 않을 때 발생하는 예외 */ | ||
public class NotFoundCookieException extends BusinessException { | ||
private static final String FAIL_CODE = "4004"; | ||
|
||
public NotFoundCookieException() { | ||
super(FAIL_CODE, HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return "리프레시 토큰이 존재하지 않습니다."; | ||
} | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
...c/main/java/com/example/demo/auth/application/exception/NotFoundHeaderTokenException.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.example.demo.auth.application.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
/** 토큰이 헤더에 존재하지 않을 때 발생하는 예외 */ | ||
public class NotFoundHeaderTokenException extends AuthorizationException { | ||
private static final String FAIL_CODE = "4000"; | ||
|
||
public NotFoundHeaderTokenException() { | ||
super(FAIL_CODE, HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return "엑세스 토큰이 존재하지 않습니다."; | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
...c/main/java/com/example/demo/auth/application/exception/NotFoundOauthServerException.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,20 @@ | ||
package com.example.demo.auth.application.exception; | ||
|
||
import com.example.demo.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** 존재하지 않는 oauth 서버일 때 발생하는 예외 */ | ||
public class NotFoundOauthServerException extends BusinessException { | ||
private static final String FAIL_CODE = "5000"; | ||
private final String oauthServer; | ||
|
||
public NotFoundOauthServerException(String oauthServer) { | ||
super(FAIL_CODE, HttpStatus.NOT_FOUND); | ||
this.oauthServer = oauthServer; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("%s 는 존재하지 oauth 서버입니다.", oauthServer); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rror/src/main/java/com/example/demo/auth/application/exception/TokenExpiredException.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.example.demo.auth.application.exception; | ||
|
||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public class TokenExpiredException extends AuthorizationException { | ||
|
||
private static final String FAIL_CODE = "4001"; | ||
|
||
public TokenExpiredException() { | ||
super(FAIL_CODE, HttpStatus.FORBIDDEN); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return "액세스 토큰이 만료되었습니다."; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...rror/src/main/java/com/example/demo/auth/application/exception/TokenParsingException.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,20 @@ | ||
package com.example.demo.auth.application.exception; | ||
|
||
import com.example.demo.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** JWT 파싱 중 발생한 예외 */ | ||
public class TokenParsingException extends BusinessException { | ||
private static final String FAIL_CODE = "4007"; | ||
private String message; | ||
|
||
public TokenParsingException(Exception e) { | ||
super(FAIL_CODE, HttpStatus.BAD_REQUEST); | ||
message = e.getMessage(); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("JWT 파싱 중 오류 발생: {}", message); | ||
} | ||
} |
Oops, something went wrong.