-
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.
- Loading branch information
1 parent
ac76f29
commit 32be120
Showing
32 changed files
with
196 additions
and
104 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
20 changes: 20 additions & 0 deletions
20
...n/app-api/src/main/java/core/startup/mealtoktok/api/global/exception/GlobalErrorCode.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 core.startup.mealtoktok.api.global.exception; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import core.startup.mealtoktok.common.exception.BaseErrorCode; | ||
import core.startup.mealtoktok.common.exception.ErrorReason; | ||
|
||
@RequiredArgsConstructor | ||
public enum GlobalErrorCode implements BaseErrorCode { | ||
PERMISSION_DENIED(403, "PERMISSION_DENIED", "해당 API 권한이 없습니다"); | ||
|
||
private final Integer status; | ||
private final String errorCode; | ||
private final String message; | ||
|
||
@Override | ||
public ErrorReason getErrorReason() { | ||
return ErrorReason.of(status, errorCode, message); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...api/src/main/java/core/startup/mealtoktok/api/global/exception/NoPermissionException.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,12 @@ | ||
package core.startup.mealtoktok.api.global.exception; | ||
|
||
import core.startup.mealtoktok.common.exception.WebException; | ||
|
||
public class NoPermissionException extends WebException { | ||
|
||
public static final NoPermissionException EXCEPTION = new NoPermissionException(); | ||
|
||
private NoPermissionException() { | ||
super(GlobalErrorCode.PERMISSION_DENIED); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../src/main/java/core/startup/mealtoktok/api/global/security/CustomAccessDeniedHandler.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,34 @@ | ||
package core.startup.mealtoktok.api.global.security; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.web.access.AccessDeniedHandler; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerExceptionResolver; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import core.startup.mealtoktok.api.global.exception.NoPermissionException; | ||
|
||
@Component | ||
@Slf4j | ||
public class CustomAccessDeniedHandler implements AccessDeniedHandler { | ||
|
||
private final HandlerExceptionResolver resolver; | ||
|
||
public CustomAccessDeniedHandler( | ||
@Qualifier("handlerExceptionResolver") HandlerExceptionResolver resolver) { | ||
this.resolver = resolver; | ||
} | ||
|
||
@Override | ||
public void handle( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
AccessDeniedException accessDeniedException) { | ||
resolver.resolveException(request, response, null, NoPermissionException.EXCEPTION); | ||
} | ||
} |
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
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
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.