Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ActionManagementAuditLogger #6180

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Action updateAction(String actionType, String actionId, Action action, St
ActionDTO updatingActionDTO = buildActionDTO(resolvedActionType, actionId, action);

DAO_FACADE.updateAction(updatingActionDTO, existingActionDTO, IdentityTenantUtil.getTenantId(tenantDomain));
auditLogger.printAuditLog(ActionManagementAuditLogger.Operation.UPDATE, actionId, updatingActionDTO);
auditLogger.printAuditLog(ActionManagementAuditLogger.Operation.UPDATE, updatingActionDTO);
return getActionByActionId(actionType, actionId, tenantDomain);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ public void printAuditLog(Operation operation, ActionDTO actionDTO) {
buildAuditLog(operation, data);
}

/**
* Print action audit log related to the operation by action ID.
*
* @param operation Operation associated with the state change.
* @param actionId ID of the action to be logged.
* @param actionDTO Action object to be logged.
*/
public void printAuditLog(Operation operation, String actionId, ActionDTO actionDTO) {

if (!LoggerUtils.isEnableV2AuditLogs()) {
return;
}
JSONObject data = createAuditLogEntry(actionId, actionDTO);
buildAuditLog(operation, data);
}

/**
* Print action audit log related to the operation by the action type and action ID.
*
Expand Down Expand Up @@ -105,39 +89,18 @@ private void buildAuditLog(Operation operation, JSONObject data) {
triggerAuditLogEvent(auditLogBuilder);
}

/**
* Create audit log data with action.
* This method expects all the action fields to be non-null/non-empty.
*
* @param actionDTO Action to be logged.
* @return audit log data.
*/
private JSONObject createAuditLogEntry(ActionDTO actionDTO) {

JSONObject data = new JSONObject();
data.put(LogConstants.ACTION_TYPE_FIELD, actionDTO.getType());
data.put(LogConstants.ACTION_ID_FIELD, actionDTO.getId());
data.put(LogConstants.ACTION_NAME_FIELD, actionDTO.getName());
data.put(LogConstants.ACTION_DESCRIPTION_FIELD, actionDTO.getDescription());
data.put(LogConstants.ACTION_STATUS_FIELD, actionDTO.getStatus());
data.put(LogConstants.ENDPOINT_CONFIG_FIELD, getAllEndpointData(actionDTO.getEndpoint()));
data.put(LogConstants.ACTION_PROPERTIES, getPropertiesData(actionDTO.getProperties()));
return data;
}

/**
* Create audit log data with action and ID.
* This method expects null/empty action fields.
*
* @param actionId ID of the action to be logged.
* @param actionDTO Action to be logged.
* @return audit log data.
*/
private JSONObject createAuditLogEntry(String actionId, ActionDTO actionDTO) {
private JSONObject createAuditLogEntry(ActionDTO actionDTO) {

JSONObject data = new JSONObject();
data.put(LogConstants.ACTION_TYPE_FIELD, actionDTO.getType() != null ? actionDTO.getType() : JSONObject.NULL);
data.put(LogConstants.ACTION_ID_FIELD, actionId);
data.put(LogConstants.ACTION_ID_FIELD, actionDTO.getId() != null ? actionDTO.getId() : JSONObject.NULL);
data.put(LogConstants.ACTION_NAME_FIELD, actionDTO.getName() != null ? actionDTO.getName() : JSONObject.NULL);
data.put(LogConstants.ACTION_DESCRIPTION_FIELD,
actionDTO.getDescription() != null ? actionDTO.getDescription() : JSONObject.NULL);
Expand Down Expand Up @@ -167,39 +130,6 @@ private JSONObject createAuditLogEntry(String actionType, String actionId) {
return data;
}

/**
* Retrieve complete endpoint configuration data to be logged.
*
* @param endpointConfig Endpoint data to be logged.
* @return endpoint config data.
*/
private JSONObject getAllEndpointData(EndpointConfig endpointConfig) {

JSONObject endpointData = new JSONObject();
endpointData.put(LogConstants.ENDPOINT_URI_FIELD, endpointConfig.getUri());
Authentication authentication = endpointConfig.getAuthentication();
endpointData.put(LogConstants.AUTHENTICATION_SCHEME_FIELD, authentication.getType().getName());
switch (authentication.getType()) {
case BASIC:
endpointData.put(LogConstants.USERNAME_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.USERNAME).getValue()));
endpointData.put(LogConstants.PASSWORD_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.PASSWORD).getValue()));
break;
case BEARER:
endpointData.put(LogConstants.ACCESS_TOKEN_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.ACCESS_TOKEN).getValue()));
break;
case API_KEY:
endpointData.put(LogConstants.API_KEY_HEADER_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.HEADER).getValue()));
endpointData.put(LogConstants.API_KEY_VALUE_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.VALUE).getValue()));
break;
}
return endpointData;
}

/**
* Retrieve properties data to be logged.
* All the properties will be masked.
Expand Down Expand Up @@ -231,26 +161,20 @@ private JSONObject getEndpointData(EndpointConfig endpointConfig) {
endpointData.put(LogConstants.AUTHENTICATION_SCHEME_FIELD, authentication.getType());
switch (authentication.getType()) {
case BASIC:
endpointData.put(LogConstants.USERNAME_FIELD, LoggerUtils.getMaskedContent(
authentication.getProperty(Authentication.Property.USERNAME) != null
? authentication.getProperty(Authentication.Property.USERNAME).getValue() : ""));
endpointData.put(LogConstants.PASSWORD_FIELD, LoggerUtils.getMaskedContent(
authentication.getProperty(Authentication.Property.PASSWORD) != null
? authentication.getProperty(Authentication.Property.PASSWORD).getValue() : ""));
endpointData.put(LogConstants.USERNAME_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.USERNAME).getValue()));
endpointData.put(LogConstants.PASSWORD_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.PASSWORD).getValue()));
break;
case BEARER:
endpointData.put(LogConstants.ACCESS_TOKEN_FIELD, LoggerUtils.getMaskedContent(
authentication.getProperty(Authentication.Property.ACCESS_TOKEN) != null
? authentication.getProperty(Authentication.Property.ACCESS_TOKEN).
getValue() : ""));
endpointData.put(LogConstants.ACCESS_TOKEN_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.ACCESS_TOKEN).getValue()));
break;
case API_KEY:
endpointData.put(LogConstants.API_KEY_HEADER_FIELD, LoggerUtils.getMaskedContent(
authentication.getProperty(Authentication.Property.HEADER) != null
? authentication.getProperty(Authentication.Property.HEADER).getValue() : ""));
endpointData.put(LogConstants.API_KEY_VALUE_FIELD, LoggerUtils.getMaskedContent(
authentication.getProperty(Authentication.Property.VALUE) != null
? authentication.getProperty(Authentication.Property.VALUE).getValue() : ""));
endpointData.put(LogConstants.API_KEY_HEADER_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.HEADER).getValue()));
endpointData.put(LogConstants.API_KEY_VALUE_FIELD, LoggerUtils.getMaskedContent(authentication.
getProperty(Authentication.Property.VALUE).getValue()));
break;
}
}
Expand Down
Loading
Loading