mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-18 20:47:58 +00:00
Updated code after recognizing an issue with archiving items. This
doesn't include updating the values displayed at the bottom of the list page.
This commit is contained in:
parent
f01b5a2060
commit
cfb30d9a4b
@ -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;
|
||||
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||
@Repository
|
||||
public interface CACredentialRepository extends JpaRepository<CertificateAuthorityCredential, UUID> {
|
||||
|
||||
@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<CertificateAuthorityCredential> findAll();
|
||||
List<CertificateAuthorityCredential> findBySubject(String subject);
|
||||
|
@ -13,6 +13,7 @@ import java.util.UUID;
|
||||
@Repository
|
||||
public interface EndorsementCredentialRepository extends JpaRepository<EndorsementCredential, UUID> {
|
||||
|
||||
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='EndorsementCredential' AND archiveFlag=false", nativeQuery = true)
|
||||
@Override
|
||||
List<EndorsementCredential> findAll();
|
||||
EndorsementCredential findByHolderSerialNumber(BigInteger holderSerialNumber);
|
||||
|
@ -11,7 +11,7 @@ import java.util.UUID;
|
||||
@Repository
|
||||
public interface IssuedCertificateRepository extends JpaRepository<IssuedAttestationCertificate, UUID> {
|
||||
|
||||
@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<IssuedAttestationCertificate> findAll();
|
||||
List<IssuedAttestationCertificate> findByDeviceId(UUID deviceId);
|
||||
|
@ -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<PlatformCredential, UUID> {
|
||||
|
||||
@Query(value = "SELECT * FROM Certificate WHERE DTYPE='PlatformCredential' AND archiveFlag=false", nativeQuery = true)
|
||||
@Override
|
||||
List<PlatformCredential> findAll();
|
||||
List<PlatformCredential> findByDeviceId(UUID deviceId);
|
||||
|
@ -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<ReferenceMani
|
||||
List<SupportReferenceManifest> getSupportByManufacturerModel(String manufacturer, String model);
|
||||
@Query(value = "SELECT * FROM ReferenceManifest WHERE platformModel = ?1 AND DTYPE = 'EventLogMeasurements'", nativeQuery = true)
|
||||
EventLogMeasurements getLogByModel(String model);
|
||||
Page<ReferenceManifest> findByArchiveFlag(boolean archiveFlag, Pageable pageable);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -313,7 +313,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
|
||||
return new DataTableResponse<>(records, input);
|
||||
}
|
||||
|
||||
return new DataTableResponse<Certificate>(new FilteredRecordsList<>(), input);
|
||||
return new DataTableResponse<>(new FilteredRecordsList<>(), input);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -375,7 +375,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
|
||||
|
||||
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<NoPageParams> {
|
||||
|
||||
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<NoPageParams> {
|
||||
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.
|
||||
|
@ -120,15 +120,13 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
FilteredRecordsList<ReferenceManifest> records = new FilteredRecordsList<>();
|
||||
int currentPage = input.getStart() / input.getLength();
|
||||
Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
org.springframework.data.domain.Page<ReferenceManifest> pagedResult = referenceManifestRepository.findAll(paging);
|
||||
org.springframework.data.domain.Page<ReferenceManifest> 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<NoPageParams
|
||||
|
||||
try {
|
||||
ReferenceManifest referenceManifest = getRimFromDb(id);
|
||||
List<ReferenceDigestValue> values = new LinkedList<>();
|
||||
|
||||
if (referenceManifest == null) {
|
||||
String notFoundMessage = "Unable to locate RIM with ID: " + id;
|
||||
@ -228,14 +225,8 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
log.warn(notFoundMessage);
|
||||
} else {
|
||||
// if support rim, update associated events
|
||||
values = referenceDigestValueRepository.findBySupportRimHash(
|
||||
referenceManifest.getHexDecHash());
|
||||
|
||||
for (ReferenceDigestValue value : values) {
|
||||
referenceDigestValueRepository.delete(value);
|
||||
}
|
||||
|
||||
referenceManifestRepository.delete(referenceManifest);
|
||||
referenceManifest.archive();
|
||||
referenceManifestRepository.save(referenceManifest);
|
||||
String deleteCompletedMessage = "RIM successfully deleted";
|
||||
messages.addInfo(deleteCompletedMessage);
|
||||
log.info(deleteCompletedMessage);
|
||||
|
@ -150,7 +150,7 @@ public final class CertificateStringMapBuilder {
|
||||
final Certificate certificate,
|
||||
final CertificateRepository certificateRepository,
|
||||
final CACredentialRepository caCredentialRepository) {
|
||||
List<CertificateAuthorityCredential> issuerCertificates = new ArrayList<>();
|
||||
List<Certificate> issuerCertificates = new ArrayList<>();
|
||||
CertificateAuthorityCredential skiCA = null;
|
||||
String issuerResult;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user