From ca60dcb9e0d6080774f127aca9f31ce1d1c151a2 Mon Sep 17 00:00:00 2001 From: "angelo.andreussi" Date: Wed, 10 Jul 2024 11:57:17 +0200 Subject: [PATCH] feature: introduce base classes for matchTerm feature on certificates --- .../info/CertificateInfoAttributes.java | 9 ++++- .../info/CertificateInfoMatchPredicate.java | 19 +++++++++ .../info/CertificateInfoQuery.java | 10 +++++ .../CertificateInfoMatchPredicateImpl.java | 40 +++++++++++++++++++ .../internal/CertificateInfoQueryImpl.java | 6 +++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java create mode 100644 service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoAttributes.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoAttributes.java index 5957848c611..3f4b23f7ec6 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoAttributes.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoAttributes.java @@ -21,7 +21,6 @@ * @since 1.1.0 */ public class CertificateInfoAttributes extends KapuaNamedEntityAttributes { - public static final String CA_ID = "caId"; public static final String FORWARDABLE = "forwardable"; @@ -34,4 +33,12 @@ public class CertificateInfoAttributes extends KapuaNamedEntityAttributes { public static final String USAGE_NAME = USAGE + ".name"; + public static final String SERIAL = "serial"; + + public static final String ALGORITHM = "algorithm"; + + public static final String SUBJECT = "subject"; + + + } diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java new file mode 100644 index 00000000000..80d1166cb16 --- /dev/null +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoMatchPredicate.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.certificate.info; + +import org.eclipse.kapua.model.query.predicate.MatchPredicate; + +public interface CertificateInfoMatchPredicate extends MatchPredicate { + +} \ No newline at end of file diff --git a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java index e8fc64aca09..1bf1f33dee5 100644 --- a/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java +++ b/service/security/certificate/api/src/main/java/org/eclipse/kapua/service/certificate/info/CertificateInfoQuery.java @@ -51,4 +51,14 @@ public interface CertificateInfoQuery extends KapuaForwardableEntityQuery { * @since 1.1.0 */ void setIncludeInherited(Boolean includeInherited); + + /** + * Instantiates a new {@link CertificateInfoMatchPredicate}. + * + * @param matchTerm The term to use to match. + * @param The type of the term + * @return The newly instantiated {@link CertificateInfoMatchPredicate}. + * @since 2.1.0 + */ + CertificateInfoMatchPredicate matchPredicate(T matchTerm); } diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java new file mode 100644 index 00000000000..4d42434e7a5 --- /dev/null +++ b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoMatchPredicateImpl.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech - initial API and implementation + *******************************************************************************/ +package org.eclipse.kapua.service.certificate.info.internal; + +import org.eclipse.kapua.commons.model.query.predicate.AbstractMatchPredicate; +import org.eclipse.kapua.service.certificate.info.CertificateInfoAttributes; +import org.eclipse.kapua.service.certificate.info.CertificateInfoMatchPredicate; + +import java.util.Arrays; + +public class CertificateInfoMatchPredicateImpl extends AbstractMatchPredicate implements CertificateInfoMatchPredicate { + + /** + * Constructor. + * + * @param matchTerm + * @since 2.1.0 + */ + public CertificateInfoMatchPredicateImpl(T matchTerm) { + this.attributeNames = Arrays.asList( + CertificateInfoAttributes.NAME, + CertificateInfoAttributes.SERIAL, + CertificateInfoAttributes.SIGNATURE, + CertificateInfoAttributes.ALGORITHM, + CertificateInfoAttributes.SUBJECT + ); + this.matchTerm = matchTerm; + } + +} diff --git a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java index fbc765ed32c..3c64874d30f 100644 --- a/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java +++ b/service/security/certificate/internal/src/main/java/org/eclipse/kapua/service/certificate/info/internal/CertificateInfoQueryImpl.java @@ -14,6 +14,7 @@ import org.eclipse.kapua.commons.model.query.AbstractKapuaNamedQuery; import org.eclipse.kapua.model.id.KapuaId; +import org.eclipse.kapua.service.certificate.info.CertificateInfoMatchPredicate; import org.eclipse.kapua.service.certificate.info.CertificateInfoQuery; /** @@ -54,4 +55,9 @@ public Boolean getIncludeInherited() { public void setIncludeInherited(Boolean includeInherited) { this.includeInherited = includeInherited; } + + @Override + public CertificateInfoMatchPredicate matchPredicate(T matchTerm) { + return new CertificateInfoMatchPredicateImpl<>(matchTerm); + } }