From 751a8104fc4f46f94ef4063b64727a94bc1fabb6 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Fri, 4 Aug 2023 10:13:25 -0400 Subject: [PATCH 1/2] Updated all page controllers that were causing an issue to display content based on the page allocations. --- .../ReferenceDigestValueRepository.java | 1 - .../DeviceAssociatedCertificate.java | 4 +++ .../CertificatePageController.java | 19 ++++++++++-- .../controllers/DevicePageController.java | 27 +++++++++++----- ...eferenceManifestDetailsPageController.java | 2 +- .../ReferenceManifestPageController.java | 24 +++++++++++--- .../RimDatabasePageController.java | 7 +++-- .../ValidationReportsPageController.java | 31 ++++++++++--------- .../jsp/endorsement-key-credentials.jsp | 4 +-- .../WEB-INF/jsp/issued-certificates.jsp | 4 +-- .../WEB-INF/jsp/platform-credentials.jsp | 4 +-- .../java/hirs/utils/BouncyCastleUtils.java | 2 +- 12 files changed, 87 insertions(+), 42 deletions(-) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceDigestValueRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceDigestValueRepository.java index 87632ce1..d1fae962 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceDigestValueRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/manager/ReferenceDigestValueRepository.java @@ -17,7 +17,6 @@ public interface ReferenceDigestValueRepository extends JpaRepository findByManufacturer(String manufacturer); @Query(value = "SELECT * FROM ReferenceDigestValue WHERE baseRimId = '?1' OR supportRimId = '?1'", nativeQuery = true) List getValuesByRimId(UUID associatedRimId); - @Query(value = "SELECT * FROM ReferenceDigestValue WHERE supportRimId = '?1'", nativeQuery = true) List findBySupportRimId(UUID supportRimId); List findBySupportRimHash(String supportRimHash); } diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/DeviceAssociatedCertificate.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/DeviceAssociatedCertificate.java index 924c4abc..e0f54321 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/DeviceAssociatedCertificate.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/entity/userdefined/certificate/DeviceAssociatedCertificate.java @@ -28,6 +28,10 @@ public abstract class DeviceAssociatedCertificate extends Certificate { @JdbcTypeCode(java.sql.Types.VARCHAR) @Column private UUID deviceId; + @Getter + @Setter + @Column + private String deviceName; /** * Holds the name of the entity 'DEVICE_ID' field. 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 94a01748..f50d7c64 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 @@ -31,6 +31,9 @@ import lombok.extern.log4j.Log4j2; import org.bouncycastle.util.encoders.DecoderException; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -226,13 +229,23 @@ public class CertificatePageController extends PageController { * tell it what the type T is. */ FilteredRecordsList records = new FilteredRecordsList<>(); + int currentPage = input.getStart() / input.getLength(); + Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); + // special parsing for platform credential // Add the EndorsementCredential for each PlatformCredential based on the // serial number. (pc.HolderSerialNumber = ec.SerialNumber) if (certificateType.equals(PLATFORMCREDENTIAL)) { - records = OrderedListQueryDataTableAdapter.getOrderedList( - getCertificateClass(certificateType), platformCertificateRepository, - input, orderColumnName, criteriaModifier); +// records = OrderedListQueryDataTableAdapter.getOrderedList( +// getCertificateClass(certificateType), platformCertificateRepository, +// input, orderColumnName, criteriaModifier); + + org.springframework.data.domain.Page pagedResult = this.platformCertificateRepository.findAll(paging); + if (pagedResult.hasContent()) { + records.addAll(pagedResult.getContent()); + } + records.setRecordsFiltered(input.getLength()); + records.setRecordsTotal(platformCertificateRepository.count()); EndorsementCredential associatedEC; if (!records.isEmpty()) { diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/DevicePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/DevicePageController.java index 3df1e90b..b596e788 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/DevicePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/DevicePageController.java @@ -20,6 +20,9 @@ import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.params.NoPageParams; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -80,16 +83,26 @@ public class DevicePageController extends PageController { log.info("Ordering on column: " + orderColumnName); // get all the devices - FilteredRecordsList deviceList = - OrderedListQueryDataTableAdapter.getOrderedList( - Device.class, - deviceRepository, - input, orderColumnName); + FilteredRecordsList deviceList = new FilteredRecordsList<>(); +// OrderedListQueryDataTableAdapter.getOrderedList( +// Device.class, +// deviceRepository, +// input, orderColumnName); - FilteredRecordsList> record + int currentPage = input.getStart() / input.getLength(); + Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); + org.springframework.data.domain.Page pagedResult = deviceRepository.findAll(paging); + + if (pagedResult.hasContent()) { + deviceList.addAll(pagedResult.getContent()); + } + deviceList.setRecordsTotal(input.getLength()); + deviceList.setRecordsFiltered(deviceRepository.count()); + + FilteredRecordsList> records = retrieveDevicesAndAssociatedCertificates(deviceList); - return new DataTableResponse<>(record, input); + return new DataTableResponse<>(records, input); } /** diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java index 37bf6ac3..a2ee5373 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java @@ -312,7 +312,7 @@ public class ReferenceManifestDetailsPageController extends PageController records - = OrderedListQueryDataTableAdapter.getOrderedList( - ReferenceManifest.class, - this.referenceManifestRepository, - input, orderColumnName, criteriaModifier); + + FilteredRecordsList 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); + + if (pagedResult.hasContent()) { + records.addAll(pagedResult.getContent()); + } + records.setRecordsTotal(input.getLength()); + records.setRecordsFiltered(referenceManifestRepository.count()); +// FilteredRecordsList records +// = OrderedListQueryDataTableAdapter.getOrderedList( +// ReferenceManifest.class, +// this.referenceManifestRepository, +// input, orderColumnName, criteriaModifier); log.debug("Returning list of size: " + records.size()); return new DataTableResponse<>(records, input); diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java index b27f7b05..253576c6 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java @@ -108,15 +108,16 @@ public class RimDatabasePageController extends PageController { log.info("Querying with the following datatableinput: " + input.toString()); FilteredRecordsList referenceDigestValues = new FilteredRecordsList<>(); - Pageable paging = PageRequest.of(input.getStart(), input.getLength(), Sort.by(orderColumnName)); + int currentPage = input.getStart() / input.getLength(); + Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); org.springframework.data.domain.Page pagedResult = referenceDigestValueRepository.findAll(paging); if (pagedResult.hasContent()) { referenceDigestValues.addAll(pagedResult.getContent()); } - referenceDigestValues.setRecordsTotal(referenceDigestValueRepository.count()); - referenceDigestValues.setRecordsFiltered(input.getLength()); + referenceDigestValues.setRecordsTotal(input.getLength()); + referenceDigestValues.setRecordsFiltered(referenceDigestValueRepository.count()); // FilteredRecordsList referenceDigestValues = // OrderedListQueryDataTableAdapter.getOrderedList( diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index 24d4b788..f010941e 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -121,23 +121,13 @@ public class ValidationReportsPageController extends PageController records = - OrderedListQueryDataTableAdapter.getOrderedList( - SupplyChainValidationSummary.class, - supplyChainValidatorSummaryRepository, input, orderColumnName, - criteriaModifier); + FilteredRecordsList 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 = supplyChainValidatorSummaryRepository.findAll(paging); + + if (pagedResult.hasContent()) { + records.addAll(pagedResult.getContent()); + } + records.setRecordsTotal(input.getLength()); + records.setRecordsFiltered(supplyChainValidatorSummaryRepository.count()); + +// FilteredRecordsList records = +// OrderedListQueryDataTableAdapter.getOrderedList( +// SupplyChainValidationSummary.class, +// supplyChainValidatorSummaryRepository, input, orderColumnName, +// criteriaModifier); return new DataTableResponse<>(records, input); } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/endorsement-key-credentials.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/endorsement-key-credentials.jsp index 5e40dce6..75706028 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/endorsement-key-credentials.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/endorsement-key-credentials.jsp @@ -49,14 +49,14 @@ var url = pagePath +'/list'; var columns = [ { - data: 'device.name', + data: 'deviceName', render: function (data, type, full, meta) { // if there's a device, display its name, otherwise // display nothing if (full.device) { // TODO render a link to a device details page, // passing the device.id - return full.device.name; + return full.deviceName; } return ''; } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp index bd8052e2..0ed637bb 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/issued-certificates.jsp @@ -44,14 +44,14 @@ var url = pagePath + '/list'; var columns = [ { - data: 'device.name', + data: 'deviceName', render: function (data, type, full, meta) { // if there's a device, display its name, otherwise // display nothing if (full.device) { // TODO render a link to a device details page, // passing the device.id - return full.device.name; + return full.deviceName; } return ''; } diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp index 59e11c61..defb07e1 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/platform-credentials.jsp @@ -54,14 +54,14 @@ var url = pagePath +'/list'; var columns = [ { - data: 'device.name', + data: 'deviceName', render: function (data, type, full, meta) { // if there's a device, display its name, otherwise // display nothing if (full.device) { // TODO render a link to a device details page, // passing the device.id - return full.device.name; + return full.deviceName; } return ''; } diff --git a/HIRS_Utils/src/main/java/hirs/utils/BouncyCastleUtils.java b/HIRS_Utils/src/main/java/hirs/utils/BouncyCastleUtils.java index d04cd993..3c748284 100644 --- a/HIRS_Utils/src/main/java/hirs/utils/BouncyCastleUtils.java +++ b/HIRS_Utils/src/main/java/hirs/utils/BouncyCastleUtils.java @@ -27,7 +27,7 @@ public final class BouncyCastleUtils { */ public static boolean x500NameCompare(final String nameValue1, final String nameValue2) { if (nameValue1 == null || nameValue2 == null) { - log.error("Provided DN string is null."); + log.warn("Provided DN string is null."); return true; } From 46ecbe6b269a0ac79591370ce262a71f45afbb41 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Mon, 7 Aug 2023 06:23:41 -0400 Subject: [PATCH 2/2] Resolved the issue with the Certificate page not paging. I had the setters flipped. --- .../CertificatePageController.java | 65 +++++++++++++------ .../ReferenceManifestPageController.java | 2 + .../RimDatabasePageController.java | 4 +- .../ValidationReportsPageController.java | 3 + 4 files changed, 54 insertions(+), 20 deletions(-) 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 f50d7c64..674d6c7f 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 @@ -61,9 +61,6 @@ import java.util.UUID; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -//import java.security.cert.CertificateEncodingException; -//import java.security.cert.X509Certificate; - // note uploading base64 certs, old or new having decode issues check ACA channel /** @@ -223,12 +220,6 @@ public class CertificatePageController extends PageController { } }; - - /** - * Ok I think what I will do is make repositories for each certificate type to I can - * tell it what the type T is. - */ - FilteredRecordsList records = new FilteredRecordsList<>(); int currentPage = input.getStart() / input.getLength(); Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); @@ -239,13 +230,14 @@ public class CertificatePageController extends PageController { // records = OrderedListQueryDataTableAdapter.getOrderedList( // getCertificateClass(certificateType), platformCertificateRepository, // input, orderColumnName, criteriaModifier); + FilteredRecordsList records = new FilteredRecordsList<>(); org.springframework.data.domain.Page pagedResult = this.platformCertificateRepository.findAll(paging); if (pagedResult.hasContent()) { records.addAll(pagedResult.getContent()); } - records.setRecordsFiltered(input.getLength()); - records.setRecordsTotal(platformCertificateRepository.count()); + records.setRecordsTotal(input.getLength()); + records.setRecordsFiltered(platformCertificateRepository.count()); EndorsementCredential associatedEC; if (!records.isEmpty()) { @@ -264,18 +256,53 @@ public class CertificatePageController extends PageController { pc.setEndorsementCredential(associatedEC); } } + + log.debug("Returning list of size: " + records.size()); + return new DataTableResponse<>(records, input); } else if (certificateType.equals(ENDORSEMENTCREDENTIAL)) { - records = OrderedListQueryDataTableAdapter.getOrderedList( - getCertificateClass(certificateType), endorsementCredentialRepository, - input, orderColumnName, criteriaModifier); +// records = OrderedListQueryDataTableAdapter.getOrderedList( +// getCertificateClass(certificateType), endorsementCredentialRepository, +// input, orderColumnName, criteriaModifier); + FilteredRecordsList records = new FilteredRecordsList<>(); + org.springframework.data.domain.Page pagedResult = this.endorsementCredentialRepository.findAll(paging); + if (pagedResult.hasContent()) { + records.addAll(pagedResult.getContent()); + } + + records.setRecordsTotal(input.getLength()); + records.setRecordsFiltered(endorsementCredentialRepository.count()); + + log.debug("Returning list of size: " + records.size()); + return new DataTableResponse<>(records, input); } else if (certificateType.equals(TRUSTCHAIN)) { - records = OrderedListQueryDataTableAdapter.getOrderedList( - getCertificateClass(certificateType), caCredentialRepository, - input, orderColumnName, criteriaModifier); +// records = OrderedListQueryDataTableAdapter.getOrderedList( +// getCertificateClass(certificateType), caCredentialRepository, +// input, orderColumnName, criteriaModifier); + FilteredRecordsList records = new FilteredRecordsList<>(); + org.springframework.data.domain.Page pagedResult = this.caCredentialRepository.findAll(paging); + + if (pagedResult.hasContent()) { + records.addAll(pagedResult.getContent()); + } + records.setRecordsTotal(input.getLength()); + records.setRecordsFiltered(caCredentialRepository.count()); + + log.debug("Returning list of size: " + records.size()); + return new DataTableResponse<>(records, input); + } else if (certificateType.equals(ISSUEDCERTIFICATES)) { + FilteredRecordsList records = new FilteredRecordsList<>(); + org.springframework.data.domain.Page pagedResult = this.issuedCertificateRepository.findAll(paging); + if (pagedResult.hasContent()) { + records.addAll(pagedResult.getContent()); + } + records.setRecordsTotal(input.getLength()); + records.setRecordsFiltered(issuedCertificateRepository.count()); + + log.debug("Returning list of size: " + records.size()); + return new DataTableResponse<>(records, input); } - log.debug("Returning list of size: " + records.size()); - return new DataTableResponse<>(records, input); + return new DataTableResponse(new FilteredRecordsList<>(), input); } /** 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 69cb3c49..4bfdde19 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 @@ -136,6 +136,8 @@ public class ReferenceManifestPageController extends PageController records = new FilteredRecordsList<>(); int currentPage = input.getStart() / input.getLength(); Pageable paging = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName)); diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java index 253576c6..b7aef697 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/RimDatabasePageController.java @@ -106,7 +106,8 @@ public class RimDatabasePageController extends PageController { } }; - log.info("Querying with the following datatableinput: " + input.toString()); + log.info("Querying with the following dataTableInput: " + input.toString()); + FilteredRecordsList referenceDigestValues = new FilteredRecordsList<>(); int currentPage = input.getStart() / input.getLength(); @@ -141,6 +142,7 @@ public class RimDatabasePageController extends PageController { } } + log.debug("Returning list of size: " + referenceDigestValues.size()); return new DataTableResponse<>(referenceDigestValues, input); } } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java index f010941e..9106180f 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ValidationReportsPageController.java @@ -29,6 +29,9 @@ import jakarta.servlet.http.HttpServletResponse; import lombok.extern.log4j.Log4j2; import org.hibernate.Session; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model;