Skip to content

Commit

Permalink
Fix #925: Audit type missing in AuditingServiceBehavior (#927)
Browse files Browse the repository at this point in the history
* Fix #925: Audit type missing in AuditingServiceBehavior
- Add AuditType enum
- Replace the hardcoded strings for AuditDetail type in several classes
- Add javadoc
  • Loading branch information
jandusil authored Jul 18, 2023
1 parent e5894f6 commit 0c6c446
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public AddActivationFlagsResponse addActivationFlags(String activationId, List<S
final List<String> newFlags = activationFlags.stream().filter(flag -> !currentFlags.contains(flag)).collect(Collectors.toList());
if (!newFlags.isEmpty()) { // only in case there are new flags
final AuditDetail auditDetail = AuditDetail.builder()
.type("activation")
.type(AuditType.ACTIVATION.getCode())
.param("activationId", activationId)
.param("flags", newFlags)
.param("addedFlags", activationFlags)
Expand Down Expand Up @@ -148,7 +148,7 @@ public UpdateActivationFlagsResponse updateActivationFlags(String activationId,
throw localizationProvider.buildExceptionForCode(ServiceError.ACTIVATION_NOT_FOUND);
}
final AuditDetail auditDetail = AuditDetail.builder()
.type("activation")
.type(AuditType.ACTIVATION.getCode())
.param("activationId", activationId)
.param("flags", activationFlags)
.build();
Expand Down Expand Up @@ -185,7 +185,7 @@ public RemoveActivationFlagsResponse removeActivationFlags(String activationId,
throw localizationProvider.buildExceptionForCode(ServiceError.ACTIVATION_NOT_FOUND);
}
final AuditDetail auditDetail = AuditDetail.builder()
.type("activation")
.type(AuditType.ACTIVATION.getCode())
.param("activationId", activationId)
.param("removedFlags", activationFlags)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public ActivationHistoryResponse getActivationHistory(String activationId, Date
private void logAuditItem(ActivationRecordEntity activation, String externalUserId, String historyEventReason) {
// Prepare shared parameters
final AuditDetail.Builder auditDetailBuilder = AuditDetail.builder()
.type("activation")
.type(AuditType.ACTIVATION.getCode())
.param("activationId", activation.getActivationId())
.param("userId", activation.getUserId())
.param("applicationId", activation.getApplication().getId())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* PowerAuth Server and related software components
* Copyright (C) 2023 Wultra s.r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.getlime.security.powerauth.app.server.service.behavior.tasks;

/**
* This enum represents different types of audits.
*
* @author Jan Dusil, jan.dusil@wultra.com
*/
enum AuditType {

/**
* Audit type for signatures.
*/
SIGNATURE("signature"),

/**
* Audit type for operations.
*/
OPERATION("operation"),

/**
* Audit type for activations.
*/
ACTIVATION("activation");

/**
* The code associated with each audit type.
*/
private final String code;

/**
* Constructor to initialize the audit type with its code.
*
* @param code the code of the audit type
*/
AuditType(final String code) {
this.code = code;
}

/**
* Get the code of the audit type.
*
* @return the code of the audit type
*/
public String getCode() {
return this.code;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public void logSignatureAuditRecord(ActivationRecordDto activation, SignatureDat
.param("activationVersion", version)
.param("note", note)
.param("timestamp", currentTimestamp)
.type(AuditType.SIGNATURE.getCode())
.build();
audit.log("Signature validation completed: {}, activation ID: {}, user ID: {}", AuditLevel.INFO, auditDetail,
(valid ? "SUCCESS" : "FAILURE (" + note + ")"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public OperationDetailResponse createOperation(OperationCreateRequest request) t
operationEntity.setTotpSeed(generateTotpSeed(request, templateEntity));

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("userId", userId)
.param("applications", applications)
Expand Down Expand Up @@ -268,7 +268,7 @@ && proximityCheckPassed(proximityCheckResult)){
final OperationDetailResponse operationDetailResponse = convertFromEntity(savedEntity);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("userId", userId)
.param("appId", applicationId)
Expand Down Expand Up @@ -301,7 +301,7 @@ && proximityCheckPassed(proximityCheckResult)){
logger.info("Operation approval failed for operation ID: {}, user ID: {}, application ID: {}.", operationId, userId, applicationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("userId", userId)
.param("appId", applicationId)
Expand Down Expand Up @@ -330,7 +330,7 @@ && proximityCheckPassed(proximityCheckResult)){
logger.info("Operation failed for operation ID: {}, user ID: {}, application ID: {}.", operationId, userId, applicationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("userId", userId)
.param("appId", applicationId)
Expand Down Expand Up @@ -396,7 +396,7 @@ public OperationUserActionResponse rejectOperation(OperationRejectRequest reques
logger.info("Operation rejected operation ID: {}, user ID: {}, application ID: {}.", operationId, userId, applicationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("userId", userId)
.param("appId", applicationId)
Expand All @@ -414,7 +414,7 @@ public OperationUserActionResponse rejectOperation(OperationRejectRequest reques
logger.info("Operation reject failed for operation ID: {}, user ID: {}, application ID: {}.", operationId, userId, applicationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("userId", userId)
.param("appId", applicationId)
Expand Down Expand Up @@ -468,7 +468,7 @@ public OperationUserActionResponse failApprovalOperation(OperationFailApprovalRe
logger.info("Operation approval failed via explicit server call for operation ID: {}.", operationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("failureCount", operationEntity.getFailureCount())
.param("status", operationEntity.getStatus().name())
Expand All @@ -493,7 +493,7 @@ public OperationUserActionResponse failApprovalOperation(OperationFailApprovalRe
logger.info("Operation approval permanently failed via explicit server call for operation ID: {}.", operationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("failureCount", operationEntity.getFailureCount())
.param("status", operationEntity.getStatus().name())
Expand Down Expand Up @@ -539,7 +539,7 @@ public OperationDetailResponse cancelOperation(OperationCancelRequest request) t
logger.info("Operation canceled via explicit server call for operation ID: {}.", operationId);

final AuditDetail auditDetail = AuditDetail.builder()
.type("operation")
.type(AuditType.OPERATION.getCode())
.param("id", operationId)
.param("failureCount", operationEntity.getFailureCount())
.param("status", operationEntity.getStatus().name())
Expand Down

0 comments on commit 0c6c446

Please sign in to comment.