From e0d57d972eeba6671c18f24aaa833d3d85ec295a Mon Sep 17 00:00:00 2001 From: Yasasr1 Date: Tue, 4 Jul 2023 14:48:16 +0530 Subject: [PATCH 1/3] add forbidden response --- .../java/org/wso2/charon3/core/extensions/RoleManager.java | 4 +++- .../charon3/core/protocol/endpoints/RoleResourceManager.java | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java index a3637ed59..7e1409bac 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java @@ -21,6 +21,7 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.ConflictException; +import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.exceptions.NotImplementedException; import org.wso2.charon3.core.objects.Role; @@ -129,7 +130,8 @@ RolesGetResponse listRolesWithPost(SearchRequest searchRequest) * @throws NotImplementedException Functionality no implemented exception. */ default Role patchRole(String roleId, Map> patchOperations) - throws NotImplementedException, BadRequestException, CharonException, ConflictException, NotFoundException { + throws NotImplementedException, BadRequestException, CharonException, ConflictException, NotFoundException, + ForbiddenException { throw new NotImplementedException("patchRole method is not implemented"); } diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java index ffeb4319b..26d8c3500 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java @@ -32,6 +32,7 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.ConflictException; +import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.InternalErrorException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.exceptions.NotImplementedException; @@ -613,7 +614,7 @@ private SCIMResponse updateWithPatchOperations(String existingRoleId, List Date: Wed, 5 Jul 2023 11:56:32 +0530 Subject: [PATCH 2/3] handle without changing method signature --- .../charon3/core/extensions/RoleManager.java | 4 +--- .../endpoints/AbstractResourceManager.java | 16 ++++++++++++++++ .../protocol/endpoints/RoleResourceManager.java | 3 +-- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java index 7e1409bac..a3637ed59 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java @@ -21,7 +21,6 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.ConflictException; -import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.exceptions.NotImplementedException; import org.wso2.charon3.core.objects.Role; @@ -130,8 +129,7 @@ RolesGetResponse listRolesWithPost(SearchRequest searchRequest) * @throws NotImplementedException Functionality no implemented exception. */ default Role patchRole(String roleId, Map> patchOperations) - throws NotImplementedException, BadRequestException, CharonException, ConflictException, NotFoundException, - ForbiddenException { + throws NotImplementedException, BadRequestException, CharonException, ConflictException, NotFoundException { throw new NotImplementedException("patchRole method is not implemented"); } diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java index 4d701477b..1ca3079fb 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java @@ -21,6 +21,7 @@ import org.wso2.charon3.core.encoder.JSONEncoder; import org.wso2.charon3.core.exceptions.AbstractCharonException; import org.wso2.charon3.core.exceptions.CharonException; +import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.protocol.ResponseCodeConstants; import org.wso2.charon3.core.protocol.SCIMResponse; @@ -101,6 +102,21 @@ public static void setEndpointURLMap(Map endpointURLMap) { */ public static SCIMResponse encodeSCIMException(AbstractCharonException exception) { + if (exception.getDetail().contains(String.format("%d--", ResponseCodeConstants.CODE_FORBIDDEN))) { + ForbiddenException forbiddenException; + if (exception.getDetail().split("--").length > 1) { + forbiddenException = new ForbiddenException(exception.getDetail().split("--")[1]); + } else { + forbiddenException = new ForbiddenException(exception.getDetail()); + } + + logger.debug(forbiddenException.getDetail(), forbiddenException); + Map responseHeaders = new HashMap<>(); + responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON); + return new SCIMResponse(forbiddenException.getStatus(), encoder.encodeSCIMException(forbiddenException), + responseHeaders); + } + if (exception.getStatus() == ResponseCodeConstants.CODE_INTERNAL_ERROR) { logger.error(exception.getDetail(), exception); } else { diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java index 26d8c3500..ffeb4319b 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java @@ -32,7 +32,6 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.ConflictException; -import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.InternalErrorException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.exceptions.NotImplementedException; @@ -614,7 +613,7 @@ private SCIMResponse updateWithPatchOperations(String existingRoleId, List Date: Mon, 10 Jul 2023 10:11:30 +0530 Subject: [PATCH 3/3] Revert "handle without changing method signature" This reverts commit f0a0ea9a980474d4aea59adf043b4d8d19cc62ad. --- .../charon3/core/extensions/RoleManager.java | 4 +++- .../endpoints/AbstractResourceManager.java | 16 ---------------- .../protocol/endpoints/RoleResourceManager.java | 3 ++- 3 files changed, 5 insertions(+), 18 deletions(-) diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java index a3637ed59..7e1409bac 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/extensions/RoleManager.java @@ -21,6 +21,7 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.ConflictException; +import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.exceptions.NotImplementedException; import org.wso2.charon3.core.objects.Role; @@ -129,7 +130,8 @@ RolesGetResponse listRolesWithPost(SearchRequest searchRequest) * @throws NotImplementedException Functionality no implemented exception. */ default Role patchRole(String roleId, Map> patchOperations) - throws NotImplementedException, BadRequestException, CharonException, ConflictException, NotFoundException { + throws NotImplementedException, BadRequestException, CharonException, ConflictException, NotFoundException, + ForbiddenException { throw new NotImplementedException("patchRole method is not implemented"); } diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java index 1ca3079fb..4d701477b 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/AbstractResourceManager.java @@ -21,7 +21,6 @@ import org.wso2.charon3.core.encoder.JSONEncoder; import org.wso2.charon3.core.exceptions.AbstractCharonException; import org.wso2.charon3.core.exceptions.CharonException; -import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.protocol.ResponseCodeConstants; import org.wso2.charon3.core.protocol.SCIMResponse; @@ -102,21 +101,6 @@ public static void setEndpointURLMap(Map endpointURLMap) { */ public static SCIMResponse encodeSCIMException(AbstractCharonException exception) { - if (exception.getDetail().contains(String.format("%d--", ResponseCodeConstants.CODE_FORBIDDEN))) { - ForbiddenException forbiddenException; - if (exception.getDetail().split("--").length > 1) { - forbiddenException = new ForbiddenException(exception.getDetail().split("--")[1]); - } else { - forbiddenException = new ForbiddenException(exception.getDetail()); - } - - logger.debug(forbiddenException.getDetail(), forbiddenException); - Map responseHeaders = new HashMap<>(); - responseHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON); - return new SCIMResponse(forbiddenException.getStatus(), encoder.encodeSCIMException(forbiddenException), - responseHeaders); - } - if (exception.getStatus() == ResponseCodeConstants.CODE_INTERNAL_ERROR) { logger.error(exception.getDetail(), exception); } else { diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java index ffeb4319b..26d8c3500 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/RoleResourceManager.java @@ -32,6 +32,7 @@ import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; import org.wso2.charon3.core.exceptions.ConflictException; +import org.wso2.charon3.core.exceptions.ForbiddenException; import org.wso2.charon3.core.exceptions.InternalErrorException; import org.wso2.charon3.core.exceptions.NotFoundException; import org.wso2.charon3.core.exceptions.NotImplementedException; @@ -613,7 +614,7 @@ private SCIMResponse updateWithPatchOperations(String existingRoleId, List