From 963086fc0ed32101a1c11305caf841442627b153 Mon Sep 17 00:00:00 2001 From: TheSilentCoder <184309164+ThatSilentCoder@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:36:04 -0400 Subject: [PATCH] issue_847: Took another look over the PR for this issue and found nothing alarming. Made some minor tweaks to four files. Should be good to go for PR --- .../selector/ReferenceManifestSelector.java | 2 +- .../portal/datatables/DataTableInput.java | 51 +++++-------------- ...eferenceManifestDetailsPageController.java | 20 +++----- .../ValidationReportsPageController.java | 25 +++++---- 4 files changed, 33 insertions(+), 65 deletions(-) diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/selector/ReferenceManifestSelector.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/selector/ReferenceManifestSelector.java index 2a0be756a..876e302cd 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/selector/ReferenceManifestSelector.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/persist/service/selector/ReferenceManifestSelector.java @@ -147,7 +147,7 @@ protected void setFieldValue(final String name, final Object value) { /** * Construct the criterion that can be used to query for rims matching the - * + * configuration of this {@link ReferenceManifestSelector}. + * configuration of this {@link ReferenceManifestSelector}. * * @param criteriaBuilder criteria builder * @return a Criterion that can be used to query for rims matching the diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/datatables/DataTableInput.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/datatables/DataTableInput.java index 9c176eea4..fcfab95c2 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/datatables/DataTableInput.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/datatables/DataTableInput.java @@ -3,10 +3,10 @@ import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotNull; -import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; @@ -18,10 +18,22 @@ /** * Represents a data table input in a jQuery DataTable. */ -@NoArgsConstructor(access = AccessLevel.PUBLIC) +@Getter +@NoArgsConstructor +@ToString public class DataTableInput { private static final int DEFAULT_LENGTH = 10; + /** + * Order parameter. + */ + @NotEmpty + private final List order = new ArrayList<>(); + /** + * Per-column search parameter. + */ + @NotEmpty + private final List columns = new ArrayList<>(); /** * Draw counter. This is used by DataTables to ensure that the Ajax returns from server-side * processing requests are drawn in sequence by DataTables (Ajax requests are asynchronous and @@ -30,7 +42,6 @@ public class DataTableInput { */ @NotNull @Min(0) - @Getter @Setter private int draw = 1; /** @@ -39,7 +50,6 @@ public class DataTableInput { */ @NotNull @Min(0) - @Getter @Setter private int start = 0; /** @@ -51,28 +61,14 @@ public class DataTableInput { */ @NotNull @Min(-1) - @Getter @Setter private int length = DEFAULT_LENGTH; /** * Global search parameter. */ - @Getter @Setter @NotNull private Search search = new Search(); - /** - * Order parameter. - */ - @Getter - @NotEmpty - private List order = new ArrayList<>(); - /** - * Per-column search parameter. - */ - @Getter - @NotEmpty - private List columns = new ArrayList<>(); /** * Constructor. @@ -200,23 +196,4 @@ public String getOrderColumnName() { } return orderColumnName; } - - - /** - * Generates a string for this object. - * - * @return the string - */ - @Override - public String toString() { - return "DataTableInput{" - + "draw=" + draw - + ", start=" + start - + ", length=" + length - + ", search=" + search - + ", order=" + order - + ", columns=" + columns - + '}'; - } } - 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 0f5393fc5..ea440af09 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 @@ -141,16 +141,14 @@ public static HashMap getRimDetailInfo(final UUID uuid, * @param certificateRepository the certificate manager. * @param caCertificateRepository the certificate manager. * @return mapping of the RIM information from the database. - * @throws java.io.IOException error for reading file bytes. - * @throws NoSuchAlgorithmException If an unknown Algorithm is encountered. - * @throws CertificateException if a certificate doesn't parse. + * @throws java.io.IOException error for reading file bytes. */ private static HashMap getBaseRimInfo( final BaseReferenceManifest baseRim, final ReferenceManifestRepository referenceManifestRepository, final CertificateRepository certificateRepository, final CACredentialRepository caCertificateRepository) - throws IOException, CertificateException, NoSuchAlgorithmException { + throws IOException { HashMap data = new HashMap<>(); // Software Identity @@ -260,8 +258,8 @@ private static HashMap getBaseRimInfo( caCertificateRepository)); RIM_VALIDATOR.setTrustStore(truststore); } catch (IOException e) { - log.error("Error building CA chain for " + caCert.getSubjectKeyIdentifier() + ": " - + e.getMessage()); + log.error("Error building CA chain for {}: {}", caCert.getSubjectKeyIdentifier(), + e.getMessage()); } if (RIM_VALIDATOR.validateXmlSignature(caCert.getX509Certificate().getPublicKey(), caCert.getSubjectKeyIdString(), caCert.getEncodedPublicKey())) { @@ -272,7 +270,7 @@ private static HashMap getBaseRimInfo( break; } } catch (SupplyChainValidatorException scvEx) { - log.error("Error verifying cert chain: " + scvEx.getMessage()); + log.error("Error verifying cert chain: {}", scvEx.getMessage()); } } } @@ -288,7 +286,7 @@ private static HashMap getBaseRimInfo( } } } catch (NullPointerException npEx) { - log.warn("Unable to link signing certificate: " + npEx.getMessage()); + log.warn("Unable to link signing certificate: {}", npEx.getMessage()); } return data; } @@ -610,12 +608,6 @@ public ModelAndView initPage(final ReferenceManifestDetailsPageParams params, String uuidError = "Failed to parse ID from: " + params.getId(); messages.addError(uuidError); log.error(uuidError, iaEx); - } catch (CertificateException cEx) { - log.error(cEx); - } catch (NoSuchAlgorithmException nsEx) { - log.error(nsEx); - } catch (IOException ioEx) { - log.error(ioEx); } catch (Exception ex) { log.error(ex); } 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 d158d27fb..ba4fad8e5 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 @@ -28,6 +28,7 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; @@ -115,10 +116,10 @@ public ModelAndView initPage(final NoPageParams params, final Model model) { public DataTableResponse getTableData( final DataTableInput input) { - log.debug("Handling request for summary list: " + input); + log.debug("Handling request for summary list: {}", input); // attempt to get the column property based on the order index. String orderColumnName = input.getOrderColumnName(); - log.debug("Ordering on column: " + orderColumnName); + log.debug("Ordering on column: {}", orderColumnName); FilteredRecordsList records = new FilteredRecordsList<>(); int currentPage = input.getStart() / input.getLength(); @@ -145,8 +146,7 @@ public DataTableResponse getTableData( * @param response object * @throws IOException thrown by BufferedWriter object */ - @SuppressWarnings({"checkstyle:magicnumber", "checkstyle:methodlength"}) - @RequestMapping(value = "download", method = RequestMethod.POST) + @PostMapping(value = "download") public void download(final HttpServletRequest request, final HttpServletResponse response) throws IOException { @@ -158,7 +158,7 @@ public void download(final HttpServletRequest request, DateTimeFormatter dateTimeFormat = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss"); LocalDate startDate = null; LocalDate endDate = null; - ArrayList createTimes = new ArrayList(); + ArrayList createTimes = new ArrayList<>(); String[] deviceNames = new String[] {}; String columnHeaders = ""; boolean systemOnly = false; @@ -171,7 +171,7 @@ public void download(final HttpServletRequest request, while (parameters.hasMoreElements()) { String parameter = (String) parameters.nextElement(); String parameterValue = request.getParameter(parameter); - log.info(parameter + ": " + parameterValue); + log.info("{}: {}", parameter, parameterValue); switch (parameter) { case "company": Matcher companyMatcher = pattern.matcher(parameterValue); @@ -335,7 +335,6 @@ public void download(final HttpServletRequest request, * @param contractNumber contract number. * @return the JSON object in String format. */ - @SuppressWarnings({"checkstyle:magicnumber"}) private JsonObject assembleJsonContent(final PlatformCredential pc, final ArrayList> parsedComponents, final String company, @@ -384,19 +383,19 @@ private JsonObject assembleJsonContent(final PlatformCredential pc, * @return the ArrayList of ArrayLists containing the parsed component data. */ private ArrayList> parseComponents(final PlatformCredential pc) { - ArrayList> parsedComponents = new ArrayList>(); + ArrayList> parsedComponents = new ArrayList<>(); ArrayList> chainComponents = new ArrayList<>(); StringBuilder componentFailureString = new StringBuilder(); if (pc.getComponentIdentifiers() != null - && pc.getComponentIdentifiers().size() > 0) { + && !pc.getComponentIdentifiers().isEmpty()) { componentFailureString.append(pc.getComponentFailures()); // get all the certificates associated with the platform serial List chainCertificates = certificateRepository.byBoardSerialNumber(pc.getPlatformSerial()); // combine all components in each certificate for (ComponentIdentifier ci : pc.getComponentIdentifiers()) { - ArrayList issuerAndComponent = new ArrayList(); + ArrayList issuerAndComponent = new ArrayList<>(); issuerAndComponent.add(pc.getHolderIssuer()); issuerAndComponent.add(ci); chainComponents.add(issuerAndComponent); @@ -406,16 +405,16 @@ private ArrayList> parseComponents(final PlatformCredential pc componentFailureString.append(cert.getComponentFailures()); if (!cert.isPlatformBase()) { for (ComponentIdentifier ci : cert.getComponentIdentifiers()) { - ArrayList issuerAndComponent = new ArrayList(); + ArrayList issuerAndComponent = new ArrayList<>(); issuerAndComponent.add(cert.getHolderIssuer()); issuerAndComponent.add(ci); chainComponents.add(issuerAndComponent); } } } - log.info("Component failures: " + componentFailureString); + log.info("Component failures: {}", componentFailureString); for (ArrayList issuerAndComponent : chainComponents) { - ArrayList componentData = new ArrayList(); + ArrayList componentData = new ArrayList<>(); String issuer = (String) issuerAndComponent.get(0); issuer = issuer.replaceAll(",", " "); ComponentIdentifier ci = (ComponentIdentifier) issuerAndComponent.get(1);