mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-04-20 17:11:04 +00:00
v3_issue_811: Fixed comments, checkstyle issues, can now search on all pages except for validaiton summaries, moved helper method that creates list of searchable column names into utils class.
Some checks failed
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (ubuntu-latest) (push) Has been cancelled
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (windows-2022) (push) Has been cancelled
HIRS Build and Unit Test / ACA_Provisioner_Unit_Tests (push) Has been cancelled
HIRS System Tests / DockerTests (push) Has been cancelled
Dotnet Provisioner Unit Tests / Evaluate Tests (push) Has been cancelled
Some checks failed
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (ubuntu-latest) (push) Has been cancelled
Dotnet Provisioner Unit Tests / Restore and Run Unit Tests (windows-2022) (push) Has been cancelled
HIRS Build and Unit Test / ACA_Provisioner_Unit_Tests (push) Has been cancelled
HIRS System Tests / DockerTests (push) Has been cancelled
Dotnet Provisioner Unit Tests / Evaluate Tests (push) Has been cancelled
This commit is contained in:
parent
d1886751d5
commit
4e8d0d29f9
@ -44,9 +44,9 @@ public class CertificateService {
|
||||
/**
|
||||
* Constructor for the Certificate Service.
|
||||
*
|
||||
* @param certificateRepository certificateRepository
|
||||
* @param componentResultRepository componentResultRepository
|
||||
* @param entityManager entityManager
|
||||
* @param certificateRepository certificate repository
|
||||
* @param componentResultRepository component result repository
|
||||
* @param entityManager entity manager
|
||||
*/
|
||||
@Autowired
|
||||
public CertificateService(final CertificateRepository certificateRepository,
|
||||
@ -208,7 +208,6 @@ public class CertificateService {
|
||||
List<ComponentResult> componentResults = componentResultRepository
|
||||
.findByBoardSerialNumber(existingPlatformCredential
|
||||
.getPlatformSerial());
|
||||
|
||||
for (ComponentResult componentResult : componentResults) {
|
||||
componentResult.restore();
|
||||
componentResult.resetCreateTime();
|
||||
|
@ -3,8 +3,9 @@ package hirs.attestationca.persist.service;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Contains a set of request mapping paths associated with the endpoints for the Certificate Pages.
|
||||
* Each entry in this enum corresponds to a specific URL pattern handled by the controller for managing certificate-related requests.
|
||||
* Contains a set of request mapping paths associated with the Certificate Pages endpoints.
|
||||
* Each entry in this enum corresponds to a specific URL pattern handled by the certificate-related
|
||||
* controller.
|
||||
*/
|
||||
@Getter
|
||||
public enum CertificateType {
|
||||
@ -14,7 +15,8 @@ public enum CertificateType {
|
||||
PLATFORM_CREDENTIALS("platform-credentials"),
|
||||
|
||||
/**
|
||||
* Represents the request mapping path for the endpoints inside the Endorsement Key Credentials Page controller.
|
||||
* Represents the request mapping path for the endpoints inside the
|
||||
* Endorsement Key Credentials Page controller.
|
||||
*/
|
||||
ENDORSEMENT_CREDENTIALS("endorsement-key-credentials"),
|
||||
|
||||
@ -33,9 +35,9 @@ public enum CertificateType {
|
||||
*/
|
||||
TRUST_CHAIN("trust-chain");
|
||||
|
||||
private final String certificateTypePath;
|
||||
private final String certificateRequestPath;
|
||||
|
||||
CertificateType(final String certificateTypePath) {
|
||||
this.certificateTypePath = certificateTypePath;
|
||||
CertificateType(final String certificateRequestPath) {
|
||||
this.certificateRequestPath = certificateRequestPath;
|
||||
}
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ public class DeviceService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of devices combined with the certificates.
|
||||
* Returns the list of devices associated with the platform and endorsement certificates.
|
||||
*
|
||||
* @param deviceList list containing the devices
|
||||
* @return a record list after the device and certificate was mapped together.
|
||||
|
@ -3,12 +3,12 @@ package hirs.attestationca.portal.page.controllers;
|
||||
import hirs.attestationca.persist.FilteredRecordsList;
|
||||
import hirs.attestationca.persist.entity.userdefined.Device;
|
||||
import hirs.attestationca.persist.service.DeviceService;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -25,10 +25,9 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Controller for the Device page.
|
||||
* Controller for the Devices page.
|
||||
*/
|
||||
@Log4j2
|
||||
@Controller
|
||||
@ -50,22 +49,22 @@ public class DevicePageController extends PageController<NoPageParams> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes page.
|
||||
* Returns the path for the view and the data model for the validation reports page.
|
||||
*
|
||||
* @param params The object to map url parameters into.
|
||||
* @param model The data model for the request. Can contain data from
|
||||
* redirect.
|
||||
* @return model and view
|
||||
* @return the path for the view and data model devices page.
|
||||
*/
|
||||
@Override
|
||||
@RequestMapping
|
||||
public ModelAndView initPage(final NoPageParams params, final Model model) {
|
||||
return getBaseModelAndView();
|
||||
return getBaseModelAndView(Page.DEVICES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of devices and device related
|
||||
* information that will be displayed on the devices page.
|
||||
* Processes the request to retrieve a list of devices and device related
|
||||
* information for display on the devices page.
|
||||
*
|
||||
* @param input data table input.
|
||||
* @return data table of devices
|
||||
@ -83,7 +82,8 @@ public class DevicePageController extends PageController<NoPageParams> {
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(Device.class, input.getColumns());
|
||||
|
||||
// get all the devices
|
||||
FilteredRecordsList<Device> deviceList = new FilteredRecordsList<>();
|
||||
@ -112,16 +112,4 @@ public class DevicePageController extends PageController<NoPageParams> {
|
||||
log.info("Returning the size of the list of devices: {}", devicesAndAssociatedCertificates.size());
|
||||
return new DataTableResponse<>(devicesAndAssociatedCertificates, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ import hirs.attestationca.persist.entity.userdefined.Certificate;
|
||||
import hirs.attestationca.persist.entity.userdefined.certificate.EndorsementCredential;
|
||||
import hirs.attestationca.persist.service.CertificateService;
|
||||
import hirs.attestationca.persist.service.CertificateType;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -42,7 +42,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
@ -58,8 +57,8 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
/**
|
||||
* Constructor for the Endorsement Credential page.
|
||||
*
|
||||
* @param endorsementCredentialRepository endorsementCredentialRepository
|
||||
* @param certificateService certificateService
|
||||
* @param endorsementCredentialRepository endorsement credential repository
|
||||
* @param certificateService certificate service
|
||||
*/
|
||||
@Autowired
|
||||
public EndorsementCredentialPageController(
|
||||
@ -85,8 +84,8 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of endorsement credentials that will be
|
||||
* displayed on the endorsement credentials page.
|
||||
* Processes the request to retrieve a list of endorsement credentials for display
|
||||
* on the endorsement credentials page.
|
||||
*
|
||||
* @param input data table input received from the front-end
|
||||
* @return data table of endorsement credentials
|
||||
@ -106,7 +105,9 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(EndorsementCredential.class,
|
||||
input.getColumns());
|
||||
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
@ -135,14 +136,13 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
pagedResult.getTotalElements());
|
||||
ekFilteredRecordsList.setRecordsTotal(findEndorsementCredentialRepositoryCount());
|
||||
|
||||
log.debug("Returning the size of the list of endorsement credentials: {}",
|
||||
log.info("Returning the size of the list of endorsement credentials: {}",
|
||||
ekFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(ekFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the endorsement credential by writing it to the response stream
|
||||
* for download.
|
||||
* Processes the request to download the specified endorsement credential.
|
||||
*
|
||||
* @param id the UUID of the endorsement credential to download
|
||||
* @param response the response object (needed to update the header with the
|
||||
@ -150,14 +150,14 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
* @throws IOException when writing to response output stream
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void downloadSingleEndorsementCredential(
|
||||
public void downloadEndorsementCredential(
|
||||
@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
throws IOException {
|
||||
log.info("Received request to download endorsement credential id {}", id);
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
Certificate certificate = this.certificateService.findCertificate(uuid);
|
||||
|
||||
if (certificate == null) {
|
||||
@ -169,7 +169,6 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
"Unable to cast the found certificate to a endorsement credential object";
|
||||
log.warn(errorMessage);
|
||||
throw new ClassCastException(errorMessage);
|
||||
|
||||
}
|
||||
|
||||
final EndorsementCredential endorsementCredential = (EndorsementCredential) certificate;
|
||||
@ -186,9 +185,9 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
// write endorsement credential to output stream
|
||||
response.getOutputStream().write(certificate.getRawBytes());
|
||||
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to download the"
|
||||
+ " specified endorsement credential", ex);
|
||||
+ " specified endorsement credential", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified endorsement credential
|
||||
@ -197,8 +196,7 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to bulk download all the endorsement credentials by writing it to the response stream
|
||||
* for download in bulk.
|
||||
* Processes the request to bulk download all the endorsement credentials.
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -220,9 +218,9 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
// write endorsement credentials to output stream and bulk download them
|
||||
this.certificateService.bulkDownloadCertificates(zipOut, CertificateType.ENDORSEMENT_CREDENTIALS,
|
||||
singleFileName);
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to bulk download all the"
|
||||
+ "endorsement credentials", ex);
|
||||
+ "endorsement credentials", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// endorsement credentials
|
||||
@ -231,7 +229,7 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to upload one or more endorsement credentials to the ACA.
|
||||
* Processes the request to upload one or more endorsement credentials to the ACA.
|
||||
*
|
||||
* @param files the files to process
|
||||
* @param attr the redirection attributes
|
||||
@ -274,7 +272,7 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to archive/soft delete the provided endorsement credential.
|
||||
* Processes the request to archive/soft delete the specified endorsement credential.
|
||||
*
|
||||
* @param id the UUID of the endorsement certificate to delete
|
||||
* @param attr RedirectAttributes used to forward data back to the original
|
||||
@ -294,7 +292,7 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
List<String> successMessages = new ArrayList<>();
|
||||
List<String> errorMessages = new ArrayList<>();
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
|
||||
this.certificateService.deleteCertificate(uuid, CertificateType.ENDORSEMENT_CREDENTIALS,
|
||||
successMessages, errorMessages);
|
||||
@ -312,18 +310,6 @@ public class EndorsementCredentialPageController extends PageController<NoPagePa
|
||||
return redirectTo(Page.ENDORSEMENT_KEY_CREDENTIALS, new NoPageParams(), model, attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the endorsement credential repository.
|
||||
*
|
||||
|
@ -6,13 +6,13 @@ import hirs.attestationca.persist.entity.userdefined.Certificate;
|
||||
import hirs.attestationca.persist.entity.userdefined.certificate.IDevIDCertificate;
|
||||
import hirs.attestationca.persist.service.CertificateService;
|
||||
import hirs.attestationca.persist.service.CertificateType;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -42,7 +42,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
@ -58,8 +57,8 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
/**
|
||||
* Constructor for the IDevID Certificate page.
|
||||
*
|
||||
* @param iDevIDCertificateRepository iDevIDCertificateRepository
|
||||
* @param certificateService certificateService
|
||||
* @param iDevIDCertificateRepository iDevID certificate repository
|
||||
* @param certificateService certificate service
|
||||
*/
|
||||
@Autowired
|
||||
public IDevIdCertificatePageController(final IDevIDCertificateRepository iDevIDCertificateRepository,
|
||||
@ -84,8 +83,8 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of idevid certificates that will
|
||||
* be displayed on the idevid certificates page.
|
||||
* Processes the request to retrieve a list of idevid certificates for display
|
||||
* on the idevid certificates page.
|
||||
*
|
||||
* @param input data table input received from the front-end
|
||||
* @return data table of idevid certificates
|
||||
@ -105,7 +104,8 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(IDevIDCertificate.class, input.getColumns());
|
||||
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
@ -133,14 +133,13 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
idevidFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
idevidFilteredRecordsList.setRecordsTotal(findIDevIdCertificateRepositoryCount());
|
||||
|
||||
log.info("Returning the size of the list of IDEVID certificates: {}"
|
||||
, idevidFilteredRecordsList.size());
|
||||
log.info("Returning the size of the list of IDEVID certificates: "
|
||||
+ "{}", idevidFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(idevidFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the IDevId certificate by writing it to the response stream
|
||||
* for download.
|
||||
* Processes the request to download the specified IDevId certificate.
|
||||
*
|
||||
* @param id the UUID of the idevid certificate to download
|
||||
* @param response the response object (needed to update the header with the
|
||||
@ -148,14 +147,14 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
* @throws IOException when writing to response output stream
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void downloadSingleIDevIdCertificate(
|
||||
public void downloadIDevIdCertificate(
|
||||
@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
throws IOException {
|
||||
log.info("Received request to download idevid certificate id {}", id);
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
Certificate certificate = this.certificateService.findCertificate(uuid);
|
||||
|
||||
if (certificate == null) {
|
||||
@ -164,7 +163,7 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
throw new EntityNotFoundException(errorMessage);
|
||||
} else if (!(certificate instanceof IDevIDCertificate)) {
|
||||
final String errorMessage =
|
||||
"Unable to cast the found certificate to a idevid certificate object";
|
||||
"Unable to cast the found certificate to an idevid certificate object";
|
||||
log.warn(errorMessage);
|
||||
throw new ClassCastException(errorMessage);
|
||||
|
||||
@ -182,9 +181,9 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
|
||||
// write idevid certificate to output stream
|
||||
response.getOutputStream().write(certificate.getRawBytes());
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to download the"
|
||||
+ " specified idevid certificate", ex);
|
||||
+ " specified idevid certificate", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified idevid certificate
|
||||
@ -193,8 +192,7 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to bulk download all the IDevID Certificates by writing it to the response stream
|
||||
* for download in bulk.
|
||||
* Processes the request to bulk download all the IDevID Certificates.
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -216,18 +214,18 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
// write idevid certificates to output stream and bulk download them
|
||||
this.certificateService.bulkDownloadCertificates(zipOut, CertificateType.IDEVID_CERTIFICATES,
|
||||
singleFileName);
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to bulk download all the"
|
||||
+ "idevid certificates", ex);
|
||||
+ "idevid certificates", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified platform credential
|
||||
// specified idevid certificates
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to upload one or more idevid certificates to the ACA.
|
||||
* Processes the request to upload one or more idevid certificates to the ACA.
|
||||
*
|
||||
* @param files the files to process
|
||||
* @param attr the redirection attributes
|
||||
@ -271,7 +269,7 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to archive/soft delete the provided idevid certificate.
|
||||
* Processes the request to archive/soft delete the provided idevid certificate.
|
||||
*
|
||||
* @param id the UUID of the idevid certificate to delete
|
||||
* @param attr RedirectAttributes used to forward data back to the original
|
||||
@ -292,7 +290,7 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
List<String> errorMessages = new ArrayList<>();
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
|
||||
this.certificateService.deleteCertificate(uuid, CertificateType.IDEVID_CERTIFICATES,
|
||||
successMessages, errorMessages);
|
||||
@ -310,19 +308,6 @@ public class IDevIdCertificatePageController extends PageController<NoPageParams
|
||||
return redirectTo(Page.IDEVID_CERTIFICATES, new NoPageParams(), model, attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the idevid certificate repository.
|
||||
*
|
||||
|
@ -6,13 +6,13 @@ import hirs.attestationca.persist.entity.userdefined.Certificate;
|
||||
import hirs.attestationca.persist.entity.userdefined.certificate.IssuedAttestationCertificate;
|
||||
import hirs.attestationca.persist.service.CertificateService;
|
||||
import hirs.attestationca.persist.service.CertificateType;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -40,7 +40,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
@ -56,8 +55,8 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
/**
|
||||
* Constructor for the Issued Attestation Certificate page.
|
||||
*
|
||||
* @param issuedCertificateRepository issuedCertificateRepository
|
||||
* @param certificateService certificateService
|
||||
* @param issuedCertificateRepository issued certificate repository
|
||||
* @param certificateService certificate service
|
||||
*/
|
||||
@Autowired
|
||||
public IssuedCertificatePageController(
|
||||
@ -83,8 +82,8 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of issued attestation certificates
|
||||
* that will be displayed on the issued certificates page.
|
||||
* Processes the request to retrieve a list of issued attestation certificates
|
||||
* for display on the issued certificates page.
|
||||
*
|
||||
* @param input data table input received from the front-end
|
||||
* @return data table of issued certificates
|
||||
@ -104,7 +103,9 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(IssuedAttestationCertificate.class,
|
||||
input.getColumns());
|
||||
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
@ -132,14 +133,13 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
issuedCertificateFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
issuedCertificateFilteredRecordsList.setRecordsTotal(findIssuedCertificateRepoCount());
|
||||
|
||||
log.info("Returning the size of the list of issued certificates: {}"
|
||||
, issuedCertificateFilteredRecordsList.size());
|
||||
log.info("Returning the size of the list of issued certificates: "
|
||||
+ "{}", issuedCertificateFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(issuedCertificateFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the issued attestation certificate by writing it to the response stream
|
||||
* for download.
|
||||
* Processes the request to download the specified issued attestation certificate.
|
||||
*
|
||||
* @param id the UUID of the issued attestation certificate to download
|
||||
* @param response the response object (needed to update the header with the
|
||||
@ -147,14 +147,14 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
* @throws IOException when writing to response output stream
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void downloadSingleIssuedCertificate(
|
||||
public void downloadIssuedCertificate(
|
||||
@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
throws IOException {
|
||||
log.info("Received request to download issued certificate id {}", id);
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
Certificate certificate = this.certificateService.findCertificate(uuid);
|
||||
|
||||
if (certificate == null) {
|
||||
@ -185,9 +185,9 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
// write issued certificate to output stream
|
||||
response.getOutputStream().write(certificate.getRawBytes());
|
||||
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to download the"
|
||||
+ " specified issued attestation certificate", ex);
|
||||
+ " specified issued attestation certificate", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified issued attestation certificate
|
||||
@ -196,8 +196,7 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to bulk download all the issued attestation certificates by writing it
|
||||
* to the response stream for download in bulk.
|
||||
* Processes the request to bulk download all the issued attestation certificates.
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -219,9 +218,9 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
// write issued attestation certificates to output stream and bulk download them
|
||||
this.certificateService.bulkDownloadCertificates(zipOut, CertificateType.ISSUED_CERTIFICATES,
|
||||
singleFileName);
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to bulk download all the"
|
||||
+ "issued attestation certificates", ex);
|
||||
+ "issued attestation certificates", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// issued attestation certificates
|
||||
@ -230,7 +229,7 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to archive/soft delete the provided issued attestation certificate.
|
||||
* Processes the request to archive/soft delete the specified issued attestation certificate.
|
||||
*
|
||||
* @param id the UUID of the issued attestation certificate to delete
|
||||
* @param attr RedirectAttributes used to forward data back to the original
|
||||
@ -251,7 +250,7 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
List<String> errorMessages = new ArrayList<>();
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
|
||||
this.certificateService.deleteCertificate(uuid, CertificateType.ISSUED_CERTIFICATES,
|
||||
successMessages, errorMessages);
|
||||
@ -269,22 +268,10 @@ public class IssuedCertificatePageController extends PageController<NoPageParams
|
||||
return redirectTo(Page.ISSUED_CERTIFICATES, new NoPageParams(), model, attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the issued certificate repository.
|
||||
*
|
||||
* @return total number of records in the issued certificaterepository.
|
||||
* @return total number of records in the issued certificate repository.
|
||||
*/
|
||||
private long findIssuedCertificateRepoCount() {
|
||||
return this.issuedCertificateRepository.findByArchiveFlag(false).size();
|
||||
|
@ -8,13 +8,13 @@ import hirs.attestationca.persist.entity.userdefined.certificate.EndorsementCred
|
||||
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
|
||||
import hirs.attestationca.persist.service.CertificateService;
|
||||
import hirs.attestationca.persist.service.CertificateType;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -44,7 +44,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
@ -61,9 +60,9 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
/**
|
||||
* Constructor for the Platform Credential page.
|
||||
*
|
||||
* @param platformCertificateRepository platformCertificateRepository
|
||||
* @param endorsementCredentialRepository endorsementCredentialRepository
|
||||
* @param certificateService certificateService
|
||||
* @param platformCertificateRepository platform certificate repository
|
||||
* @param endorsementCredentialRepository endorsement credential repository
|
||||
* @param certificateService certificate service
|
||||
*/
|
||||
@Autowired
|
||||
public PlatformCredentialPageController(
|
||||
@ -91,7 +90,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of platform credentials that will be displayed
|
||||
* Processes the request to retrieve a list of platform credentials for display
|
||||
* on the platform credentials page.
|
||||
*
|
||||
* @param input data table input received from the front-end
|
||||
@ -101,7 +100,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
@GetMapping(value = "/list",
|
||||
produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public DataTableResponse<PlatformCredential> getPlatformCredentialsTableData(
|
||||
final DataTableInput input) {
|
||||
final DataTableInput input) throws Exception {
|
||||
log.info("Received request to display list of platform credentials");
|
||||
log.debug("Request received a datatable input object for the platform credentials page: {}", input);
|
||||
|
||||
@ -111,7 +110,9 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(PlatformCredential.class, input.getColumns());
|
||||
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
@ -162,17 +163,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the platform credential repository.
|
||||
*
|
||||
* @return total number of records in the platform credential repository.
|
||||
*/
|
||||
private long findPlatformCredentialRepositoryCount() {
|
||||
return this.platformCertificateRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the platform credential by writing it to the response stream
|
||||
* for download.
|
||||
* Processes the request to download the selected platform credential.
|
||||
*
|
||||
* @param id the UUID of the platform credential to download
|
||||
* @param response the response object (needed to update the header with the
|
||||
@ -180,14 +171,14 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
* @throws IOException when writing to response output stream
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void downloadSinglePlatformCredential(
|
||||
public void downloadPlatformCredential(
|
||||
@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
throws IOException {
|
||||
log.info("Received request to download platform credential id {}", id);
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
Certificate certificate = this.certificateService.findCertificate(uuid);
|
||||
|
||||
if (certificate == null) {
|
||||
@ -216,9 +207,9 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
// write platform credential to output stream
|
||||
response.getOutputStream().write(certificate.getRawBytes());
|
||||
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to download the"
|
||||
+ " specified platform credential", ex);
|
||||
+ " specified platform credential", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified platform credential
|
||||
@ -227,8 +218,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to bulk download all the platform credentials by writing it to the response stream
|
||||
* for download in bulk.
|
||||
* Processes the request to bulk download all the platform credentials.
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -250,9 +240,9 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
// write platform credentials to output stream and bulk download them
|
||||
this.certificateService.bulkDownloadCertificates(zipOut, CertificateType.PLATFORM_CREDENTIALS,
|
||||
singleFileName);
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to bulk download all the"
|
||||
+ "platform credentials", ex);
|
||||
+ "platform credentials", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
//platform credentials
|
||||
@ -261,7 +251,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to upload one or more platform credentials to the ACA.
|
||||
* Processes the request to upload one or more platform credentials to the ACA.
|
||||
*
|
||||
* @param files the files to process
|
||||
* @param attr the redirection attributes
|
||||
@ -304,7 +294,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to archive/soft delete the provided platform credential.
|
||||
* Processes the request to archive/soft delete the provided platform credential.
|
||||
*
|
||||
* @param id the UUID of the platform credential to delete
|
||||
* @param attr RedirectAttributes used to forward data back to the original
|
||||
@ -325,7 +315,7 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
List<String> errorMessages = new ArrayList<>();
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
|
||||
this.certificateService.deleteCertificate(uuid, CertificateType.PLATFORM_CREDENTIALS,
|
||||
successMessages, errorMessages);
|
||||
@ -344,15 +334,12 @@ public class PlatformCredentialPageController extends PageController<NoPageParam
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
* Retrieves the total number of records in the platform credential repository.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
* @return total number of records in the platform credential repository.
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
private long findPlatformCredentialRepositoryCount() {
|
||||
return this.platformCertificateRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -7,13 +7,13 @@ import hirs.attestationca.persist.entity.userdefined.ReferenceManifest;
|
||||
import hirs.attestationca.persist.entity.userdefined.rim.BaseReferenceManifest;
|
||||
import hirs.attestationca.persist.entity.userdefined.rim.ReferenceDigestValue;
|
||||
import hirs.attestationca.persist.entity.userdefined.rim.SupportReferenceManifest;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import hirs.utils.tpm.eventlog.TCGEventLog;
|
||||
import hirs.utils.tpm.eventlog.TpmPcrEvent;
|
||||
import jakarta.persistence.EntityManager;
|
||||
@ -60,7 +60,6 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@ -82,7 +81,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
* Constructor providing the Page's display and routing specification.
|
||||
*
|
||||
* @param referenceManifestRepository the reference manifest manager
|
||||
* @param referenceDigestValueRepository this is the reference event manager
|
||||
* @param referenceDigestValueRepository reference digest value manager
|
||||
* @param entityManager entity manager
|
||||
*/
|
||||
@Autowired
|
||||
@ -97,21 +96,21 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filePath for the view and the data model for the page.
|
||||
* Returns the filePath for the view and the data model for the Reference Manifest page.
|
||||
*
|
||||
* @param params The object to map url parameters into.
|
||||
* @param model The data model for the request. Can contain data from
|
||||
* redirect.
|
||||
* @return the filePath for the view and data model for the page.
|
||||
* @return the filePath for the view and data model for the Reference Manifest page.
|
||||
*/
|
||||
@Override
|
||||
public ModelAndView initPage(final NoPageParams params,
|
||||
final Model model) {
|
||||
return getBaseModelAndView();
|
||||
return getBaseModelAndView(Page.REFERENCE_MANIFESTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of RIMs that will be displayed on the RIM page.
|
||||
* Processes the request to retrieve a list of RIMs for display on the RIM page.
|
||||
*
|
||||
* @param input data table input
|
||||
* @return data table of RIMs
|
||||
@ -129,7 +128,8 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(ReferenceManifest.class, input.getColumns());
|
||||
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
@ -141,9 +141,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
if (StringUtils.isBlank(searchTerm)) {
|
||||
pagedResult = this.referenceManifestRepository.findByArchiveFlag(false, pageable);
|
||||
} else {
|
||||
pagedResult = findRIMSBySearchableColumnsAndArchiveFlag(searchableColumns
|
||||
, searchTerm,
|
||||
false,
|
||||
pagedResult = findRIMSBySearchableColumnsAndArchiveFlag(searchableColumns, searchTerm, false,
|
||||
pageable);
|
||||
}
|
||||
|
||||
@ -159,16 +157,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the RIM repository.
|
||||
*
|
||||
* @return total number of records in the RIM repository.
|
||||
*/
|
||||
private long findRIMRepoCount() {
|
||||
return this.referenceManifestRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to upload one or more reference manifest(s) to the ACA.
|
||||
* Processes the request to upload one or more reference manifest(s) to the ACA.
|
||||
*
|
||||
* @param files the files to process
|
||||
* @param attr the redirection attributes
|
||||
@ -235,14 +224,12 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
|
||||
//Add messages to the model
|
||||
model.put(MESSAGES_ATTRIBUTE, messages);
|
||||
|
||||
return redirectTo(Page.REFERENCE_MANIFESTS,
|
||||
new NoPageParams(), model, attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the RIM by writing it to the response stream
|
||||
* for download.
|
||||
* Processes the request to download the RIM .
|
||||
*
|
||||
* @param id the UUID of the rim to download
|
||||
* @param response the response object (needed to update the header with the
|
||||
@ -250,13 +237,13 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
* @throws java.io.IOException when writing to response output stream
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void downloadSingleRIM(@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
public void downloadRIM(@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
throws IOException {
|
||||
log.info("Received request to download RIM id {}", id);
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
ReferenceManifest referenceManifest = findSpecifiedRIM(uuid);
|
||||
|
||||
if (referenceManifest == null) {
|
||||
@ -274,9 +261,9 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
// write cert to output stream
|
||||
response.getOutputStream().write(referenceManifest.getRimBytes());
|
||||
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to download the"
|
||||
+ " specified RIM", ex);
|
||||
+ " specified RIM", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified RIM
|
||||
@ -285,8 +272,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to bulk download RIMs by writing it to the response stream
|
||||
* for download in bulk.
|
||||
* Processes the request to bulk download RIMs .
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -317,7 +303,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to archive/soft delete the provided Reference Integrity Manifest.
|
||||
* Processes the request to archive/soft delete the provided Reference Integrity Manifest.
|
||||
*
|
||||
* @param id the UUID of the rim to delete
|
||||
* @param attr RedirectAttributes used to forward data back to the original
|
||||
@ -326,15 +312,15 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
* @throws URISyntaxException if malformed URI
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public RedirectView delete(@RequestParam final String id,
|
||||
final RedirectAttributes attr) throws URISyntaxException {
|
||||
public RedirectView deleteRIM(@RequestParam final String id,
|
||||
final RedirectAttributes attr) throws URISyntaxException {
|
||||
log.info("Received request to delete RIM id {}", id);
|
||||
|
||||
Map<String, Object> model = new HashMap<>();
|
||||
PageMessages messages = new PageMessages();
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
ReferenceManifest referenceManifest = findSpecifiedRIM(uuid);
|
||||
|
||||
if (referenceManifest == null) {
|
||||
@ -411,6 +397,15 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
return new PageImpl<>(resultList, pageable, totalRows);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the RIM repository.
|
||||
*
|
||||
* @return total number of records in the RIM repository.
|
||||
*/
|
||||
private long findRIMRepoCount() {
|
||||
return this.referenceManifestRepository.findByArchiveFlag(false).size();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes the parameter and looks for this information in the
|
||||
* Database.
|
||||
@ -528,18 +523,6 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private Map<String, SupportReferenceManifest> updateSupportRimInfo(
|
||||
final List<SupportReferenceManifest> dbSupportRims) {
|
||||
SupportReferenceManifest supportRim;
|
||||
@ -604,7 +587,7 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
||||
|
||||
private void processTpmEvents(final List<SupportReferenceManifest> dbSupportRims) {
|
||||
List<ReferenceDigestValue> referenceValues;
|
||||
TCGEventLog logProcessor = null;
|
||||
TCGEventLog logProcessor;
|
||||
ReferenceManifest baseRim;
|
||||
ReferenceDigestValue newRdv;
|
||||
|
||||
|
@ -6,12 +6,12 @@ import hirs.attestationca.persist.entity.manager.ReferenceDigestValueRepository;
|
||||
import hirs.attestationca.persist.entity.manager.ReferenceManifestRepository;
|
||||
import hirs.attestationca.persist.entity.userdefined.rim.ReferenceDigestValue;
|
||||
import hirs.attestationca.persist.entity.userdefined.rim.SupportReferenceManifest;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
@ -37,7 +37,6 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Controller for the TPM Events page.
|
||||
@ -69,21 +68,21 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filePath for the view and the data model for the RimDatabase page.
|
||||
* Returns the filePath for the view and the data model for the RIM Database page.
|
||||
*
|
||||
* @param params The object to map url parameters into.
|
||||
* @param model The data model for the request. Can contain data from
|
||||
* redirect.
|
||||
* @return the filePath for the view and data model for the page.
|
||||
* @return the filePath for the view and data model for the RIM Database page.
|
||||
*/
|
||||
@Override
|
||||
public ModelAndView initPage(final NoPageParams params,
|
||||
final Model model) {
|
||||
return getBaseModelAndView();
|
||||
return getBaseModelAndView(Page.RIM_DATABASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of TPM Events that will be displayed
|
||||
* Processes the request to retrieve a list of reference digest values for display
|
||||
* on the rim database page.
|
||||
*
|
||||
* @param input the data tables input
|
||||
@ -102,7 +101,9 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(ReferenceDigestValue.class,
|
||||
input.getColumns());
|
||||
|
||||
FilteredRecordsList<ReferenceDigestValue> referenceDigestValues = new FilteredRecordsList<>();
|
||||
|
||||
@ -143,23 +144,11 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Returning the size of the list of reference digest values: {}"
|
||||
, pagedResult.getTotalElements());
|
||||
log.info("Returning the size of the list of reference digest values: "
|
||||
+ "{}", pagedResult.getTotalElements());
|
||||
return new DataTableResponse<>(referenceDigestValues, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the provided column names, the search term that the user entered and attempts to find
|
||||
* reference digest values whose field values matches the provided search term.
|
||||
@ -189,16 +178,14 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
||||
// Get the attribute type from entity root
|
||||
Path<?> fieldPath = referenceDigestValueRoot.get(columnName);
|
||||
|
||||
// if the field is a string type
|
||||
// if the field is a string type
|
||||
if (String.class.equals(fieldPath.getJavaType())) {
|
||||
Predicate predicate =
|
||||
criteriaBuilder.like(
|
||||
criteriaBuilder.lower(referenceDigestValueRoot.get(columnName)),
|
||||
"%" + searchTerm.toLowerCase() + "%");
|
||||
predicates.add(predicate);
|
||||
}
|
||||
// if the field is a non-string type
|
||||
else if (Integer.class.equals(fieldPath.getJavaType())) {
|
||||
} else if (Integer.class.equals(fieldPath.getJavaType())) {
|
||||
// For Integer fields, use EQUAL if the search term is numeric
|
||||
try {
|
||||
Integer searchInteger = Integer.valueOf(searchTerm); // Will throw if not a number
|
||||
|
@ -8,7 +8,6 @@ import hirs.attestationca.persist.entity.userdefined.certificate.CertificateAuth
|
||||
import hirs.attestationca.persist.service.CertificateService;
|
||||
import hirs.attestationca.persist.service.CertificateType;
|
||||
import hirs.attestationca.persist.util.CredentialHelper;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
@ -16,6 +15,7 @@ import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.PageMessages;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.CertificateStringMapBuilder;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -52,7 +52,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
/**
|
||||
@ -123,7 +122,7 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of trust chain certificates that will be
|
||||
* Processes the request to retrieve a list of trust chain certificates that will be
|
||||
* displayed on the trust chain certificates page.
|
||||
*
|
||||
* @param input data table input received from the front-end
|
||||
@ -144,7 +143,9 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(CertificateAuthorityCredential.class,
|
||||
input.getColumns());
|
||||
|
||||
final int currentPage = input.getStart() / input.getLength();
|
||||
Pageable pageable = PageRequest.of(currentPage, input.getLength(), Sort.by(orderColumnName));
|
||||
@ -173,14 +174,13 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
caFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
caFilteredRecordsList.setRecordsTotal(findTrustChainCertificateRepoCount());
|
||||
|
||||
log.info("Returning the size of the list of trust chain certificates: {}"
|
||||
, caFilteredRecordsList.size());
|
||||
log.info("Returning the size of the list of trust chain certificates: "
|
||||
+ " {}", caFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(caFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the trust chain certificate by writing it to the response stream
|
||||
* for download.
|
||||
* Processes the request to download the selected trust chain certificate.
|
||||
*
|
||||
* @param id the UUID of the trust chain certificate to download
|
||||
* @param response the response object (needed to update the header with the
|
||||
@ -188,14 +188,14 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
* @throws IOException when writing to response output stream
|
||||
*/
|
||||
@GetMapping("/download")
|
||||
public void downloadSingleTrustChainCertificate(
|
||||
public void downloadTrustChainCertificate(
|
||||
@RequestParam final String id,
|
||||
final HttpServletResponse response)
|
||||
throws IOException {
|
||||
log.info("Received request to download trust chain certificate {}", id);
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
Certificate certificate = this.certificateService.findCertificate(uuid);
|
||||
|
||||
if (certificate == null) {
|
||||
@ -226,9 +226,9 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
// write trust chain certificate to output stream
|
||||
response.getOutputStream().write(certificate.getRawBytes());
|
||||
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to download the"
|
||||
+ " specified trust chain certificate", ex);
|
||||
+ " specified trust chain certificate", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// specified trust chain certificate
|
||||
@ -237,8 +237,7 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the ACA cert by writing it to the response
|
||||
* stream for download.
|
||||
* Processes the request to download the ACA trust chain certificate.
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -260,8 +259,7 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to bulk download all the trust chain certificate by writing it to the response stream
|
||||
* for download in bulk.
|
||||
* Processes the request to bulk download all the trust chain certificates.
|
||||
*
|
||||
* @param response the response object (needed to update the header with the
|
||||
* file name)
|
||||
@ -282,9 +280,9 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
// write trust chain certificates to output stream and bulk download them
|
||||
this.certificateService.bulkDownloadCertificates(zipOut, CertificateType.TRUST_CHAIN,
|
||||
singleFileName);
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception exception) {
|
||||
log.error("An exception was thrown while attempting to bulk download all the"
|
||||
+ "trust chain certificates", ex);
|
||||
+ "trust chain certificates", exception);
|
||||
|
||||
// send a 404 error when an exception is thrown while attempting to download the
|
||||
// trust chain certificates
|
||||
@ -293,7 +291,7 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to upload one or more trust chain certificates.
|
||||
* Processes the request to upload one or more trust chain certificates.
|
||||
*
|
||||
* @param files the files to process
|
||||
* @param attr the redirection attributes
|
||||
@ -337,7 +335,7 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to archive/soft delete the provided trust chain certificate.
|
||||
* Processes the request to archive/soft delete the provided trust chain certificate.
|
||||
*
|
||||
* @param id the UUID of the trust chain certificate to delete
|
||||
* @param attr RedirectAttributes used to forward data back to the original
|
||||
@ -358,7 +356,7 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
List<String> errorMessages = new ArrayList<>();
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(id);
|
||||
final UUID uuid = UUID.fromString(id);
|
||||
|
||||
this.certificateService.deleteCertificate(uuid, CertificateType.TRUST_CHAIN,
|
||||
successMessages, errorMessages);
|
||||
@ -376,19 +374,6 @@ public class TrustChainCertificatePageController extends PageController<NoPagePa
|
||||
return redirectTo(Page.TRUST_CHAIN, new NoPageParams(), model, attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the total number of records in the certificate authority (trust chain) repository.
|
||||
*
|
||||
|
@ -4,12 +4,12 @@ import hirs.attestationca.persist.FilteredRecordsList;
|
||||
import hirs.attestationca.persist.entity.manager.SupplyChainValidationSummaryRepository;
|
||||
import hirs.attestationca.persist.entity.userdefined.SupplyChainValidationSummary;
|
||||
import hirs.attestationca.persist.service.ValidationSummaryReportsService;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import hirs.attestationca.portal.datatables.DataTableInput;
|
||||
import hirs.attestationca.portal.datatables.DataTableResponse;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.attestationca.portal.page.utils.ControllerPagesUtils;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
@ -29,7 +29,6 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Controller for the Validation Reports page.
|
||||
@ -58,20 +57,20 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path for the view and the data model for the page.
|
||||
* Returns the path for the view and the data model for the validation reports page.
|
||||
*
|
||||
* @param params The object to map url parameters into.
|
||||
* @param model The data model for the request. Can contain data from redirect.
|
||||
* @return the path for the view and data model for the page.
|
||||
* @return the path for the view and data model validation reports page.
|
||||
*/
|
||||
@Override
|
||||
@RequestMapping
|
||||
public ModelAndView initPage(final NoPageParams params, final Model model) {
|
||||
return getBaseModelAndView();
|
||||
return getBaseModelAndView(Page.VALIDATION_REPORTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to retrieve the collection of supply chain summary records that will be displayed
|
||||
* Processes the request to retrieve a list of supply chain summary records for display
|
||||
* on the validation reports page.
|
||||
*
|
||||
* @param input the data table query.
|
||||
@ -90,7 +89,9 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
||||
log.debug("Ordering on column: {}", orderColumnName);
|
||||
|
||||
final String searchTerm = input.getSearch().getValue();
|
||||
final List<String> searchableColumns = findSearchableColumnsNames(input.getColumns());
|
||||
final List<String> searchableColumns =
|
||||
ControllerPagesUtils.findSearchableColumnsNames(SupplyChainValidationSummary.class,
|
||||
input.getColumns());
|
||||
|
||||
FilteredRecordsList<SupplyChainValidationSummary> reportsFilteredRecordsList =
|
||||
new FilteredRecordsList<>();
|
||||
@ -106,11 +107,12 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
||||
this.supplyChainValidatorSummaryRepository.findByArchiveFlagFalse(pageable);
|
||||
} else {
|
||||
pagedResult =
|
||||
this.validationSummaryReportsService.findValidationReportsBySearchableColumnsAndArchiveFlag(
|
||||
searchableColumns,
|
||||
searchTerm,
|
||||
false,
|
||||
pageable);
|
||||
this.validationSummaryReportsService
|
||||
.findValidationReportsBySearchableColumnsAndArchiveFlag(
|
||||
searchableColumns,
|
||||
searchTerm,
|
||||
false,
|
||||
pageable);
|
||||
}
|
||||
|
||||
if (pagedResult.hasContent()) {
|
||||
@ -120,13 +122,13 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
||||
reportsFilteredRecordsList.setRecordsFiltered(pagedResult.getTotalElements());
|
||||
reportsFilteredRecordsList.setRecordsTotal(this.supplyChainValidatorSummaryRepository.count());
|
||||
|
||||
log.info("Returning the size of the list of validation reports: {}"
|
||||
, reportsFilteredRecordsList.size());
|
||||
log.info("Returning the size of the list of validation reports: "
|
||||
+ "{}", reportsFilteredRecordsList.size());
|
||||
return new DataTableResponse<>(reportsFilteredRecordsList, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes request to download the validation summary report.
|
||||
* Processes the request to download the selected validation summary report.
|
||||
*
|
||||
* @param request http request
|
||||
* @param response http response
|
||||
@ -138,16 +140,4 @@ public class ValidationReportsPageController extends PageController<NoPageParams
|
||||
|
||||
this.validationSummaryReportsService.downloadValidationReports(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a list of column names that are searchable.
|
||||
*
|
||||
* @param columns columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
private List<String> findSearchableColumnsNames(final List<Column> columns) {
|
||||
// Retrieve all searchable columns and collect their names into a list of strings.
|
||||
return columns.stream().filter(Column::isSearchable).map(Column::getName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,100 @@
|
||||
package hirs.attestationca.portal.page.utils;
|
||||
|
||||
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
|
||||
import hirs.attestationca.portal.datatables.Column;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Utility class for the Page Controller classes.
|
||||
*/
|
||||
@Log4j2
|
||||
public final class ControllerPagesUtils {
|
||||
/**
|
||||
* This private constructor was created to silence checkstyle error.
|
||||
*/
|
||||
private ControllerPagesUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that returns a set of the specified class' non-static declared field names.
|
||||
*
|
||||
* @param specifiedClass specified Java class
|
||||
* @return set of non-static declared field names
|
||||
*/
|
||||
public static Set<String> getNonStaticFieldNames(final Class<?> specifiedClass) {
|
||||
|
||||
Set<String> fieldNames = new HashSet<>();
|
||||
Class<?> currentClass = specifiedClass;
|
||||
|
||||
// In order to grab all the specified class' field names,
|
||||
// we will want to "climb the inheritance ladder" and grab the
|
||||
// specified class' super class and its ancestors' field name. We will continue going up the ladder
|
||||
// until there are no more superclasses left.
|
||||
while (currentClass != null) {
|
||||
// grab the current class' non-static declared field names
|
||||
Stream.of(currentClass.getDeclaredFields())
|
||||
.filter(eachField -> !Modifier.isStatic(eachField.getModifiers()))
|
||||
.map(Field::getName)
|
||||
.forEach(fieldNames::add);
|
||||
|
||||
// grab the current class' superclass
|
||||
currentClass = currentClass.getSuperclass();
|
||||
}
|
||||
|
||||
return fieldNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method that attempts to return a list of searchable column names that
|
||||
* matches the names of the provided class' non-static declared fields.
|
||||
*
|
||||
* @param pageControllerClass the controller's entity class
|
||||
* @param columns table columns
|
||||
* @return searchable column names
|
||||
*/
|
||||
public static List<String> findSearchableColumnsNames(
|
||||
final Class<?> pageControllerClass,
|
||||
final List<Column> columns) {
|
||||
|
||||
// grab all the non-static declared fields of the provided class
|
||||
Set<String> nonStaticFields = getNonStaticFieldNames(pageControllerClass);
|
||||
|
||||
// grab the list of column names that are searchable
|
||||
List<String> searchableColumnNames = new ArrayList<>(columns.stream()
|
||||
.filter(Column::isSearchable)
|
||||
.map(Column::getName)
|
||||
.toList());
|
||||
|
||||
List<String> validSearchableColumnNames = new ArrayList<>();
|
||||
|
||||
// since platform chain type is not a column type on the platform credential page,
|
||||
// but it is a field that is represented by the credential type column in the platform credential page
|
||||
// we want to include that as one of the searchable column name
|
||||
if (PlatformCredential.class.isAssignableFrom(pageControllerClass)) {
|
||||
searchableColumnNames.add("platformChainType");
|
||||
}
|
||||
|
||||
// loop through the provided searchable column names and
|
||||
for (String columnName : searchableColumnNames) {
|
||||
// loop through the non-static field names
|
||||
for (String nonStaticField : nonStaticFields) {
|
||||
// if there is a match between the column name and the non-static field
|
||||
if (columnName.equalsIgnoreCase(nonStaticField)) {
|
||||
// add the non-static field name
|
||||
validSearchableColumnNames.add(nonStaticField);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return validSearchableColumnNames;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user