-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'new-module-authorization-code'
- Loading branch information
Showing
97 changed files
with
6,068 additions
and
4,298 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
44 changes: 22 additions & 22 deletions
44
...ernknife/securityhelper/oauth2/client/SpringSecurityOauth2PasswordJpaImplApplication.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 |
---|---|---|
@@ -1,22 +1,22 @@ | ||
package com.patternknife.securityhelper.oauth2.client; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.TimeZone; | ||
|
||
|
||
@SpringBootApplication(scanBasePackages = {"com.patternknife.securityhelper.oauth2.client", "io.github.patternknife.securityhelper.oauth2.api"}) | ||
public class SpringSecurityOauth2PasswordJpaImplApplication { | ||
|
||
@PostConstruct | ||
void init() { | ||
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringSecurityOauth2PasswordJpaImplApplication.class, args); | ||
} | ||
|
||
} | ||
package com.patternknife.securityhelper.oauth2.client; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.util.TimeZone; | ||
|
||
|
||
@SpringBootApplication(scanBasePackages = {"com.patternknife.securityhelper.oauth2.client", "io.github.patternknife.securityhelper.oauth2.api"}) | ||
public class SpringSecurityOauth2PasswordJpaImplApplication { | ||
|
||
@PostConstruct | ||
void init() { | ||
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Seoul")); | ||
} | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(SpringSecurityOauth2PasswordJpaImplApplication.class, args); | ||
} | ||
|
||
} |
47 changes: 0 additions & 47 deletions
47
...ava/com/patternknife/securityhelper/oauth2/client/config/logger/common/LoggingFilter.java
This file was deleted.
Oops, something went wrong.
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
138 changes: 69 additions & 69 deletions
138
...tternknife/securityhelper/oauth2/client/config/response/error/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
package com.patternknife.securityhelper.oauth2.client.config.response.error; | ||
|
||
|
||
import com.patternknife.securityhelper.oauth2.client.config.response.error.message.GeneralErrorMessage; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.util.ExceptionKnifeUtils; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.dto.SecurityKnifeErrorResponsePayload; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.exception.KnifeOauth2AuthenticationException; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.DefaultSecurityUserExceptionMessage; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.ISecurityUserExceptionMessageService; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.util.OrderConstants; | ||
import lombok.RequiredArgsConstructor;; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import org.springframework.web.context.request.WebRequest; | ||
|
||
|
||
/* | ||
* | ||
* Customize the exception payload by implementing this, which replaces | ||
* 'io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.handler.SecurityKnifeExceptionHandler' | ||
* | ||
* Once you create 'GlobalExceptionHandler', you should insert the following two (authenticationException, authorizationException) as default. Otherwise, 'unhandledExceptionHandler' is prior to 'io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.handler.SecurityKnifeExceptionHandler'. | ||
* "OrderConstants.SECURITY_KNIFE_EXCEPTION_HANDLER_ORDER - 1" means this is prior to "SecurityKnifeExceptionHandler" | ||
* */ | ||
@Order(OrderConstants.SECURITY_KNIFE_EXCEPTION_HANDLER_ORDER - 1) | ||
@ControllerAdvice | ||
@RequiredArgsConstructor | ||
public class GlobalExceptionHandler { | ||
|
||
private final ISecurityUserExceptionMessageService iSecurityUserExceptionMessageService; | ||
|
||
// 401 : Authentication | ||
@ExceptionHandler({AuthenticationException.class}) | ||
public ResponseEntity<?> authenticationException(Exception ex, WebRequest request) { | ||
SecurityKnifeErrorResponsePayload errorResponsePayload; | ||
if(ex instanceof KnifeOauth2AuthenticationException && ((KnifeOauth2AuthenticationException) ex).getErrorMessages() != null) { | ||
errorResponsePayload = new SecurityKnifeErrorResponsePayload(((KnifeOauth2AuthenticationException) ex).getErrorMessages(), | ||
ex, request.getDescription(false), ExceptionKnifeUtils.getAllStackTraces(ex), | ||
ExceptionKnifeUtils.getAllCauses(ex), null); | ||
}else { | ||
errorResponsePayload = new SecurityKnifeErrorResponsePayload(ExceptionKnifeUtils.getAllCauses(ex), request.getDescription(false), iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHENTICATION_LOGIN_FAILURE), | ||
ex.getMessage(), ex.getStackTrace()[0].toString()); | ||
} | ||
return new ResponseEntity<>(errorResponsePayload, HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
// 403 : Authorization | ||
@ExceptionHandler({ AccessDeniedException.class }) | ||
public ResponseEntity<?> authorizationException(Exception ex, WebRequest request) { | ||
SecurityKnifeErrorResponsePayload errorResponsePayload = new SecurityKnifeErrorResponsePayload(ex.getMessage() != null ? ex.getMessage() : ExceptionKnifeUtils.getAllCauses(ex), request.getDescription(false), | ||
ex.getMessage() == null || ex.getMessage().equals("Access Denied") ? iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHORIZATION_FAILURE) : ex.getMessage(), ex.getStackTrace()[0].toString()); | ||
return new ResponseEntity<>(errorResponsePayload, HttpStatus.FORBIDDEN); | ||
} | ||
|
||
// Unhandled | ||
@ExceptionHandler(Exception.class) | ||
public ResponseEntity<?> unhandledExceptionHandler(Exception ex, WebRequest request) { | ||
SecurityKnifeErrorResponsePayload errorResponsePayload = new SecurityKnifeErrorResponsePayload(ex.getMessage(), request.getDescription(false), GeneralErrorMessage.UNHANDLED_ERROR.getUserMessage(), | ||
CustomExceptionUtils.getAllStackTraces(ex), CustomExceptionUtils.getAllCauses(ex)); | ||
return new ResponseEntity<>(errorResponsePayload, HttpStatus.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
} | ||
package com.patternknife.securityhelper.oauth2.client.config.response.error; | ||
|
||
|
||
import com.patternknife.securityhelper.oauth2.client.config.response.error.message.GeneralErrorMessage; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.util.ExceptionKnifeUtils; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.dto.SecurityKnifeErrorResponsePayload; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.exception.KnifeOauth2AuthenticationException; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.DefaultSecurityUserExceptionMessage; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.ISecurityUserExceptionMessageService; | ||
import io.github.patternknife.securityhelper.oauth2.api.config.util.OrderConstants; | ||
import lombok.RequiredArgsConstructor;; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.AccessDeniedException; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import org.springframework.web.context.request.WebRequest; | ||
|
||
|
||
/* | ||
* | ||
* Customize the exception payload by implementing this, which replaces | ||
* 'io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.handler.SecurityKnifeExceptionHandler' | ||
* | ||
* Once you create 'GlobalExceptionHandler', you should insert the following two (authenticationException, authorizationException) as default. Otherwise, 'unhandledExceptionHandler' is prior to 'io.github.patternknife.securityhelper.oauth2.api.config.security.response.error.handler.SecurityKnifeExceptionHandler'. | ||
* "OrderConstants.SECURITY_KNIFE_EXCEPTION_HANDLER_ORDER - 1" means this is prior to "SecurityKnifeExceptionHandler" | ||
* */ | ||
@Order(OrderConstants.SECURITY_KNIFE_EXCEPTION_HANDLER_ORDER - 1) | ||
@ControllerAdvice | ||
@RequiredArgsConstructor | ||
public class GlobalExceptionHandler { | ||
|
||
private final ISecurityUserExceptionMessageService iSecurityUserExceptionMessageService; | ||
|
||
// 401 : Authentication | ||
@ExceptionHandler({AuthenticationException.class}) | ||
public ResponseEntity<?> authenticationException(Exception ex, WebRequest request) { | ||
SecurityKnifeErrorResponsePayload errorResponsePayload; | ||
if(ex instanceof KnifeOauth2AuthenticationException && ((KnifeOauth2AuthenticationException) ex).getErrorMessages() != null) { | ||
errorResponsePayload = new SecurityKnifeErrorResponsePayload(((KnifeOauth2AuthenticationException) ex).getErrorMessages(), | ||
ex, request.getDescription(false), ExceptionKnifeUtils.getAllStackTraces(ex), | ||
ExceptionKnifeUtils.getAllCauses(ex), null); | ||
}else { | ||
errorResponsePayload = new SecurityKnifeErrorResponsePayload(ExceptionKnifeUtils.getAllCauses(ex), request.getDescription(false), iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHENTICATION_LOGIN_FAILURE), | ||
ex.getMessage(), ex.getStackTrace()[0].toString()); | ||
} | ||
return new ResponseEntity<>(errorResponsePayload, HttpStatus.UNAUTHORIZED); | ||
} | ||
|
||
// 403 : Authorization | ||
@ExceptionHandler({ AccessDeniedException.class }) | ||
public ResponseEntity<?> authorizationException(Exception ex, WebRequest request) { | ||
SecurityKnifeErrorResponsePayload errorResponsePayload = new SecurityKnifeErrorResponsePayload(ex.getMessage() != null ? ex.getMessage() : ExceptionKnifeUtils.getAllCauses(ex), request.getDescription(false), | ||
ex.getMessage() == null || ex.getMessage().equals("Access Denied") ? iSecurityUserExceptionMessageService.getUserMessage(DefaultSecurityUserExceptionMessage.AUTHORIZATION_FAILURE) : ex.getMessage(), ex.getStackTrace()[0].toString()); | ||
return new ResponseEntity<>(errorResponsePayload, HttpStatus.FORBIDDEN); | ||
} | ||
|
||
// Unhandled | ||
/* @ExceptionHandler(Exception.class) | ||
public ResponseEntity<?> unhandledExceptionHandler(Exception ex, WebRequest request) { | ||
SecurityKnifeErrorResponsePayload errorResponsePayload = new SecurityKnifeErrorResponsePayload(ex.getMessage(), request.getDescription(false), GeneralErrorMessage.UNHANDLED_ERROR.getUserMessage(), | ||
CustomExceptionUtils.getAllStackTraces(ex), CustomExceptionUtils.getAllCauses(ex)); | ||
return new ResponseEntity<>(errorResponsePayload, HttpStatus.INTERNAL_SERVER_ERROR); | ||
}*/ | ||
|
||
} |
75 changes: 39 additions & 36 deletions
75
...yhelper/oauth2/client/config/securityimpl/message/CustomSecurityUserExceptionMessage.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 |
---|---|---|
@@ -1,36 +1,39 @@ | ||
package com.patternknife.securityhelper.oauth2.client.config.securityimpl.message; | ||
|
||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.ExceptionMessageInterface; | ||
|
||
public enum CustomSecurityUserExceptionMessage implements ExceptionMessageInterface { | ||
|
||
AUTHENTICATION_LOGIN_FAILURE("1Authentication information is not valid. Please check and try again."), | ||
AUTHENTICATION_LOGIN_ERROR("1An error occurred during authentication. If the problem persists, please contact customer service."), | ||
AUTHENTICATION_TOKEN_FAILURE("1The authentication token has expired. Please log in again."), | ||
AUTHENTICATION_TOKEN_ERROR("1There was a problem verifying the authentication token. Please log in again."), | ||
AUTHORIZATION_FAILURE("1You do not have access permissions. Please request this from the administrator."), | ||
AUTHORIZATION_ERROR("1An error occurred with access permissions. If the problem persists, please contact customer service."), | ||
|
||
// ID PASSWORD | ||
AUTHENTICATION_ID_NO_EXISTS("1The specified ID does not exist."), | ||
AUTHENTICATION_WRONG_ID_PASSWORD("1User information could not be verified. Please check your ID or password. If the problem persists, please contact customer service."), | ||
AUTHENTICATION_PASSWORD_FAILED_EXCEEDED("1The number of password attempts has been exceeded."), | ||
|
||
// CLIENT ID, SECRET | ||
AUTHENTICATION_WRONG_CLIENT_ID_SECRET("1Client information is not verified."), | ||
|
||
// GRANT TYPE | ||
AUTHENTICATION_WRONG_GRANT_TYPE("1Wrong Grant Type detected."); | ||
|
||
private String message; | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
CustomSecurityUserExceptionMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
} | ||
package com.patternknife.securityhelper.oauth2.client.config.securityimpl.message; | ||
|
||
import io.github.patternknife.securityhelper.oauth2.api.config.security.message.ExceptionMessageInterface; | ||
|
||
public enum CustomSecurityUserExceptionMessage implements ExceptionMessageInterface { | ||
|
||
AUTHENTICATION_LOGIN_FAILURE("1Authentication information is not valid. Please check and try again."), | ||
AUTHENTICATION_LOGIN_ERROR("1An error occurred during authentication. If the problem persists, please contact customer service."), | ||
AUTHENTICATION_TOKEN_FAILURE("1The authentication token has expired. Please log in again."), | ||
AUTHENTICATION_TOKEN_ERROR("1There was a problem verifying the authentication token. Please log in again."), | ||
AUTHORIZATION_FAILURE("1You do not have access permissions. Please request this from the administrator."), | ||
AUTHORIZATION_ERROR("1An error occurred with access permissions. If the problem persists, please contact customer service."), | ||
|
||
// ID PASSWORD | ||
AUTHENTICATION_ID_NO_EXISTS("1The specified ID does not exist."), | ||
AUTHENTICATION_WRONG_ID_PASSWORD("1User information could not be verified. Please check your ID or password. If the problem persists, please contact customer service."), | ||
AUTHENTICATION_PASSWORD_FAILED_EXCEEDED("1The number of password attempts has been exceeded."), | ||
|
||
// Wrong Authorization Code | ||
AUTHORIZATION_CODE_NO_EXISTS("1The specified Authorization code does not exist."), | ||
|
||
// CLIENT ID, SECRET | ||
AUTHENTICATION_WRONG_CLIENT_ID_SECRET("1Client information is not verified."), | ||
|
||
// GRANT TYPE | ||
AUTHENTICATION_WRONG_GRANT_TYPE("1Wrong Grant Type detected."); | ||
|
||
private String message; | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
CustomSecurityUserExceptionMessage(String message) { | ||
this.message = message; | ||
} | ||
|
||
} |
Oops, something went wrong.