From e274e206188e76654de759bc687a56a80cf4bfbc Mon Sep 17 00:00:00 2001 From: Puja Sharma Date: Wed, 20 Apr 2022 20:21:26 +0530 Subject: [PATCH] feat(jans-config-api): added patch endpoint for custom script --- .../auth/CacheConfigurationResource.java | 19 +++++++------------ .../resource/auth/CustomScriptResource.java | 9 +++++++-- .../configapi/core/rest/BaseResource.java | 5 +++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CacheConfigurationResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CacheConfigurationResource.java index c97018c0350..da789ac326e 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CacheConfigurationResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CacheConfigurationResource.java @@ -26,8 +26,6 @@ import java.io.IOException; import java.util.function.Function; -import org.slf4j.Logger; - @Path(ApiConstants.CONFIG + ApiConstants.CACHE) @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @@ -35,9 +33,6 @@ public class CacheConfigurationResource extends ConfigBaseResource { private static final String ERROR_MSG = "Unable to apply patch."; - @Inject - Logger logger; - @Inject ConfigurationService configurationService; @@ -74,7 +69,7 @@ public Response patchCacheConfiguration(@NotNull String requestString) { try { return Jackson.applyPatch(requestString, cache); } catch (IOException | JsonPatchException e) { - throw new RuntimeException(ERROR_MSG, e); + throw new InternalServerErrorException(ERROR_MSG, e); } }); return Response.ok(modifiedCache).build(); @@ -111,7 +106,7 @@ public Response patchRedisConfiguration(@NotNull String requestString) { Jackson.applyPatch(requestString, loadCacheConfiguration().getRedisConfiguration())); return cache; } catch (IOException | JsonPatchException e) { - throw new RuntimeException(ERROR_MSG, e); + throw new InternalServerErrorException(ERROR_MSG, e); } }); return Response.ok(loadCacheConfiguration().getRedisConfiguration()).build(); @@ -148,7 +143,7 @@ public Response patchInMemoryConfiguration(@NotNull String requestString) { cache.setInMemoryConfiguration(Jackson.applyPatch(requestString, cache.getInMemoryConfiguration())); return cache; } catch (IOException | JsonPatchException e) { - throw new RuntimeException(ERROR_MSG, e); + throw new InternalServerErrorException(ERROR_MSG, e); } }); return Response.ok(loadCacheConfiguration().getInMemoryConfiguration()).build(); @@ -187,7 +182,7 @@ public Response patchNativePersistenceConfiguration(@NotNull String requestStrin Jackson.applyPatch(requestString, cache.getNativePersistenceConfiguration())); return cache; } catch (IOException | JsonPatchException e) { - throw new RuntimeException(ERROR_MSG, e); + throw new InternalServerErrorException(ERROR_MSG, e); } }); return Response.ok(loadCacheConfiguration().getNativePersistenceConfiguration()).build(); @@ -223,10 +218,10 @@ public Response patchMemcachedConfiguration(@NotNull String requestString) { cache.setMemcachedConfiguration(Jackson.applyPatch(requestString, cache.getMemcachedConfiguration())); return cache; } catch (IOException | JsonPatchException e) { - throw new RuntimeException(ERROR_MSG, e); + throw new InternalServerErrorException(ERROR_MSG, e); } }); return Response.ok(loadCacheConfiguration().getMemcachedConfiguration()).build(); - } - + } + } diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java index 98998dd8f74..401d670e563 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/rest/resource/auth/CustomScriptResource.java @@ -193,13 +193,18 @@ public Response deleteScript(@PathParam(ApiConstants.INUM) @NotNull String inum) @Path(ApiConstants.INUM_PATH) public Response patchAtribute(@PathParam(ApiConstants.INUM) @NotNull String inum, @NotNull String pathString) throws JsonPatchException, IOException { - log.debug(" Custom Script Resource to patch - inum:{} , pathString:{}", inum, pathString); + if (log.isDebugEnabled()) { + log.debug("Custom Script Resource to patch - inum:{} , pathString:{}", escapeLog(inum), + escapeLog(pathString)); + } + CustomScript existingScript = customScriptService.getScriptByInum(inum); checkResourceNotNull(existingScript, CUSTOM_SCRIPT); existingScript = Jackson.applyPatch(pathString, existingScript); customScriptService.update(existingScript); existingScript = customScriptService.getScriptByInum(inum); - log.debug(" Custom Script Resource after patch - inum:{} , pathString:{}", inum, pathString); + + log.debug(" Custom Script Resource after patch - existingScript:{}", existingScript); return Response.ok(existingScript).build(); } diff --git a/jans-config-api/shared/src/main/java/io/jans/configapi/core/rest/BaseResource.java b/jans-config-api/shared/src/main/java/io/jans/configapi/core/rest/BaseResource.java index 480006515a9..75411ed5fc8 100644 --- a/jans-config-api/shared/src/main/java/io/jans/configapi/core/rest/BaseResource.java +++ b/jans-config-api/shared/src/main/java/io/jans/configapi/core/rest/BaseResource.java @@ -13,6 +13,7 @@ import javax.inject.Inject; import javax.ws.rs.BadRequestException; +import javax.ws.rs.InternalServerErrorException; import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; import java.util.List; @@ -62,6 +63,10 @@ public static void checkNotEmpty(String attribute, String attributeName) { public static void thorwBadRequestException(String msg) { throw new BadRequestException(getBadRequestException(msg)); } + + public static void thorwInternalServerException(String msg) { + throw new InternalServerErrorException(getInternalServerException(msg)); + } /** * @param attributeName