From cfb30d9a4b67a76333682eda7ba6d37cacc71a28 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Mon, 13 Nov 2023 16:56:16 -0500 Subject: [PATCH] Updated code after recognizing an issue with archiving items. This doesn't include updating the values displayed at the bottom of the list page. --- .../persist/entity/ArchivableEntity.java | 7 +++++++ .../manager/CACredentialRepository.java | 2 +- .../EndorsementCredentialRepository.java | 1 + .../manager/IssuedCertificateRepository.java | 2 +- .../PlatformCertificateRepository.java | 2 ++ .../manager/ReferenceManifestRepository.java | 3 +++ .../provision/IdentityClaimProcessor.java | 1 + .../CertificatePageController.java | 21 +++---------------- .../ReferenceManifestPageController.java | 19 +++++------------ .../utils/CertificateStringMapBuilder.java | 2 +- 10 files changed, 25 insertions(+), 35 deletions(-) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/ArchivableEntity.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/ArchivableEntity.java index 6dc75f52..cd87fad3 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/ArchivableEntity.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/ArchivableEntity.java @@ -3,6 +3,7 @@ package hirs.attestationca.persist.entity; import jakarta.persistence.Column; import jakarta.persistence.MappedSuperclass; import lombok.Getter; +import lombok.Setter; import lombok.ToString; import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.type.SqlTypes; @@ -21,6 +22,11 @@ public abstract class ArchivableEntity extends AbstractEntity { */ public static final int MAX_MESSAGE_LENGTH = 2400; + @Getter + @Setter + @Column(nullable = false) + private boolean archiveFlag = false; + @Column(name = "archived_time") private Date archivedTime; @@ -54,6 +60,7 @@ public abstract class ArchivableEntity extends AbstractEntity { * false is archived time is already set, signifying the entity has been archived. */ public final boolean archive() { + this.archiveFlag = !archiveFlag; if (this.archivedTime == null) { this.archivedTime = new Date(); return true; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java index d3f3074f..1cdd9d12 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/CACredentialRepository.java @@ -11,7 +11,7 @@ import java.util.UUID; @Repository public interface CACredentialRepository extends JpaRepository { - @Query(value = "SELECT * FROM Certificate where DTYPE='CertificateAuthorityCredential'", nativeQuery = true) + @Query(value = "SELECT * FROM Certificate WHERE DTYPE='CertificateAuthorityCredential' AND archiveFlag=false", nativeQuery = true) @Override List findAll(); List findBySubject(String subject); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/EndorsementCredentialRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/EndorsementCredentialRepository.java index 3ac197b1..70152cd0 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/EndorsementCredentialRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/EndorsementCredentialRepository.java @@ -13,6 +13,7 @@ import java.util.UUID; @Repository public interface EndorsementCredentialRepository extends JpaRepository { + @Query(value = "SELECT * FROM Certificate WHERE DTYPE='EndorsementCredential' AND archiveFlag=false", nativeQuery = true) @Override List findAll(); EndorsementCredential findByHolderSerialNumber(BigInteger holderSerialNumber); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/IssuedCertificateRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/IssuedCertificateRepository.java index 3acc3cd9..26ac3a44 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/IssuedCertificateRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/IssuedCertificateRepository.java @@ -11,7 +11,7 @@ import java.util.UUID; @Repository public interface IssuedCertificateRepository extends JpaRepository { - @Query(value = "SELECT * FROM Certificate where DTYPE='IssuedAttestationCertificate'", nativeQuery = true) + @Query(value = "SELECT * FROM Certificate WHERE DTYPE='IssuedAttestationCertificate' AND archiveFlag=false", nativeQuery = true) @Override List findAll(); List findByDeviceId(UUID deviceId); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/PlatformCertificateRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/PlatformCertificateRepository.java index 98ade299..4fb1d817 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/PlatformCertificateRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/PlatformCertificateRepository.java @@ -2,6 +2,7 @@ package hirs.attestationca.persist.entity.manager; import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; @@ -10,6 +11,7 @@ import java.util.UUID; @Repository public interface PlatformCertificateRepository extends JpaRepository { + @Query(value = "SELECT * FROM Certificate WHERE DTYPE='PlatformCredential' AND archiveFlag=false", nativeQuery = true) @Override List findAll(); List findByDeviceId(UUID deviceId); diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceManifestRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceManifestRepository.java index 0ab4020e..1d1064d6 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceManifestRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceManifestRepository.java @@ -4,6 +4,8 @@ import hirs.attestationca.persist.entity.userdefined.ReferenceManifest; import hirs.attestationca.persist.entity.userdefined.rim.BaseReferenceManifest; import hirs.attestationca.persist.entity.userdefined.rim.EventLogMeasurements; import hirs.attestationca.persist.entity.userdefined.rim.SupportReferenceManifest; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -41,4 +43,5 @@ public interface ReferenceManifestRepository extends JpaRepository getSupportByManufacturerModel(String manufacturer, String model); @Query(value = "SELECT * FROM ReferenceManifest WHERE platformModel = ?1 AND DTYPE = 'EventLogMeasurements'", nativeQuery = true) EventLogMeasurements getLogByModel(String model); + Page findByArchiveFlag(boolean archiveFlag, Pageable pageable); } diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/provision/IdentityClaimProcessor.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/provision/IdentityClaimProcessor.java index d39f5962..dfa63607 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/provision/IdentityClaimProcessor.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/provision/IdentityClaimProcessor.java @@ -456,6 +456,7 @@ public class IdentityClaimProcessor extends AbstractProcessor { measurements.setPlatformModel(dv.getHw().getProductName()); measurements.setTagId(tagId); measurements.setDeviceName(dv.getNw().getHostname()); + measurements.archive(); this.referenceManifestRepository.save(measurements); diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java index 10d89a46..bfe41eed 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/CertificatePageController.java @@ -313,7 +313,7 @@ public class CertificatePageController extends PageController { return new DataTableResponse<>(records, input); } - return new DataTableResponse(new FilteredRecordsList<>(), input); + return new DataTableResponse<>(new FilteredRecordsList<>(), input); } /** @@ -375,7 +375,7 @@ public class CertificatePageController extends PageController { try { UUID uuid = UUID.fromString(id); - Certificate certificate = getCertificateById(certificateType, uuid); + Certificate certificate = certificateRepository.getReferenceById(uuid); if (certificate == null) { // Use the term "record" here to avoid user confusion b/t cert and cred String notFoundMessage = "Unable to locate record with ID: " + uuid; @@ -392,7 +392,7 @@ public class CertificatePageController extends PageController { for (PlatformCredential pc : sharedCertificates) { if (!pc.isPlatformBase()) { - pc.archive(); + pc.archive("User requested deletion via UI of the base certificate"); certificateRepository.save(pc); } } @@ -748,21 +748,6 @@ public class CertificatePageController extends PageController { return associatedCertificates; } - private Certificate getCertificateById(final String certificateType, final UUID uuid) { - switch (certificateType) { - case PLATFORMCREDENTIAL: - return this.platformCertificateRepository.getReferenceById(uuid); - case ENDORSEMENTCREDENTIAL: - return this.endorsementCredentialRepository.getReferenceById(uuid); - case ISSUEDCERTIFICATES: - return this.issuedCertificateRepository.getReferenceById(uuid); - case TRUSTCHAIN: - return this.caCredentialRepository.getReferenceById(uuid); - default: - return null; - } - } - /** * Parses an uploaded file into a certificate and populates the given model * with error messages if parsing fails. diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java index 4221dbe4..0200ca7f 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestPageController.java @@ -120,15 +120,13 @@ public class ReferenceManifestPageController extends PageController records = new FilteredRecordsList<>(); int currentPage = input.getStart() / input.getLength(); Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); - org.springframework.data.domain.Page pagedResult = referenceManifestRepository.findAll(paging); + org.springframework.data.domain.Page pagedResult = referenceManifestRepository.findByArchiveFlag(false, paging); int rimCount = 0; if (pagedResult.hasContent()) { for (ReferenceManifest manifest : pagedResult.getContent()) { - if (!manifest.getRimType().equals(ReferenceManifest.MEASUREMENT_RIM)) { - records.add(manifest); - rimCount++; - } + records.add(manifest); + rimCount++; } records.setRecordsTotal(rimCount); } else { @@ -220,7 +218,6 @@ public class ReferenceManifestPageController extends PageController values = new LinkedList<>(); if (referenceManifest == null) { String notFoundMessage = "Unable to locate RIM with ID: " + id; @@ -228,14 +225,8 @@ public class ReferenceManifestPageController extends PageController issuerCertificates = new ArrayList<>(); + List issuerCertificates = new ArrayList<>(); CertificateAuthorityCredential skiCA = null; String issuerResult;