Added finally touches to not display archived items. As well display

the correct count that doesn't include the archived items.  Also added
additional exception checks after testing uploading the wrong element to
the wrong /list page
This commit is contained in:
Cyrus 2023-11-14 08:54:08 -05:00
parent cfb30d9a4b
commit 861508c0ef
8 changed files with 31 additions and 29 deletions

View File

@ -60,9 +60,10 @@ public abstract class ArchivableEntity extends AbstractEntity {
* false is archived time is already set, signifying the entity has been archived. * false is archived time is already set, signifying the entity has been archived.
*/ */
public final boolean archive() { public final boolean archive() {
this.archiveFlag = !archiveFlag; this.archiveFlag = false;
if (this.archivedTime == null) { if (this.archivedTime == null) {
this.archivedTime = new Date(); this.archivedTime = new Date();
archiveFlag = true;
return true; return true;
} }
return false; return false;
@ -112,6 +113,7 @@ public abstract class ArchivableEntity extends AbstractEntity {
if (this.archivedTime != null) { if (this.archivedTime != null) {
this.archivedTime = null; this.archivedTime = null;
this.archivedDescription = null; this.archivedDescription = null;
archiveFlag = false;
return true; return true;
} }
return false; return false;

View File

@ -1,8 +1,9 @@
package hirs.attestationca.persist.entity.manager; package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.CertificateAuthorityCredential; import hirs.attestationca.persist.entity.userdefined.certificate.CertificateAuthorityCredential;
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.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -11,9 +12,8 @@ import java.util.UUID;
@Repository @Repository
public interface CACredentialRepository extends JpaRepository<CertificateAuthorityCredential, UUID> { public interface CACredentialRepository extends JpaRepository<CertificateAuthorityCredential, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='CertificateAuthorityCredential' AND archiveFlag=false", nativeQuery = true) List<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag);
@Override Page<CertificateAuthorityCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<CertificateAuthorityCredential> findAll();
List<CertificateAuthorityCredential> findBySubject(String subject); List<CertificateAuthorityCredential> findBySubject(String subject);
List<CertificateAuthorityCredential> findBySubjectSorted(String subject); List<CertificateAuthorityCredential> findBySubjectSorted(String subject);
CertificateAuthorityCredential findBySubjectKeyIdentifier(byte[] subjectKeyIdentifier); CertificateAuthorityCredential findBySubjectKeyIdentifier(byte[] subjectKeyIdentifier);

View File

@ -1,9 +1,9 @@
package hirs.attestationca.persist.entity.manager; package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.EndorsementCredential; import hirs.attestationca.persist.entity.userdefined.certificate.EndorsementCredential;
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential; 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.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.math.BigInteger; import java.math.BigInteger;
@ -13,9 +13,8 @@ import java.util.UUID;
@Repository @Repository
public interface EndorsementCredentialRepository extends JpaRepository<EndorsementCredential, UUID> { public interface EndorsementCredentialRepository extends JpaRepository<EndorsementCredential, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='EndorsementCredential' AND archiveFlag=false", nativeQuery = true) List<EndorsementCredential> findByArchiveFlag(boolean archiveFlag);
@Override Page<EndorsementCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<EndorsementCredential> findAll();
EndorsementCredential findByHolderSerialNumber(BigInteger holderSerialNumber); EndorsementCredential findByHolderSerialNumber(BigInteger holderSerialNumber);
List<EndorsementCredential> findByDeviceId(UUID deviceId); List<EndorsementCredential> findByDeviceId(UUID deviceId);
} }

View File

@ -1,8 +1,9 @@
package hirs.attestationca.persist.entity.manager; package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.IssuedAttestationCertificate; import hirs.attestationca.persist.entity.userdefined.certificate.IssuedAttestationCertificate;
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.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -11,8 +12,7 @@ import java.util.UUID;
@Repository @Repository
public interface IssuedCertificateRepository extends JpaRepository<IssuedAttestationCertificate, UUID> { public interface IssuedCertificateRepository extends JpaRepository<IssuedAttestationCertificate, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='IssuedAttestationCertificate' AND archiveFlag=false", nativeQuery = true) List<IssuedAttestationCertificate> findByArchiveFlag(boolean archiveFlag);
@Override Page<IssuedAttestationCertificate> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<IssuedAttestationCertificate> findAll();
List<IssuedAttestationCertificate> findByDeviceId(UUID deviceId); List<IssuedAttestationCertificate> findByDeviceId(UUID deviceId);
} }

View File

@ -1,8 +1,9 @@
package hirs.attestationca.persist.entity.manager; package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential; import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
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.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
@ -11,8 +12,7 @@ import java.util.UUID;
@Repository @Repository
public interface PlatformCertificateRepository extends JpaRepository<PlatformCredential, UUID> { public interface PlatformCertificateRepository extends JpaRepository<PlatformCredential, UUID> {
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='PlatformCredential' AND archiveFlag=false", nativeQuery = true) List<PlatformCredential> findByArchiveFlag(boolean archiveFlag);
@Override Page<PlatformCredential> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
List<PlatformCredential> findAll();
List<PlatformCredential> findByDeviceId(UUID deviceId); List<PlatformCredential> findByDeviceId(UUID deviceId);
} }

View File

@ -43,5 +43,6 @@ public interface ReferenceManifestRepository extends JpaRepository<ReferenceMani
List<SupportReferenceManifest> getSupportByManufacturerModel(String manufacturer, String model); List<SupportReferenceManifest> getSupportByManufacturerModel(String manufacturer, String model);
@Query(value = "SELECT * FROM ReferenceManifest WHERE platformModel = ?1 AND DTYPE = 'EventLogMeasurements'", nativeQuery = true) @Query(value = "SELECT * FROM ReferenceManifest WHERE platformModel = ?1 AND DTYPE = 'EventLogMeasurements'", nativeQuery = true)
EventLogMeasurements getLogByModel(String model); EventLogMeasurements getLogByModel(String model);
List<ReferenceManifest> findByArchiveFlag(boolean archiveFlag);
Page<ReferenceManifest> findByArchiveFlag(boolean archiveFlag, Pageable pageable); Page<ReferenceManifest> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
} }

View File

@ -235,7 +235,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
// serial number. (pc.HolderSerialNumber = ec.SerialNumber) // serial number. (pc.HolderSerialNumber = ec.SerialNumber)
if (certificateType.equals(PLATFORMCREDENTIAL)) { if (certificateType.equals(PLATFORMCREDENTIAL)) {
FilteredRecordsList<PlatformCredential> records = new FilteredRecordsList<>(); FilteredRecordsList<PlatformCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<PlatformCredential> pagedResult = this.platformCertificateRepository.findAll(paging); org.springframework.data.domain.Page<PlatformCredential> pagedResult = this.platformCertificateRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) { if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent()); records.addAll(pagedResult.getContent());
@ -244,7 +244,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength()); records.setRecordsTotal(input.getLength());
} }
records.setRecordsFiltered(platformCertificateRepository.count()); records.setRecordsFiltered(platformCertificateRepository.findByArchiveFlag(false).size());
EndorsementCredential associatedEC; EndorsementCredential associatedEC;
if (!records.isEmpty()) { if (!records.isEmpty()) {
@ -268,7 +268,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
return new DataTableResponse<>(records, input); return new DataTableResponse<>(records, input);
} else if (certificateType.equals(ENDORSEMENTCREDENTIAL)) { } else if (certificateType.equals(ENDORSEMENTCREDENTIAL)) {
FilteredRecordsList<EndorsementCredential> records = new FilteredRecordsList<>(); FilteredRecordsList<EndorsementCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<EndorsementCredential> pagedResult = this.endorsementCredentialRepository.findAll(paging); org.springframework.data.domain.Page<EndorsementCredential> pagedResult = this.endorsementCredentialRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) { if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent()); records.addAll(pagedResult.getContent());
@ -277,13 +277,13 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength()); records.setRecordsTotal(input.getLength());
} }
records.setRecordsFiltered(endorsementCredentialRepository.count()); records.setRecordsFiltered(endorsementCredentialRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size()); log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input); return new DataTableResponse<>(records, input);
} else if (certificateType.equals(TRUSTCHAIN)) { } else if (certificateType.equals(TRUSTCHAIN)) {
FilteredRecordsList<CertificateAuthorityCredential> records = new FilteredRecordsList<>(); FilteredRecordsList<CertificateAuthorityCredential> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findAll(paging); org.springframework.data.domain.Page<CertificateAuthorityCredential> pagedResult = this.caCredentialRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) { if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent()); records.addAll(pagedResult.getContent());
@ -292,13 +292,13 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength()); records.setRecordsTotal(input.getLength());
} }
records.setRecordsFiltered(caCredentialRepository.count()); records.setRecordsFiltered(caCredentialRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size()); log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input); return new DataTableResponse<>(records, input);
} else if (certificateType.equals(ISSUEDCERTIFICATES)) { } else if (certificateType.equals(ISSUEDCERTIFICATES)) {
FilteredRecordsList<IssuedAttestationCertificate> records = new FilteredRecordsList<>(); FilteredRecordsList<IssuedAttestationCertificate> records = new FilteredRecordsList<>();
org.springframework.data.domain.Page<IssuedAttestationCertificate> pagedResult = this.issuedCertificateRepository.findAll(paging); org.springframework.data.domain.Page<IssuedAttestationCertificate> pagedResult = this.issuedCertificateRepository.findByArchiveFlag(false, paging);
if (pagedResult.hasContent()) { if (pagedResult.hasContent()) {
records.addAll(pagedResult.getContent()); records.addAll(pagedResult.getContent());
@ -307,7 +307,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
records.setRecordsTotal(input.getLength()); records.setRecordsTotal(input.getLength());
} }
records.setRecordsFiltered(issuedCertificateRepository.count()); records.setRecordsFiltered(issuedCertificateRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size()); log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input); return new DataTableResponse<>(records, input);
@ -821,7 +821,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
log.error(failMessage, dEx); log.error(failMessage, dEx);
messages.addError(failMessage + dEx.getMessage()); messages.addError(failMessage + dEx.getMessage());
return null; return null;
} catch (IllegalArgumentException iaEx) { } catch (IllegalArgumentException | IllegalStateException iaEx) {
final String failMessage = String.format( final String failMessage = String.format(
"Certificate format not recognized(%s): ", fileName); "Certificate format not recognized(%s): ", fileName);
log.error(failMessage, iaEx); log.error(failMessage, iaEx);

View File

@ -133,7 +133,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
records.setRecordsTotal(input.getLength()); records.setRecordsTotal(input.getLength());
} }
records.setRecordsFiltered(referenceManifestRepository.count()); records.setRecordsFiltered(referenceManifestRepository.findByArchiveFlag(false).size());
log.debug("Returning list of size: " + records.size()); log.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input); return new DataTableResponse<>(records, input);
@ -413,7 +413,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
baseRims.add(baseRim); baseRims.add(baseRim);
} }
} }
} catch (IOException ioEx) { } catch (IOException | NullPointerException ioEx) {
final String failMessage final String failMessage
= String.format("Failed to parse uploaded file (%s): ", fileName); = String.format("Failed to parse uploaded file (%s): ", fileName);
log.error(failMessage, ioEx); log.error(failMessage, ioEx);