From 235141a1ebd3916c808b8bd1087e3a084df7a6f4 Mon Sep 17 00:00:00 2001 From: Gurleen Kaur <34331959+gurleenkaurbp@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:23:19 +0530 Subject: [PATCH] MODAUD-216 - Remove PII from mod-audit logs (#181) * MODAUD-216 - Improve the log level for the sensitive prints. * MODAUD-216 - Improve the log level for the sensitive prints. --- .../builder/service/LogRecordBuilder.java | 29 ++++++++++--------- .../folio/rest/impl/AuditHandlersService.java | 1 - 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java index 53e4355d..762a0f3e 100644 --- a/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java +++ b/mod-audit-server/src/main/java/org/folio/builder/service/LogRecordBuilder.java @@ -93,7 +93,7 @@ private CompletableFuture handleGetRequest(String endpoint) { HttpClientInterface httpClient = HttpClientFactory.getHttpClient(okapiURL, tenantId); try { - LOGGER.info("handleGetRequest::Calling GET {}", endpoint); + LOGGER.debug("handleGetRequest::Calling GET {}", endpoint); httpClient.request(HttpMethod.GET, endpoint, okapiHeaders) .whenComplete((response, throwable) -> { if (Objects.nonNull(throwable)) { @@ -115,7 +115,7 @@ private CompletableFuture handleGetRequest(String endpoint) { public CompletableFuture getEntitiesByQuery(String url, Class collection, int limit, int offset, String query) { LOGGER.debug("getEntitiesByQuery:: Getting Entities By Query : {}", query); String endpoint = String.format(url + SEARCH_PARAMS, limit, offset, buildQuery(query)); - LOGGER.info("getEntitiesByQuery:: Entities successfully retrieved from endpoint: {}", endpoint); + LOGGER.debug("getEntitiesByQuery:: Entities successfully retrieved from endpoint: {}", endpoint); return handleGetRequest(endpoint).thenApply(response -> response.mapTo(collection)); } @@ -159,7 +159,7 @@ public CompletableFuture fetchUserDetails(JsonObject payload, String .stream() .findFirst() .ifPresent(user -> updatePayload(payload, userId, user)); - LOGGER.info("fetchUserDetails:: Fetched user details for user Id : {}", userId); + LOGGER.debug("fetchUserDetails:: Fetched user details for user Id : {}", userId); return CompletableFuture.completedFuture(payload); }); } @@ -168,7 +168,7 @@ private void updatePayload(JsonObject payload, String userId, User user) { LOGGER.debug("updatePayload:: Updating payload with details for user ID {}", userId); if (nonNull(user)) { if (userId.equals(getProperty(payload, USER_ID))) { - LOGGER.info("updatePayload:: Updating user id to payload because user id : {} matched with user id from payload", userId); + LOGGER.debug("updatePayload:: Updating user id to payload because user id : {} matched with user id from payload", userId); payload.put(USER_BARCODE.value(), user.getBarcode()); } fetchUserPersonal(payload, user); @@ -244,7 +244,7 @@ private String buildQuery(String query) { private String encodeQuery(String query) { LOGGER.debug("encodeQuery:: Encoding Query : {}", query ); try { - LOGGER.info("Encoded query"); + LOGGER.debug("Encoded query"); return URLEncoder.encode(query, StandardCharsets.UTF_8.toString()); } catch (UnsupportedEncodingException e) { LOGGER.warn("Error happened while attempting to encode '{}'", query); @@ -273,7 +273,7 @@ private String convertIdsToCqlQuery(String... ids) { private String convertIdsToCqlQuery(String fieldName, boolean strictMatch, String... values) { LOGGER.debug("convertIdsToCqlQuery:: Converting Ids To CqlQuery with field name : {}", fieldName); String prefix = fieldName + (strictMatch ? "==(" : "=("); - LOGGER.info("Converted IDs to CQL query"); + LOGGER.debug("Converted IDs to CQL query"); return StreamEx.of(values) .joining(" or ", prefix, ")"); } @@ -283,10 +283,10 @@ private CompletableFuture addItemData(JsonObject payload, JsonObject if (nonNull(itemJson)) { ofNullable(getProperty(itemJson, BARCODE)) .ifPresent(barcode -> payload.put(ITEM_BARCODE.value(), barcode)); - LOGGER.info("addItemData:: Added item barcode"); + LOGGER.debug("addItemData:: Added item barcode"); ofNullable(getProperty(itemJson, HOLDINGS_RECORD_ID)) .ifPresent(holdingsRecordId -> payload.put(HOLDINGS_RECORD_ID.value(), holdingsRecordId)); - LOGGER.info("addItemData:: Added holdings record ID"); + LOGGER.debug("addItemData:: Added holdings record ID"); } LOGGER.info("addItemData:: Added Item Data"); return completedFuture(payload); @@ -321,14 +321,15 @@ private static JsonObject verifyAndExtractBody(Response response) { LOGGER.warn("Error calling {} with code {}, response body: {}", endpoint, code, body); return null; } - LOGGER.info("verifyAndExtractBody:: The response body for GET {}: {}", endpoint, nonNull(body) ? body.encodePrettily() : null); + LOGGER.debug("verifyAndExtractBody:: The response body for GET {}: {}", endpoint, nonNull(body) ? body.encodePrettily() : null); + LOGGER.info("verifyAndExtractBody:: Verifying and Extracting Body completed"); return response.getBody(); } protected LogRecord.Action resolveAction(String actionString) { LOGGER.debug("resolveAction:: Resolving Action"); try { - LOGGER.info("resolveAction:: Trying to Resolve Action with action String : {}", actionString); + LOGGER.debug("resolveAction:: Trying to Resolve Action with action String : {}", actionString); return LogRecord.Action.fromValue(actionString); } catch (IllegalArgumentException e) { String errorMessage = "Builder isn't implemented yet for: " + actionString; @@ -343,16 +344,16 @@ protected LogRecord.Action resolveAction(String actionString) { String buildPersonalName(String firstName, String lastName) { LOGGER.debug("buildPersonalName:: Building Personal Name with firstname : {} and lastname : {}", firstName, lastName); if (isNotEmpty(firstName) && isNotEmpty(lastName)) { - LOGGER.info("buildPersonalName:: Built Personal Name with firstname : {} and lastname : {}", firstName, lastName); + LOGGER.debug("buildPersonalName:: Built Personal Name with firstname : {} and lastname : {}", firstName, lastName); return lastName + ", " + firstName; } else if (isEmpty(firstName) && isNotEmpty(lastName)) { - LOGGER.info("buildPersonalName:: Built Personal Name with lastname : {}", lastName); + LOGGER.debug("buildPersonalName:: Built Personal Name with lastname : {}", lastName); return lastName; } else if (isNotEmpty(firstName) && isEmpty(lastName)) { - LOGGER.info("buildPersonalName:: Built Personal Name with firstname : {}", firstName); + LOGGER.debug("buildPersonalName:: Built Personal Name with firstname : {}", firstName); return firstName; } else { - LOGGER.info("buildPersonalName:: Error building personal name because there is no firstname and lastname"); + LOGGER.debug("buildPersonalName:: Error building personal name because there is no firstname and lastname"); return null; } } diff --git a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java index 87d66e7b..e39a48be 100644 --- a/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java +++ b/mod-audit-server/src/main/java/org/folio/rest/impl/AuditHandlersService.java @@ -35,7 +35,6 @@ public void postAuditHandlersLogRecord(String entity, Map okapiH Handler> asyncResultHandler, Context vertxContext) { LOGGER.debug("postAuditHandlersLogRecord:: Trying to Save AuditHandlersLogRecord request with entity: {}", entity); try { - LOGGER.info("postAuditHandlersLogRecord:: Saving AuditHandlersLogRecord request with entity: {}", entity); JsonObject payload = new JsonObject(entity); LogRecordBuilder builder = LogRecordBuilderResolver.getBuilder(payload.getString(LOG_EVENT_TYPE.value()), okapiHeaders, vertxContext); builder.buildLogRecord(payload)