From f36922762590bea8cfa559641b45c87ed5d4772d Mon Sep 17 00:00:00 2001
From: klaraf755 <80590912+klaraf755@users.noreply.github.com>
Date: Thu, 12 Sep 2024 07:30:10 +0200
Subject: [PATCH 01/12] Clean up code related to filtering (#856)
---
pom.xml | 4 +-
.../core/api/ExceptionHandlingAdvice.java | 11 +
.../api/web/CertificateControllerImpl.java | 12 +-
.../SecurityFilterRepositoryImpl.java | 14 +-
.../core/enums/SearchFieldNameEnum.java | 128 ----
.../evaluator/CertificateRuleEvaluator.java | 6 +-
.../core/evaluator/RuleEvaluator.java | 46 +-
.../CertificateEventHistoryService.java | 3 -
.../core/service/CertificateService.java | 4 +-
.../core/service/SearchService.java | 23 -
.../service/impl/AuditLogServiceImpl.java | 4 +-
.../CertificateEventHistoryServiceImpl.java | 15 -
.../service/impl/CertificateServiceImpl.java | 148 +---
.../impl/CryptographicKeyServiceImpl.java | 25 +-
.../service/impl/DiscoveryServiceImpl.java | 17 +-
.../impl/EntityInstanceServiceImpl.java | 8 +-
.../service/impl/LocationServiceImpl.java | 16 +-
.../service/impl/ResourceServiceImpl.java | 16 +-
.../service/impl/SchedulerServiceImpl.java | 16 +-
.../core/service/impl/SearchServiceImpl.java | 296 --------
.../core/util/FilterPredicatesBuilder.java | 87 +++
.../czertainly/core/util/SearchHelper.java | 20 +-
.../converter/Sql2PredicateConverter.java | 464 ------------
.../core/evaluator/RuleEvaluatorTest.java | 45 +-
.../search/DiscoveryHistorySearchTest.java | 28 +-
.../core/search/EntityInstanceSearchTest.java | 8 +-
.../core/search/LocationsSearchTest.java | 12 +-
.../core/service/CertificateServiceTest.java | 3 +-
.../util/FilterPredicatesBuilderTest.java | 684 +++++++++++++++++-
.../converter/Sql2PredicateConverterTest.java | 383 ----------
30 files changed, 948 insertions(+), 1598 deletions(-)
delete mode 100644 src/main/java/com/czertainly/core/enums/SearchFieldNameEnum.java
delete mode 100644 src/main/java/com/czertainly/core/service/SearchService.java
delete mode 100644 src/main/java/com/czertainly/core/service/impl/SearchServiceImpl.java
delete mode 100644 src/main/java/com/czertainly/core/util/converter/Sql2PredicateConverter.java
delete mode 100644 src/test/java/com/czertainly/core/util/converter/Sql2PredicateConverterTest.java
diff --git a/pom.xml b/pom.xml
index 4166b7fca..74da60719 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
core
- 2.13.0
+ 2.13.1-SNAPSHOT
CZERTAINLY-Core
@@ -49,7 +49,7 @@
com.czertainly
interfaces
- 2.13.0
+ 2.13.1-SNAPSHOT
diff --git a/src/main/java/com/czertainly/core/api/ExceptionHandlingAdvice.java b/src/main/java/com/czertainly/core/api/ExceptionHandlingAdvice.java
index b8463b107..352722777 100644
--- a/src/main/java/com/czertainly/core/api/ExceptionHandlingAdvice.java
+++ b/src/main/java/com/czertainly/core/api/ExceptionHandlingAdvice.java
@@ -458,6 +458,17 @@ public ErrorMessageDto handleCertificateRequestException(CertificateRequestExcep
return ErrorMessageDto.getInstance(ex.getMessage() + cause);
}
+ /**
+ * Handler for {@link NotSupportedException}.
+ *
+ * @return {@link ErrorMessageDto}
+ */
+ @ExceptionHandler(NotSupportedException.class)
+ @ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
+ public ErrorMessageDto handleTokenInstanceException(NotSupportedException ex) {
+ LOG.debug("HTTP 501: {}", ex.getMessage());
+ return ErrorMessageDto.getInstance(ex.getMessage());
+ }
/**
* Handler for {@link Exception}.
diff --git a/src/main/java/com/czertainly/core/api/web/CertificateControllerImpl.java b/src/main/java/com/czertainly/core/api/web/CertificateControllerImpl.java
index c243a72ff..1cc2caf4a 100644
--- a/src/main/java/com/czertainly/core/api/web/CertificateControllerImpl.java
+++ b/src/main/java/com/czertainly/core/api/web/CertificateControllerImpl.java
@@ -81,7 +81,10 @@ public void updateCertificateObjects(String uuid, CertificateUpdateObjectsDto re
}
@Override
- public void bulkUpdateCertificateObjects(MultipleCertificateObjectUpdateDto request) throws NotFoundException {
+ public void bulkUpdateCertificateObjects(MultipleCertificateObjectUpdateDto request) throws NotFoundException, NotSupportedException {
+ if (request.getFilters() != null && !request.getFilters().isEmpty() && (request.getCertificateUuids() == null || request.getCertificateUuids().isEmpty())) {
+ throw new NotSupportedException("Bulk updating of certificates by filters is not supported.");
+ }
certificateService.bulkUpdateCertificateObjects(SecurityFilter.create(), request);
}
@@ -100,9 +103,12 @@ public ResponseEntity upload(@RequestBody UploadCertificateRequestDto r
}
@Override
- public BulkOperationResponse bulkDeleteCertificate(@RequestBody RemoveCertificateDto request) throws NotFoundException {
- certificateService.bulkDeleteCertificate(SecurityFilter.create(), request);
+ public BulkOperationResponse bulkDeleteCertificate(@RequestBody RemoveCertificateDto request) throws NotFoundException, NotSupportedException {
BulkOperationResponse response = new BulkOperationResponse();
+ if (request.getFilters() != null && !request.getFilters().isEmpty() && (request.getUuids() == null || request.getUuids().isEmpty())) {
+ throw new NotSupportedException("Bulk delete of certificates by filters is not supported.");
+ }
+ certificateService.bulkDeleteCertificate(SecurityFilter.create(), request);
response.setMessage("Initiated bulk delete Certificates. Please refresh after some time");
response.setStatus(BulkOperationStatus.SUCCESS);
return response;
diff --git a/src/main/java/com/czertainly/core/dao/repository/SecurityFilterRepositoryImpl.java b/src/main/java/com/czertainly/core/dao/repository/SecurityFilterRepositoryImpl.java
index 1b350c838..c76c7cc14 100644
--- a/src/main/java/com/czertainly/core/dao/repository/SecurityFilterRepositoryImpl.java
+++ b/src/main/java/com/czertainly/core/dao/repository/SecurityFilterRepositoryImpl.java
@@ -3,14 +3,14 @@
import com.czertainly.api.exception.ValidationError;
import com.czertainly.api.exception.ValidationException;
import com.czertainly.api.model.common.NameAndUuidDto;
-import com.czertainly.core.dao.entity.*;
import com.czertainly.core.dao.AggregateResultDto;
+import com.czertainly.core.dao.entity.CryptographicKeyItem;
import com.czertainly.core.model.auth.ResourceAction;
import com.czertainly.core.security.authz.SecuredUUID;
import com.czertainly.core.security.authz.SecurityFilter;
import com.czertainly.core.security.authz.SecurityResourceFilter;
import com.czertainly.core.util.AuthHelper;
-import com.czertainly.core.util.converter.Sql2PredicateConverter;
+import com.czertainly.core.util.FilterPredicatesBuilder;
import jakarta.persistence.EntityManager;
import jakarta.persistence.NoResultException;
import jakarta.persistence.criteria.*;
@@ -241,8 +241,8 @@ private List getPredicates(SecurityFilter filter, TriFunction
try {
NameAndUuidDto userInformation = AuthHelper.getUserIdentification();
String ownerAttributePath = root.getJavaType().equals(CryptographicKeyItem.class) ? "cryptographicKey.owner" : "owner";
- Join fromOwner = Sql2PredicateConverter.prepareJoin(root, ownerAttributePath);
- combinedObjectAccessPredicates.add(cb.equal(Sql2PredicateConverter.prepareExpression(fromOwner, "ownerUsername"), userInformation.getName()));
+ Join fromOwner = FilterPredicatesBuilder.prepareJoin(root, ownerAttributePath);
+ combinedObjectAccessPredicates.add(cb.equal(FilterPredicatesBuilder.prepareExpression(fromOwner, "ownerUsername"), userInformation.getName()));
} catch (ValidationException e) {
// cannot apply filter predicate for anonymous user
}
@@ -266,14 +266,14 @@ private Predicate getPredicateBySecurityResourceFilter(Root root, SecurityRes
if (resourceFilter != null) {
From from = root;
if (attributeName.contains(".")) {
- from = Sql2PredicateConverter.prepareJoin(root, attributeName.substring(0, attributeName.lastIndexOf(".")));
+ from = FilterPredicatesBuilder.prepareJoin(root, attributeName.substring(0, attributeName.lastIndexOf(".")));
attributeName = attributeName.substring(attributeName.lastIndexOf(".") + 1);
}
if (resourceFilter.areOnlySpecificObjectsAllowed()) {
- predicate = Sql2PredicateConverter.prepareExpression(from, attributeName).in(resourceFilter.getAllowedObjects());
+ predicate = FilterPredicatesBuilder.prepareExpression(from, attributeName).in(resourceFilter.getAllowedObjects());
} else {
if (!resourceFilter.getForbiddenObjects().isEmpty()) {
- predicate = Sql2PredicateConverter.prepareExpression(from, attributeName).in(resourceFilter.getForbiddenObjects()).not();
+ predicate = FilterPredicatesBuilder.prepareExpression(from, attributeName).in(resourceFilter.getForbiddenObjects()).not();
}
}
}
diff --git a/src/main/java/com/czertainly/core/enums/SearchFieldNameEnum.java b/src/main/java/com/czertainly/core/enums/SearchFieldNameEnum.java
deleted file mode 100644
index c75a00d74..000000000
--- a/src/main/java/com/czertainly/core/enums/SearchFieldNameEnum.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package com.czertainly.core.enums;
-
-import com.czertainly.api.model.core.auth.Resource;
-import com.czertainly.api.model.core.search.SearchableFields;
-
-import java.util.Arrays;
-import java.util.List;
-
-public enum SearchFieldNameEnum {
-
- // Certificate
- COMMON_NAME(SearchableFields.COMMON_NAME, "Common Name", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- SERIAL_NUMBER_LABEL(SearchableFields.SERIAL_NUMBER, "Serial Number", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- RA_PROFILE(SearchableFields.RA_PROFILE_NAME, "RA Profile", SearchFieldTypeEnum.LIST, true, Resource.CERTIFICATE, Resource.RA_PROFILE),
- CERTIFICATE_STATE(SearchableFields.CERTIFICATE_STATE, "State", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- CERTIFICATE_VALIDATION_STATUS(SearchableFields.CERTIFICATE_VALIDATION_STATUS, "Validation status", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- GROUP(SearchableFields.GROUP_NAME, "Groups", SearchFieldTypeEnum.LIST, true, Resource.CERTIFICATE, Resource.GROUP),
- CERT_LOCATION_NAME(SearchableFields.CERT_LOCATION_NAME, "Locations", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, Resource.LOCATION),
- OWNER(SearchableFields.OWNER, "Owner", SearchFieldTypeEnum.LIST, true, Resource.CERTIFICATE, Resource.USER),
- ISSUER_COMMON_NAME(SearchableFields.ISSUER_COMMON_NAME, "Issuer Common Name", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- SIGNATURE_ALGORITHM(SearchableFields.SIGNATURE_ALGORITHM, "Signature Algorithm", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- FINGERPRINT(SearchableFields.FINGERPRINT, "Fingerprint", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- EXPIRES(SearchableFields.NOT_AFTER, "Expires At", SearchFieldTypeEnum.DATE, false, Resource.CERTIFICATE, null),
- NOT_BEFORE(SearchableFields.NOT_BEFORE, "Valid From", SearchFieldTypeEnum.DATE, false, Resource.CERTIFICATE, null),
- PUBLIC_KEY_ALGORITHM(SearchableFields.PUBLIC_KEY_ALGORITHM, "Public Key Algorithm", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- KEY_SIZE(SearchableFields.KEY_SIZE, "Key Size", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- KEY_USAGE(SearchableFields.KEY_USAGE, "Key Usage", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- BASIC_CONSTRAINTS(SearchableFields.BASIC_CONSTRAINTS, "Basic Constraints", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- SUBJECT_ALTERNATIVE(SearchableFields.SUBJECT_ALTERNATIVE_NAMES, "Subject Alternative Name", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- SUBJECT_DN(SearchableFields.SUBJECTDN, "Subject DN", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- ISSUER_DN(SearchableFields.ISSUERDN, "Issuer DN", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- ISSUER_SERIAL_NUMBER(SearchableFields.ISSUER_SERIAL_NUMBER, "Issuer Serial Number", SearchFieldTypeEnum.STRING, false, Resource.CERTIFICATE, null),
- OCSP_VALIDATION(SearchableFields.OCSP_VALIDATION, "OCSP Validation", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- CRL_VALIDATION(SearchableFields.CRL_VALIDATION, "CRL Validation", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- SIGNATURE_VALIDATION(SearchableFields.SIGNATURE_VALIDATION, "Signature Validation", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- COMPLIANCE_STATUS(SearchableFields.COMPLIANCE_STATUS, "Compliance Status", SearchFieldTypeEnum.LIST, false, Resource.CERTIFICATE, null),
- PRIVATE_KEY(SearchableFields.PRIVATE_KEY, "Has private key", SearchFieldTypeEnum.BOOLEAN, false, Resource.CERTIFICATE, null),
- TRUSTED_CA(SearchableFields.TRUSTED_CA, "Trusted CA", SearchFieldTypeEnum.BOOLEAN, false, Resource.CERTIFICATE, null),
-
- // Cryptographic Key
- CKI_NAME(SearchableFields.CKI_NAME, "Name", SearchFieldTypeEnum.STRING, false, Resource.CRYPTOGRAPHIC_KEY, null),
- KEY_TYPE(SearchableFields.CKI_TYPE, "Key type", SearchFieldTypeEnum.LIST, false, Resource.CRYPTOGRAPHIC_KEY, null),
- KEY_FORMAT(SearchableFields.CKI_FORMAT, "Key format", SearchFieldTypeEnum.LIST, false, Resource.CRYPTOGRAPHIC_KEY, null),
- KEY_STATE(SearchableFields.CKI_STATE, "State", SearchFieldTypeEnum.LIST, true, Resource.CRYPTOGRAPHIC_KEY, null),
- KEY_CRYPTOGRAPHIC_ALGORITHM(SearchableFields.CKI_CRYPTOGRAPHIC_ALGORITHM, "Cryptographic algorithm", SearchFieldTypeEnum.LIST, false, Resource.CRYPTOGRAPHIC_KEY, null),
- KEY_TOKEN_PROFILE(SearchableFields.CK_TOKEN_PROFILE, "Token profile", SearchFieldTypeEnum.LIST, false, Resource.CRYPTOGRAPHIC_KEY, Resource.TOKEN_PROFILE),
- KEY_TOKEN_INSTANCE_LABEL(SearchableFields.CK_TOKEN_INSTANCE, "Token instance", SearchFieldTypeEnum.LIST, true, Resource.CRYPTOGRAPHIC_KEY, Resource.TOKEN),
- KEY_LENGTH(SearchableFields.CKI_LENGTH, "Key Size", SearchFieldTypeEnum.NUMBER, false, Resource.CRYPTOGRAPHIC_KEY, null),
- CK_GROUP(SearchableFields.CK_GROUP, "Groups", SearchFieldTypeEnum.LIST, true, Resource.CRYPTOGRAPHIC_KEY, Resource.GROUP),
- CK_OWNER(SearchableFields.CK_OWNER, "Owner", SearchFieldTypeEnum.LIST, true, Resource.CRYPTOGRAPHIC_KEY, Resource.USER),
- CK_KEY_USAGE(SearchableFields.CKI_USAGE, "Key Usage", SearchFieldTypeEnum.LIST, true, Resource.CRYPTOGRAPHIC_KEY, null),
-
- // Discovery
- DISCOVERY_NAME(SearchableFields.DISCOVERY_NAME, "Name", SearchFieldTypeEnum.DATETIME, false, Resource.DISCOVERY, null),
- DISCOVERY_START_TIME(SearchableFields.DISCOVERY_START_TIME, "Start time", SearchFieldTypeEnum.DATETIME, false, Resource.DISCOVERY, null),
- DISCOVERY_END_TIME(SearchableFields.DISCOVERY_END_TIME, "End time", SearchFieldTypeEnum.DATETIME, false, Resource.DISCOVERY, null),
- DISCOVERY_TOTAL_CERT_DISCOVERED(SearchableFields.DISCOVERY_TOTAL_CERT_DISCOVERED, "Total certificate discovered", SearchFieldTypeEnum.NUMBER, false, Resource.DISCOVERY, null),
- DISCOVERY_CONNECTOR_NAME(SearchableFields.DISCOVERY_CONNECTOR_NAME, "Discovery provider",SearchFieldTypeEnum.LIST, false, Resource.DISCOVERY, null),
- DISCOVERY_KIND(SearchableFields.DISCOVERY_KIND, "Kind",SearchFieldTypeEnum.STRING, false, Resource.DISCOVERY, null),
- DISCOVERY_STATUS(SearchableFields.DISCOVERY_STATUS, "Status", SearchFieldTypeEnum.LIST, false, Resource.DISCOVERY, null),
-
- // Entity
- ENTITY_NAME(SearchableFields.ENTITY_NAME, "Name", SearchFieldTypeEnum.STRING, false, Resource.ENTITY, null),
- ENTITY_CONNECTOR_NAME(SearchableFields.ENTITY_CONNECTOR_NAME, "Entity provider", SearchFieldTypeEnum.LIST, false, Resource.ENTITY, null),
- ENTITY_KIND(SearchableFields.ENTITY_KIND, "Kind", SearchFieldTypeEnum.LIST, false, Resource.ENTITY, null),
-
- // Location
- LOCATION_NAME(SearchableFields.LOCATION_NAME, "Name", SearchFieldTypeEnum.STRING, false, Resource.LOCATION, null),
- LOCATION_ENTITY_INSTANCE(SearchableFields.LOCATION_ENTITY_INSTANCE, "Entity instance", SearchFieldTypeEnum.LIST, false, Resource.LOCATION, Resource.ENTITY),
- LOCATION_ENABLED(SearchableFields.LOCATION_ENABLED, "Enabled", SearchFieldTypeEnum.BOOLEAN, true, Resource.LOCATION, null),
- LOCATION_SUPPORT_MULTIPLE_ENTRIES(SearchableFields.LOCATION_SUPPORT_MULTIPLE_ENTRIES, "Support multiple entries", SearchFieldTypeEnum.BOOLEAN, false, Resource.LOCATION, null),
- LOCATION_SUPPORT_KEY_MANAGEMENT(SearchableFields.LOCATION_SUPPORT_KEY_MANAGEMENT, "Support key management", SearchFieldTypeEnum.BOOLEAN, false, Resource.LOCATION, null),
- ;
-
- private final SearchableFields fieldProperty;
-
- private final String fieldLabel;
-
- private final SearchFieldTypeEnum fieldTypeEnum;
-
- private final boolean settable;
-
- private final Resource resource;
-
- private final Resource fieldResource;
-
- SearchFieldNameEnum(final SearchableFields fieldProperty, final String fieldLabel, final SearchFieldTypeEnum fieldTypeEnum, final boolean settable, final Resource resource, final Resource fieldResource) {
- this.fieldProperty = fieldProperty;
- this.fieldLabel = fieldLabel;
- this.fieldTypeEnum = fieldTypeEnum;
- this.settable = settable;
- this.resource = resource;
- this.fieldResource = fieldResource;
- }
-
- public SearchableFields getFieldProperty() {
- return fieldProperty;
- }
-
- public String getFieldLabel() {
- return fieldLabel;
- }
-
- public SearchFieldTypeEnum getFieldTypeEnum() {
- return fieldTypeEnum;
- }
-
- public boolean isSettable() {
- return settable;
- }
-
- public Resource getResource() { return this.resource; }
-
- public Resource getFieldResource() {return this.fieldResource;}
-
- public static SearchFieldNameEnum getEnumBySearchableFields(final SearchableFields searchableFields) {
- for (SearchFieldNameEnum searchFieldNameEnum : SearchFieldNameEnum.values()) {
- if (searchFieldNameEnum.getFieldProperty().equals(searchableFields)) {
- return searchFieldNameEnum;
- }
- }
- return null;
- }
-
- public static List getEnumsForResource(Resource resource) {
- return Arrays.stream(SearchFieldNameEnum.values()).filter(searchFieldNameEnum -> searchFieldNameEnum.resource == resource).toList();
- }
-}
diff --git a/src/main/java/com/czertainly/core/evaluator/CertificateRuleEvaluator.java b/src/main/java/com/czertainly/core/evaluator/CertificateRuleEvaluator.java
index 7d934c835..89721e492 100644
--- a/src/main/java/com/czertainly/core/evaluator/CertificateRuleEvaluator.java
+++ b/src/main/java/com/czertainly/core/evaluator/CertificateRuleEvaluator.java
@@ -6,9 +6,9 @@
import com.czertainly.api.exception.RuleException;
import com.czertainly.api.model.core.auth.Resource;
import com.czertainly.api.model.core.search.FilterFieldSource;
-import com.czertainly.api.model.core.search.SearchableFields;
import com.czertainly.core.dao.entity.Certificate;
import com.czertainly.core.dao.entity.workflows.ExecutionItem;
+import com.czertainly.core.enums.FilterField;
import com.czertainly.core.security.authz.SecuredUUID;
import com.czertainly.core.service.CertificateService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -37,9 +37,9 @@ public void performAction(ExecutionItem executionItem, Certificate object, Resou
SecuredUUID certificateUuid = object.getSecuredUuid();
- SearchableFields searchableField;
+ FilterField searchableField;
try {
- searchableField = Enum.valueOf(SearchableFields.class, executionItem.getFieldIdentifier());
+ searchableField = Enum.valueOf(FilterField.class, executionItem.getFieldIdentifier());
} catch (IllegalArgumentException e) {
throw new RuleException("Field identifier '" + executionItem.getFieldIdentifier() + "' is not supported.");
}
diff --git a/src/main/java/com/czertainly/core/evaluator/RuleEvaluator.java b/src/main/java/com/czertainly/core/evaluator/RuleEvaluator.java
index bcb64a811..9a8dd3c4c 100644
--- a/src/main/java/com/czertainly/core/evaluator/RuleEvaluator.java
+++ b/src/main/java/com/czertainly/core/evaluator/RuleEvaluator.java
@@ -13,14 +13,15 @@
import com.czertainly.api.model.core.search.FilterConditionOperator;
import com.czertainly.api.model.core.search.FilterFieldSource;
import com.czertainly.api.model.core.search.FilterFieldType;
-import com.czertainly.api.model.core.search.SearchableFields;
import com.czertainly.core.attribute.engine.AttributeEngine;
import com.czertainly.core.attribute.engine.records.ObjectAttributeContentInfo;
import com.czertainly.core.dao.entity.workflows.*;
+import com.czertainly.core.enums.FilterField;
import com.czertainly.core.enums.ResourceToClass;
-import com.czertainly.core.enums.SearchFieldNameEnum;
import com.czertainly.core.service.TriggerService;
import com.czertainly.core.util.AttributeDefinitionUtils;
+import com.czertainly.core.util.FilterPredicatesBuilder;
+import jakarta.persistence.metamodel.Attribute;
import org.apache.commons.beanutils.PropertyUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -116,37 +117,27 @@ public Boolean evaluateConditionItem(ConditionItem conditionItem, T object, Reso
// First, check where from to get object value based on Field Source
if (fieldSource == FilterFieldSource.PROPERTY) {
Object objectValue;
- SearchableFields field;
+ FilterField field;
try {
- field = Enum.valueOf(SearchableFields.class, fieldIdentifier);
+ field = Enum.valueOf(FilterField.class, fieldIdentifier);
} catch (IllegalArgumentException e) {
throw new RuleException("Field identifier '" + fieldIdentifier + "' is not supported.");
}
// Get value of property from the object
try {
- objectValue = getPropertyValue(object, field.getCode(), false);
+ objectValue = getPropertyValue(object, field, false);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuleException("Cannot get property " + fieldIdentifier + " from resource " + resource + ".");
}
- // Determine field type from field identifier using Searchable field enum
- SearchFieldNameEnum propertyEnum;
- try {
- propertyEnum = SearchFieldNameEnum.getEnumBySearchableFields(field);
- } catch (Exception e) {
- throw new RuleException("Field identifier '" + fieldIdentifier + "' is not supported.");
- }
- if (propertyEnum == null) {
- throw new RuleException("Unknown property field identifier: " + fieldIdentifier);
- }
- FilterFieldType fieldType = propertyEnum.getFieldTypeEnum().getFieldType();
+ FilterFieldType fieldType = field.getType().getFieldType();
// Apply comparing function on value in object and value in condition, based on operator and field type, return whether the condition is satisfied
try {
if (!(objectValue instanceof Collection> objectValues)) {
return fieldTypeToOperatorActionMap.get(fieldType).get(operator).apply(objectValue, conditionValue);
}
for (Object item : objectValues) {
- Object o = getPropertyValue(item, field.getCode(), true);
+ Object o = getPropertyValue(item, field, true);
if (!fieldTypeToOperatorActionMap.get(fieldType).get(operator).apply(o, conditionValue)) {
return false;
}
@@ -238,14 +229,14 @@ public void performAction(ExecutionItem executionItem, T object, Resource resour
// Set a property of the object using setter, the property must be set as settable
if (fieldSource == FilterFieldSource.PROPERTY) {
- SearchFieldNameEnum propertyEnum = SearchFieldNameEnum.getEnumBySearchableFields(SearchableFields.fromCode(fieldIdentifier));
+ FilterField propertyEnum = Enum.valueOf(FilterField.class, fieldIdentifier);
if (propertyEnum == null) {
throw new RuleException("Field identifier '" + fieldIdentifier + "' is not supported.");
}
if (!propertyEnum.isSettable())
throw new RuleException("Setting property '" + fieldIdentifier + "' is not supported.");
try {
- PropertyUtils.setProperty(object, propertyEnum.getFieldProperty().getCode(), actionData);
+ PropertyUtils.setProperty(object, propertyEnum.getFieldAttribute().getName(), actionData);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException |
NoSuchMethodException e) {
throw new RuleException(e.getMessage());
@@ -268,29 +259,32 @@ public void performAction(ExecutionItem executionItem, T object, Resource resour
}
}
- private Object getPropertyValue(Object object, String fieldIdentifier, boolean alreadyNested) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
- final int indexOfDot = fieldIdentifier.lastIndexOf(".");
- boolean isNested = indexOfDot != -1;
+ private Object getPropertyValue(Object object, FilterField filterField, boolean alreadyNested) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
+ boolean isNested = filterField.getJoinAttributes() != null;
+ String pathToProperty = FilterPredicatesBuilder.buildPathToProperty(filterField, alreadyNested);
+
try {
if (alreadyNested) {
- return PropertyUtils.getProperty(object, fieldIdentifier.substring(indexOfDot + 1));
+ return PropertyUtils.getProperty(object, pathToProperty);
}
- return PropertyUtils.getProperty(object, fieldIdentifier);
+ return PropertyUtils.getProperty(object, pathToProperty);
} catch (NoSuchMethodException e) {
if (!isNested || alreadyNested) {
throw e;
}
- final String parentPropertyIdentifier = fieldIdentifier.substring(0, indexOfDot);
- Object tmpValue = PropertyUtils.getProperty(object, parentPropertyIdentifier);
+ Object tmpValue = PropertyUtils.getProperty(object, filterField.getJoinAttributes().getFirst().getName());
if (tmpValue instanceof Collection>) {
return tmpValue;
}
throw e;
+
}
+
}
+
private boolean getConditionEvaluationResult(ConditionItem conditionItem, T object, TriggerHistory triggerHistory, Rule rule) {
try {
if (!evaluateConditionItem(conditionItem, object, rule.getResource())) {
diff --git a/src/main/java/com/czertainly/core/service/CertificateEventHistoryService.java b/src/main/java/com/czertainly/core/service/CertificateEventHistoryService.java
index 4b26b2ad1..17e33fa21 100644
--- a/src/main/java/com/czertainly/core/service/CertificateEventHistoryService.java
+++ b/src/main/java/com/czertainly/core/service/CertificateEventHistoryService.java
@@ -1,11 +1,9 @@
package com.czertainly.core.service;
import com.czertainly.api.exception.NotFoundException;
-import com.czertainly.api.model.client.certificate.SearchFilterRequestDto;
import com.czertainly.api.model.core.certificate.CertificateEvent;
import com.czertainly.api.model.core.certificate.CertificateEventHistoryDto;
import com.czertainly.api.model.core.certificate.CertificateEventStatus;
-import com.czertainly.api.model.core.search.SearchFieldDataDto;
import com.czertainly.core.dao.entity.Certificate;
import com.czertainly.core.dao.entity.CertificateEventHistory;
@@ -31,5 +29,4 @@ public interface CertificateEventHistoryService {
void addEventHistory(UUID certificateUuid, CertificateEvent event, CertificateEventStatus status, String message, String additionalInformation);
- void addEventHistoryForRequest(List filters, String entity, List originalJson, CertificateEvent event, CertificateEventStatus status, String message);
}
diff --git a/src/main/java/com/czertainly/core/service/CertificateService.java b/src/main/java/com/czertainly/core/service/CertificateService.java
index f49ae01dc..3fffc967e 100644
--- a/src/main/java/com/czertainly/core/service/CertificateService.java
+++ b/src/main/java/com/czertainly/core/service/CertificateService.java
@@ -85,7 +85,7 @@ public interface CertificateService extends ResourceExtensionService {
List getSearchableFieldInformationByGroup();
- void bulkDeleteCertificate(SecurityFilter filter, RemoveCertificateDto request) throws NotFoundException;
+ void bulkDeleteCertificate(SecurityFilter filter, RemoveCertificateDto request) throws NotFoundException, NotSupportedException;
/**
* List all locations associated with the certificate
@@ -164,7 +164,7 @@ public interface CertificateService extends ResourceExtensionService {
*
* @param request Request to update multiple objects
*/
- void bulkUpdateCertificateObjects(SecurityFilter filter, MultipleCertificateObjectUpdateDto request) throws NotFoundException;
+ void bulkUpdateCertificateObjects(SecurityFilter filter, MultipleCertificateObjectUpdateDto request) throws NotFoundException, NotSupportedException;
/**
* Function to update status of certificates by scheduled event
diff --git a/src/main/java/com/czertainly/core/service/SearchService.java b/src/main/java/com/czertainly/core/service/SearchService.java
deleted file mode 100644
index 13bd05989..000000000
--- a/src/main/java/com/czertainly/core/service/SearchService.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.czertainly.core.service;
-
-import com.czertainly.api.exception.ValidationException;
-import com.czertainly.api.model.client.certificate.SearchFilterRequestDto;
-import com.czertainly.api.model.client.certificate.SearchRequestDto;
-import com.czertainly.api.model.core.search.DynamicSearchInternalResponse;
-import com.czertainly.api.model.core.search.SearchFieldDataDto;
-import com.czertainly.core.security.authz.SecurityFilter;
-
-import java.util.List;
-
-public interface SearchService {
- Object completeSearchQueryExecutor(List filters, String entity, List originalJson);
- DynamicSearchInternalResponse dynamicSearchQueryExecutor(SearchRequestDto searchRequestDto, String entity, List originalJson, String additionalWhereClause);
-
- Object customQueryExecutor(String sqlQuery);
-
- String getCompleteSearchQuery(List filters, String entity, String joinQuery, List originalJson, Boolean conditionOnly, Boolean nativeCode);
-
- String getQueryDynamicBasedOnFilter(List conditions, String entity, List originalJson, String joinQuery, Boolean conditionOnly, Boolean nativeCode, String additionalWhereClause) throws ValidationException;
-
- String createCriteriaBuilderString(SecurityFilter filter, Boolean addFinisher);
-}
diff --git a/src/main/java/com/czertainly/core/service/impl/AuditLogServiceImpl.java b/src/main/java/com/czertainly/core/service/impl/AuditLogServiceImpl.java
index c100acaea..33307ffa7 100644
--- a/src/main/java/com/czertainly/core/service/impl/AuditLogServiceImpl.java
+++ b/src/main/java/com/czertainly/core/service/impl/AuditLogServiceImpl.java
@@ -9,7 +9,7 @@
import com.czertainly.core.model.auth.ResourceAction;
import com.czertainly.core.security.authz.ExternalAuthorization;
import com.czertainly.core.service.AuditLogService;
-import com.czertainly.core.util.converter.Sql2PredicateConverter;
+import com.czertainly.core.util.FilterPredicatesBuilder;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -166,7 +166,7 @@ public ExportResultDto exportAuditLogs(AuditLogFilter filter, Sort sort) {
@AuditLogged(originator = ObjectType.FE, affected = ObjectType.AUDIT_LOG, operation = OperationType.DELETE)
@ExternalAuthorization(resource = Resource.AUDIT_LOG, action = ResourceAction.DELETE)
public void purgeAuditLogs(AuditLogFilter filter, Sort sort) {
- CriteriaDelete criteriaQueryDataObject = Sql2PredicateConverter.prepareQueryForAuditLog(filter, entityManager.getCriteriaBuilder());
+ CriteriaDelete criteriaQueryDataObject = FilterPredicatesBuilder.prepareQueryForAuditLog(filter, entityManager.getCriteriaBuilder());
entityManager.createQuery(criteriaQueryDataObject).executeUpdate();
}
diff --git a/src/main/java/com/czertainly/core/service/impl/CertificateEventHistoryServiceImpl.java b/src/main/java/com/czertainly/core/service/impl/CertificateEventHistoryServiceImpl.java
index 60f4dd7f9..1ed2461ad 100644
--- a/src/main/java/com/czertainly/core/service/impl/CertificateEventHistoryServiceImpl.java
+++ b/src/main/java/com/czertainly/core/service/impl/CertificateEventHistoryServiceImpl.java
@@ -1,17 +1,14 @@
package com.czertainly.core.service.impl;
import com.czertainly.api.exception.NotFoundException;
-import com.czertainly.api.model.client.certificate.SearchFilterRequestDto;
import com.czertainly.api.model.core.certificate.CertificateEvent;
import com.czertainly.api.model.core.certificate.CertificateEventHistoryDto;
import com.czertainly.api.model.core.certificate.CertificateEventStatus;
-import com.czertainly.api.model.core.search.SearchFieldDataDto;
import com.czertainly.core.dao.entity.Certificate;
import com.czertainly.core.dao.entity.CertificateEventHistory;
import com.czertainly.core.dao.repository.CertificateEventHistoryRepository;
import com.czertainly.core.dao.repository.CertificateRepository;
import com.czertainly.core.service.CertificateEventHistoryService;
-import com.czertainly.core.service.SearchService;
import com.czertainly.core.util.MetaDefinitions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -20,7 +17,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
@@ -36,8 +32,6 @@ public class CertificateEventHistoryServiceImpl implements CertificateEventHisto
private CertificateRepository certificateRepository;
@Autowired
private CertificateEventHistoryRepository certificateEventHistoryRepository;
- @Autowired
- private SearchService searchService;
@Override
public void addEventHistory(UUID certificateUuid, CertificateEvent event, CertificateEventStatus status, String message, HashMap additionalInformation) {
@@ -79,14 +73,5 @@ public void asyncSaveAllInBatch(List certificateEventHi
logger.info("Inserted {} record into the database", certificateEventHistories.size());
}
- @Override
- @Async
- public void addEventHistoryForRequest(List filters, String entity, List originalJson, CertificateEvent event, CertificateEventStatus status, String message) {
- List batchHistoryOperationList = new ArrayList<>();
- for (Certificate certificate : (List) searchService.completeSearchQueryExecutor(filters, "Certificate", originalJson)) {
- batchHistoryOperationList.add(getEventHistory(event, status, message, "", certificate));
- }
- asyncSaveAllInBatch(batchHistoryOperationList);
- }
}
diff --git a/src/main/java/com/czertainly/core/service/impl/CertificateServiceImpl.java b/src/main/java/com/czertainly/core/service/impl/CertificateServiceImpl.java
index 189d3a485..bd38290b3 100644
--- a/src/main/java/com/czertainly/core/service/impl/CertificateServiceImpl.java
+++ b/src/main/java/com/czertainly/core/service/impl/CertificateServiceImpl.java
@@ -33,7 +33,7 @@
import com.czertainly.core.comparator.SearchFieldDataComparator;
import com.czertainly.core.dao.entity.*;
import com.czertainly.core.dao.repository.*;
-import com.czertainly.core.enums.SearchFieldNameEnum;
+import com.czertainly.core.enums.FilterField;
import com.czertainly.core.event.transaction.CertificateValidationEvent;
import com.czertainly.core.messaging.model.NotificationRecipient;
import com.czertainly.core.messaging.producers.EventProducer;
@@ -49,7 +49,6 @@
import com.czertainly.core.service.*;
import com.czertainly.core.service.v2.ExtendedAttributeService;
import com.czertainly.core.util.*;
-import com.czertainly.core.util.converter.Sql2PredicateConverter;
import com.czertainly.core.validation.certificate.ICertificateValidator;
import jakarta.persistence.criteria.*;
import org.apache.commons.lang3.function.TriFunction;
@@ -91,7 +90,9 @@
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
@@ -142,9 +143,6 @@ public class CertificateServiceImpl implements CertificateService {
@Autowired
private CertificateEventHistoryService certificateEventHistoryService;
- @Autowired
- private SearchService searchService;
-
@Lazy
@Autowired
private LocationService locationService;
@@ -374,7 +372,7 @@ private void updateTrustedCaMark(SecuredUUID uuid, Boolean trustedCa) throws Not
@Override
@AuditLogged(originator = ObjectType.FE, affected = ObjectType.CERTIFICATE, operation = OperationType.CHANGE)
@ExternalAuthorization(resource = Resource.CERTIFICATE, action = ResourceAction.UPDATE, parentResource = Resource.RA_PROFILE, parentAction = ResourceAction.DETAIL)
- public void bulkUpdateCertificateObjects(SecurityFilter filter, MultipleCertificateObjectUpdateDto request) throws NotFoundException {
+ public void bulkUpdateCertificateObjects(SecurityFilter filter, MultipleCertificateObjectUpdateDto request) throws NotFoundException, NotSupportedException {
logger.info("Bulk updating certificate objects: RA {} groups {} owner {}", request.getRaProfileUuid(), request.getGroupUuids(), request.getOwnerUuid());
setupSecurityFilter(filter);
if (request.getRaProfileUuid() != null) {
@@ -393,7 +391,7 @@ public void bulkUpdateCertificateObjects(SecurityFilter filter, MultipleCertific
@Async
@ExternalAuthorization(resource = Resource.CERTIFICATE, action = ResourceAction.DELETE, parentResource = Resource.RA_PROFILE, parentAction = ResourceAction.DETAIL)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
- public void bulkDeleteCertificate(SecurityFilter filter, RemoveCertificateDto request) throws NotFoundException {
+ public void bulkDeleteCertificate(SecurityFilter filter, RemoveCertificateDto request) throws NotFoundException, NotSupportedException {
setupSecurityFilter(filter);
UUID loggedUserUuid = null;
@@ -414,61 +412,42 @@ public void bulkDeleteCertificate(SecurityFilter filter, RemoveCertificateDto re
}
logger.debug("Bulk deleted {} of {} certificates.", deletedCount, request.getUuids().size());
} else {
- String joins = "WHERE c.userUuid IS NULL";
- String data = searchService.createCriteriaBuilderString(filter, true);
- if (!data.isEmpty()) {
- joins = joins + " AND " + data;
- }
-
- String customQuery = searchService.getQueryDynamicBasedOnFilter(request.getFilters(), "Certificate", getSearchableFieldInformation(), joins, false, false, "");
-
- List certListDyn = (List) searchService.customQueryExecutor(customQuery);
-
- for (List certificates : partitionList(certListDyn)) {
- certificateRepository.deleteAll(certificates);
- }
- for (List certificateContents : partitionContents(certificateContentRepository.findCertificateContentNotUsed())) {
- certificateContentRepository.deleteAll(certificateContents);
- }
+ throw new NotSupportedException("Bulk delete of certificates by filters is not supported.");
}
}
- @Deprecated
- public List getSearchableFieldInformation() {
- return getSearchableFieldsMap();
- }
@Override
public List getSearchableFieldInformationByGroup() {
final List searchFieldDataByGroupDtos = attributeEngine.getResourceSearchableFields(Resource.CERTIFICATE, false);
List fields = List.of(
- SearchHelper.prepareSearch(SearchFieldNameEnum.COMMON_NAME),
- SearchHelper.prepareSearch(SearchFieldNameEnum.SERIAL_NUMBER_LABEL),
- SearchHelper.prepareSearch(SearchFieldNameEnum.ISSUER_SERIAL_NUMBER),
- SearchHelper.prepareSearch(SearchFieldNameEnum.RA_PROFILE, raProfileRepository.findAll().stream().map(RaProfile::getName).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.GROUP, groupRepository.findAll().stream().map(Group::getName).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.CERT_LOCATION_NAME, locationRepository.findAll().stream().map(Location::getName).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.OWNER, userManagementApiClient.getUsers().getData().stream().map(UserDto::getUsername).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.CERTIFICATE_STATE, Arrays.stream(CertificateState.values()).map(CertificateState::getCode).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.CERTIFICATE_VALIDATION_STATUS, Arrays.stream(CertificateValidationStatus.values()).map(CertificateValidationStatus::getCode).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.COMPLIANCE_STATUS, Arrays.stream(ComplianceStatus.values()).map(ComplianceStatus::getCode).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.ISSUER_COMMON_NAME),
- SearchHelper.prepareSearch(SearchFieldNameEnum.FINGERPRINT),
- SearchHelper.prepareSearch(SearchFieldNameEnum.SIGNATURE_ALGORITHM, new ArrayList<>(certificateRepository.findDistinctSignatureAlgorithm())),
- SearchHelper.prepareSearch(SearchFieldNameEnum.EXPIRES),
- SearchHelper.prepareSearch(SearchFieldNameEnum.NOT_BEFORE),
- SearchHelper.prepareSearch(SearchFieldNameEnum.SUBJECT_DN),
- SearchHelper.prepareSearch(SearchFieldNameEnum.ISSUER_DN),
- SearchHelper.prepareSearch(SearchFieldNameEnum.SUBJECT_ALTERNATIVE),
- SearchHelper.prepareSearch(SearchFieldNameEnum.OCSP_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.CRL_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.SIGNATURE_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()),
- SearchHelper.prepareSearch(SearchFieldNameEnum.PUBLIC_KEY_ALGORITHM, new ArrayList<>(certificateRepository.findDistinctPublicKeyAlgorithm())),
- SearchHelper.prepareSearch(SearchFieldNameEnum.KEY_SIZE, new ArrayList<>(certificateRepository.findDistinctKeySize())),
- SearchHelper.prepareSearch(SearchFieldNameEnum.KEY_USAGE, serializedListOfStringToListOfObject(certificateRepository.findDistinctKeyUsage())),
- SearchHelper.prepareSearch(SearchFieldNameEnum.PRIVATE_KEY),
- SearchHelper.prepareSearch(SearchFieldNameEnum.TRUSTED_CA)
+ SearchHelper.prepareSearch(FilterField.COMMON_NAME),
+ SearchHelper.prepareSearch(FilterField.SERIAL_NUMBER),
+ SearchHelper.prepareSearch(FilterField.ISSUER_SERIAL_NUMBER),
+ SearchHelper.prepareSearch(FilterField.RA_PROFILE_NAME, raProfileRepository.findAll().stream().map(RaProfile::getName).toList()),
+ SearchHelper.prepareSearch(FilterField.GROUP_NAME, groupRepository.findAll().stream().map(Group::getName).toList()),
+ SearchHelper.prepareSearch(FilterField.CERT_LOCATION_NAME, locationRepository.findAll().stream().map(Location::getName).toList()),
+ SearchHelper.prepareSearch(FilterField.OWNER, userManagementApiClient.getUsers().getData().stream().map(UserDto::getUsername).toList()),
+ SearchHelper.prepareSearch(FilterField.CERTIFICATE_STATE, Arrays.stream(CertificateState.values()).map(CertificateState::getCode).toList()),
+ SearchHelper.prepareSearch(FilterField.CERTIFICATE_VALIDATION_STATUS, Arrays.stream(CertificateValidationStatus.values()).map(CertificateValidationStatus::getCode).toList()),
+ SearchHelper.prepareSearch(FilterField.COMPLIANCE_STATUS, Arrays.stream(ComplianceStatus.values()).map(ComplianceStatus::getCode).toList()),
+ SearchHelper.prepareSearch(FilterField.ISSUER_COMMON_NAME),
+ SearchHelper.prepareSearch(FilterField.FINGERPRINT),
+ SearchHelper.prepareSearch(FilterField.SIGNATURE_ALGORITHM, new ArrayList<>(certificateRepository.findDistinctSignatureAlgorithm())),
+ SearchHelper.prepareSearch(FilterField.NOT_AFTER),
+ SearchHelper.prepareSearch(FilterField.NOT_BEFORE),
+ SearchHelper.prepareSearch(FilterField.SUBJECTDN),
+ SearchHelper.prepareSearch(FilterField.ISSUERDN),
+ SearchHelper.prepareSearch(FilterField.SUBJECT_ALTERNATIVE_NAMES),
+ SearchHelper.prepareSearch(FilterField.OCSP_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()),
+ SearchHelper.prepareSearch(FilterField.CRL_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()),
+ SearchHelper.prepareSearch(FilterField.SIGNATURE_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()),
+ SearchHelper.prepareSearch(FilterField.PUBLIC_KEY_ALGORITHM, new ArrayList<>(certificateRepository.findDistinctPublicKeyAlgorithm())),
+ SearchHelper.prepareSearch(FilterField.KEY_SIZE, new ArrayList<>(certificateRepository.findDistinctKeySize())),
+ SearchHelper.prepareSearch(FilterField.KEY_USAGE, serializedListOfStringToListOfObject(certificateRepository.findDistinctKeyUsage())),
+ SearchHelper.prepareSearch(FilterField.PRIVATE_KEY),
+ SearchHelper.prepareSearch(FilterField.TRUSTED_CA)
);
fields = new ArrayList<>(fields);
@@ -1387,34 +1366,6 @@ public List listCmpSigningCertificates(SecurityFilter filter) {
.map(Certificate::mapToListDto).toList();
}
- private String getExpiryTime(Date now, Date expiry) {
- long diffInMilliseconds = expiry.getTime() - now.getTime();
- long difference = TimeUnit.DAYS.convert(diffInMilliseconds, TimeUnit.MILLISECONDS);
- if (diffInMilliseconds <= 0) {
- return "expired";
- } else if (difference < 10) {
- return "10";
- } else if (difference < 20) {
- return "20";
- } else if (difference < 30) {
- return "30";
- } else if (difference < 60) {
- return "60";
- } else if (difference < 90) {
- return "90";
- }
- return "More";
- }
-
-
- @Deprecated
- private List getSearchableFieldsMap() {
-
- final List fields = List.of(SearchHelper.prepareSearch(SearchFieldNameEnum.COMMON_NAME), SearchHelper.prepareSearch(SearchFieldNameEnum.SERIAL_NUMBER_LABEL), SearchHelper.prepareSearch(SearchFieldNameEnum.ISSUER_SERIAL_NUMBER), SearchHelper.prepareSearch(SearchFieldNameEnum.RA_PROFILE, raProfileRepository.findAll().stream().map(RaProfile::getName).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.GROUP, groupRepository.findAll().stream().map(Group::getName).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.OWNER), SearchHelper.prepareSearch(SearchFieldNameEnum.CERTIFICATE_STATE, Arrays.stream(CertificateState.values()).map(CertificateState::getCode).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.CERTIFICATE_VALIDATION_STATUS, Arrays.stream(CertificateValidationStatus.values()).map(CertificateValidationStatus::getCode).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.COMPLIANCE_STATUS, Arrays.stream(ComplianceStatus.values()).map(ComplianceStatus::getCode).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.ISSUER_COMMON_NAME), SearchHelper.prepareSearch(SearchFieldNameEnum.FINGERPRINT), SearchHelper.prepareSearch(SearchFieldNameEnum.SIGNATURE_ALGORITHM, new ArrayList<>(certificateRepository.findDistinctSignatureAlgorithm())), SearchHelper.prepareSearch(SearchFieldNameEnum.EXPIRES), SearchHelper.prepareSearch(SearchFieldNameEnum.NOT_BEFORE), SearchHelper.prepareSearch(SearchFieldNameEnum.SUBJECT_DN), SearchHelper.prepareSearch(SearchFieldNameEnum.ISSUER_DN), SearchHelper.prepareSearch(SearchFieldNameEnum.SUBJECT_ALTERNATIVE), SearchHelper.prepareSearch(SearchFieldNameEnum.OCSP_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.CRL_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.SIGNATURE_VALIDATION, Arrays.stream((CertificateValidationStatus.values())).map(CertificateValidationStatus::getCode).toList()), SearchHelper.prepareSearch(SearchFieldNameEnum.PUBLIC_KEY_ALGORITHM, new ArrayList<>(certificateRepository.findDistinctPublicKeyAlgorithm())), SearchHelper.prepareSearch(SearchFieldNameEnum.KEY_SIZE, new ArrayList<>(certificateRepository.findDistinctKeySize())), SearchHelper.prepareSearch(SearchFieldNameEnum.KEY_USAGE, serializedListOfStringToListOfObject(certificateRepository.findDistinctKeyUsage())));
-
- logger.debug("Searchable Fields: {}", fields);
- return fields;
- }
private List