Further updates to reference digest controller and the persistence

configuration which now includes updated refactoring for entity manager
This commit is contained in:
Cyrus 2022-08-03 12:17:55 -04:00
parent 56b77ab360
commit 9221befdf0
13 changed files with 141 additions and 184 deletions

View File

@ -1,31 +1,25 @@
package hirs.attestationca.configuration; package hirs.attestationca.configuration;
import hirs.attestationca.AttestationCertificateAuthorityConfiguration; import hirs.attestationca.service.CertificateServiceImpl;
import hirs.attestationca.servicemanager.DBCertificateManager; import hirs.attestationca.service.DbServiceImpl;
import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.attestationca.service.DeviceServiceImpl;
import hirs.attestationca.service.PolicyServiceImpl;
import hirs.attestationca.service.ReferenceDigestValueServiceImpl;
import hirs.attestationca.service.ReferenceManifestServiceImpl;
import hirs.attestationca.servicemanager.DBManager; import hirs.attestationca.servicemanager.DBManager;
import hirs.attestationca.servicemanager.DBPolicyManager;
import hirs.attestationca.servicemanager.DBPortalInfoManager; import hirs.attestationca.servicemanager.DBPortalInfoManager;
import hirs.attestationca.servicemanager.DBReferenceEventManager;
import hirs.attestationca.servicemanager.DBReferenceManifestManager;
import hirs.attestationca.servicemanager.DBReportManager;
import hirs.attestationca.servicemanager.DBReportRequestStateManager;
import hirs.attestationca.servicemanager.DBReportSummaryManager;
import hirs.data.persist.SupplyChainValidationSummary; import hirs.data.persist.SupplyChainValidationSummary;
import hirs.persist.CertificateManager;
import hirs.persist.CrudManager; import hirs.persist.CrudManager;
import hirs.persist.DeviceManager;
import hirs.persist.PolicyManager;
import hirs.persist.PortalInfoManager; import hirs.persist.PortalInfoManager;
import hirs.persist.ReferenceEventManager; import hirs.persist.service.CertificateService;
import hirs.persist.ReferenceManifestManager; import hirs.persist.service.DeviceService;
import hirs.persist.ReportManager; import hirs.persist.service.PolicyService;
import hirs.persist.ReportRequestStateManager; import hirs.persist.service.ReferenceDigestValueService;
import hirs.persist.ReportSummaryManager; import hirs.persist.service.ReferenceManifestService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
@ -39,7 +33,7 @@ import javax.persistence.PersistenceContext;
* file, the default persistence file will be used instead. * file, the default persistence file will be used instead.
*/ */
@Configuration @Configuration
@Import(AttestationCertificateAuthorityConfiguration.class) @EnableJpaRepositories("hirs.attestationca.service")
public class PersistenceConfiguration { public class PersistenceConfiguration {
/** /**
@ -60,115 +54,78 @@ public class PersistenceConfiguration {
private int maxTransactionRetryAttempts; private int maxTransactionRetryAttempts;
/** /**
* Creates a {@link hirs.persist.PolicyManager} ready to use. * Creates a {@link hirs.persist.service.PolicyService} ready to use.
* *
* @return {@link hirs.persist.PolicyManager} * @return {@link hirs.persist.service.PolicyService}
*/ */
@Bean @Bean
public PolicyManager policyManager() { public PolicyService policyService() {
DBPolicyManager manager = new DBPolicyManager(entityManager); PolicyServiceImpl serviceImpl = new PolicyServiceImpl(entityManager);
setDbManagerRetrySettings(manager); setDbServiceRetrySettings(serviceImpl);
return manager; return serviceImpl;
} }
/** /**
* Creates a {@link hirs.persist.ReportManager} ready to use. * Creates a {@link hirs.persist.service.DeviceService} ready to use.
* *
* @return {@link hirs.persist.ReportManager} * @return {@link hirs.persist.service.DeviceService}
*/ */
@Bean @Bean
public ReportManager reportManager() { public DeviceService deviceService() {
DBReportManager manager = new DBReportManager(entityManager); DeviceServiceImpl serviceImpl = new DeviceServiceImpl(entityManager);
setDbManagerRetrySettings(manager); setDbServiceRetrySettings(serviceImpl);
return manager; return serviceImpl;
} }
/** /**
* Creates a {@link hirs.persist.DeviceManager} ready to use. * Creates a {@link hirs.persist.service.CertificateService} ready to use.
* *
* @return {@link hirs.persist.DeviceManager} * @return {@link hirs.persist.service.CertificateService}
*/ */
@Bean @Bean
public DeviceManager deviceManager() { public CertificateService certificateService() {
DBDeviceManager manager = new DBDeviceManager(entityManager); CertificateServiceImpl serviceImpl = new CertificateServiceImpl(entityManager);
setDbManagerRetrySettings(manager); setDbServiceRetrySettings(serviceImpl);
return manager; return serviceImpl;
} }
/** /**
* Creates a {@link hirs.persist.ReportSummaryManager} ready to use. * Creates a {@link hirs.persist.service.ReferenceManifestService} ready to use.
* *
* @return {@link hirs.persist.ReportSummaryManager} * @return {@link hirs.persist.service.ReferenceManifestService}
*/ */
@Bean @Bean
public ReportSummaryManager reportSummaryManager() { public ReferenceManifestService referenceManifestService() {
DBReportSummaryManager manager = new DBReportSummaryManager(entityManager); ReferenceManifestServiceImpl serviceImpl
setDbManagerRetrySettings(manager); = new ReferenceManifestServiceImpl(entityManager);
return manager; setDbServiceRetrySettings(serviceImpl);
return serviceImpl;
} }
/** /**
* Creates a {@link hirs.persist.CertificateManager} ready to use. * Creates a {@link hirs.persist.service.ReferenceDigestValueService} ready to use.
* *
* @return {@link hirs.persist.CertificateManager} * @return {@link hirs.persist.service.ReferenceDigestValueService}
*/ */
@Bean @Bean
public CertificateManager certificateManager() { public ReferenceDigestValueService referenceEventService() {
DBCertificateManager manager = new DBCertificateManager(entityManager); ReferenceDigestValueServiceImpl serviceImpl
manager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds); = new ReferenceDigestValueServiceImpl(entityManager);
return manager; setDbServiceRetrySettings(serviceImpl);
return serviceImpl;
} }
/** // /**
* Creates a {@link hirs.persist.ReferenceManifestManager} ready to use. // * Creates a {@link hirs.persist.PortalInfoManager} ready to use.
* // *
* @return {@link hirs.persist.ReferenceManifestManager} // * @return {@link hirs.persist.PortalInfoManager}
*/ // */
@Bean // @Bean
public ReferenceManifestManager referenceManifestManager() { // public PortalInfoManager portalInfoManager() {
DBReferenceManifestManager manager // DBPortalInfoManager manager = new DBPortalInfoManager(entityManager);
= new DBReferenceManifestManager(entityManager); // setDbServiceRetrySettings(manager);
setDbManagerRetrySettings(manager); // return manager;
return manager; // }
}
/**
* Creates a {@link hirs.persist.ReferenceEventManager} ready to use.
*
* @return {@link hirs.persist.ReferenceEventManager}
*/
@Bean
public ReferenceEventManager referenceEventManager() {
DBReferenceEventManager manager
= new DBReferenceEventManager(entityManager);
setDbManagerRetrySettings(manager);
return manager;
}
/**
* Creates a {@link hirs.persist.ReportRequestStateManager} ready to use.
*
* @return {@link hirs.persist.ReportRequestStateManager}
*/
@Bean
public ReportRequestStateManager reportRequestStateManager() {
DBReportRequestStateManager manager
= new DBReportRequestStateManager(entityManager);
setDbManagerRetrySettings(manager);
return manager;
}
/**
* Creates a {@link hirs.persist.PortalInfoManager} ready to use.
*
* @return {@link hirs.persist.PortalInfoManager}
*/
@Bean
public PortalInfoManager portalInfoManager() {
DBPortalInfoManager manager = new DBPortalInfoManager(entityManager);
setDbManagerRetrySettings(manager);
return manager;
}
/** /**
* Creates a {@link hirs.attestationca.servicemanager.DBManager} * Creates a {@link hirs.attestationca.servicemanager.DBManager}
@ -178,20 +135,20 @@ public class PersistenceConfiguration {
*/ */
@Bean @Bean
public CrudManager<SupplyChainValidationSummary> supplyChainValidationSummaryManager() { public CrudManager<SupplyChainValidationSummary> supplyChainValidationSummaryManager() {
DBManager<SupplyChainValidationSummary> manager DbServiceImpl<SupplyChainValidationSummary> manager
= new DBManager<SupplyChainValidationSummary>( = new DbServiceImpl<>(
SupplyChainValidationSummary.class, SupplyChainValidationSummary.class,
entityManager entityManager
); );
setDbManagerRetrySettings(manager); setDbServiceRetrySettings(manager);
return manager; return manager;
} }
/** /**
* Apply the spring-wired retry template settings to the db manager. * Apply the spring-wired retry template settings to the db manager.
* @param dbManager the manager to apply the retry settings to * @param dbServiceImpl the service to apply the retry settings to
*/ */
private void setDbManagerRetrySettings(final DBManager dbManager) { private void setDbServiceRetrySettings(final DbServiceImpl dbServiceImpl) {
dbManager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds); dbServiceImpl.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds);
} }
} }

View File

@ -7,10 +7,11 @@ import hirs.data.persist.certificate.CertificateAuthorityCredential;
import hirs.data.persist.certificate.EndorsementCredential; import hirs.data.persist.certificate.EndorsementCredential;
import hirs.data.persist.certificate.IssuedAttestationCertificate; import hirs.data.persist.certificate.IssuedAttestationCertificate;
import hirs.data.persist.certificate.PlatformCredential; import hirs.data.persist.certificate.PlatformCredential;
import hirs.persist.service.CertificateService; import hirs.persist.CertificateSelector;
import hirs.persist.CriteriaModifier; import hirs.persist.CriteriaModifier;
import hirs.persist.DBManagerException; import hirs.persist.DBManagerException;
import hirs.persist.OrderedQuery; import hirs.persist.OrderedQuery;
import hirs.persist.service.CertificateService;
import hirs.persist.service.DefaultService; import hirs.persist.service.DefaultService;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -19,8 +20,11 @@ import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext; import org.springframework.retry.RetryContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
/** /**
@ -37,7 +41,14 @@ public class CertificateServiceImpl extends DbServiceImpl<Certificate>
@Autowired @Autowired
private CertificateRepository certificateRepository; private CertificateRepository certificateRepository;
@Override /**
* Default constructor.
* @param em entity manager for jpa hibernate events
*/
public CertificateServiceImpl(final EntityManager em) {
}
@Override
public Certificate saveCertificate(final Certificate certificate) { public Certificate saveCertificate(final Certificate certificate) {
LOGGER.debug("Saving certificate: {}", certificate); LOGGER.debug("Saving certificate: {}", certificate);
@ -73,6 +84,12 @@ public class CertificateServiceImpl extends DbServiceImpl<Certificate>
return saveCertificate(dbCertificate); return saveCertificate(dbCertificate);
} }
@Override
public <T extends Certificate> Set<T> getCertificate(
final CertificateSelector certificateSelector) {
return new HashSet<>(0);
}
@Override @Override
public List<Certificate> getList() { public List<Certificate> getList() {
LOGGER.debug("Getting all certificates..."); LOGGER.debug("Getting all certificates...");

View File

@ -16,6 +16,7 @@ import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext; import org.springframework.retry.RetryContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -33,6 +34,13 @@ public class DeviceServiceImpl extends DbServiceImpl<Device> implements DefaultS
@Autowired @Autowired
private DeviceRepository deviceRepository; private DeviceRepository deviceRepository;
/**
* Default constructor.
* @param em entity manager for jpa hibernate events
*/
public DeviceServiceImpl(final EntityManager em) {
}
@Override @Override
public final Device saveDevice(final Device device) throws DeviceManagerException { public final Device saveDevice(final Device device) throws DeviceManagerException {
LOGGER.debug("Saving device: {}", device); LOGGER.debug("Saving device: {}", device);

View File

@ -15,6 +15,7 @@ import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext; import org.springframework.retry.RetryContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -32,6 +33,12 @@ public class PolicyServiceImpl extends DbServiceImpl<Policy> implements DefaultS
@Autowired @Autowired
private PolicyRepository policyRepository; private PolicyRepository policyRepository;
/**
* Default Constructor.
*/
public PolicyServiceImpl(final EntityManager em) {
}
@Override @Override
public List<Policy> getList() { public List<Policy> getList() {
LOGGER.debug("Getting all policies..."); LOGGER.debug("Getting all policies...");

View File

@ -15,6 +15,7 @@ import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext; import org.springframework.retry.RetryContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -37,8 +38,7 @@ public class ReferenceDigestValueServiceImpl extends DbServiceImpl<ReferenceDige
/** /**
* Default Constructor. * Default Constructor.
*/ */
public ReferenceDigestValueServiceImpl() { public ReferenceDigestValueServiceImpl(final EntityManager em) {
super();
} }
@Override @Override

View File

@ -15,6 +15,7 @@ import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext; import org.springframework.retry.RetryContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.EntityManager;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
@ -33,6 +34,13 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl<ReferenceManifes
@Autowired @Autowired
private ReferenceManifestRepository referenceManifestRepository; private ReferenceManifestRepository referenceManifestRepository;
/**
* Default constructor.
* @param em entity manager for jpa hibernate events
*/
public ReferenceManifestServiceImpl(final EntityManager em) {
}
@Override @Override
public ReferenceManifest saveRIM(final ReferenceManifest rim) { public ReferenceManifest saveRIM(final ReferenceManifest rim) {
LOGGER.debug("Saving reference manifest: {}", rim); LOGGER.debug("Saving reference manifest: {}", rim);

View File

@ -2,7 +2,7 @@ package hirs.attestationca.portal.datatables;
import hirs.FilteredRecordsList; import hirs.FilteredRecordsList;
import hirs.persist.CriteriaModifier; import hirs.persist.CriteriaModifier;
import hirs.persist.OrderedListQuerier; import hirs.persist.OrderedQuery;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -31,7 +31,7 @@ public final class OrderedListQueryDataTableAdapter<T> {
* @return the filtered record list * @return the filtered record list
*/ */
public static <T> FilteredRecordsList<T> getOrderedList(final Class<T> clazz, public static <T> FilteredRecordsList<T> getOrderedList(final Class<T> clazz,
final OrderedListQuerier<T> dbManager, final OrderedQuery<T> dbManager,
final DataTableInput dataTableInput, final DataTableInput dataTableInput,
final String orderColumnName) { final String orderColumnName) {
@ -54,10 +54,12 @@ public final class OrderedListQueryDataTableAdapter<T> {
* @param <T> the parameter type * @param <T> the parameter type
* @return the filtered record list * @return the filtered record list
*/ */
public static <T> FilteredRecordsList<T> getOrderedList(final Class<T> clazz, public static <T> FilteredRecordsList<T> getOrderedList(
final OrderedListQuerier<T> dbManager, final DataTableInput dataTableInput, final Class<T> clazz,
final String orderColumnName, final OrderedQuery<T> dbManager,
final CriteriaModifier criteriaModifier) { final DataTableInput dataTableInput,
final String orderColumnName,
final CriteriaModifier criteriaModifier) {
Map<String, Boolean> searchableColumnMap = new HashMap<>(); Map<String, Boolean> searchableColumnMap = new HashMap<>();
for (Column column : dataTableInput.getColumns()) { for (Column column : dataTableInput.getColumns()) {

View File

@ -8,14 +8,13 @@ import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter;
import hirs.attestationca.portal.page.Page; import hirs.attestationca.portal.page.Page;
import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.params.NoPageParams; import hirs.attestationca.portal.page.params.NoPageParams;
import hirs.attestationca.service.ReferenceDigestValueServiceImpl;
import hirs.attestationca.servicemanager.DBReferenceManifestManager;
import hirs.data.persist.ReferenceDigestValue; import hirs.data.persist.ReferenceDigestValue;
import hirs.data.persist.SupportReferenceManifest; import hirs.data.persist.SupportReferenceManifest;
import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.Certificate;
import hirs.persist.CriteriaModifier; import hirs.persist.CriteriaModifier;
import hirs.persist.DBManagerException; import hirs.persist.DBManagerException;
import hirs.attestationca.servicemanager.DBReferenceEventManager;
import hirs.attestationca.servicemanager.DBReferenceManifestManager;
import hirs.persist.ReferenceEventManager;
import hirs.persist.ReferenceManifestManager; import hirs.persist.ReferenceManifestManager;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -47,7 +46,7 @@ public class RimDatabasePageController
private final BiosDateValidator biosValidator; private final BiosDateValidator biosValidator;
private final ReferenceManifestManager referenceManifestManager; private final ReferenceManifestManager referenceManifestManager;
private final ReferenceEventManager referenceEventManager; private final ReferenceDigestValueServiceImpl referenceDigestValueService;
private static final Logger LOGGER private static final Logger LOGGER
= LogManager.getLogger(RimDatabasePageController.class); = LogManager.getLogger(RimDatabasePageController.class);
@ -97,15 +96,15 @@ public class RimDatabasePageController
* Constructor providing the Page's display and routing specification. * Constructor providing the Page's display and routing specification.
* *
* @param referenceManifestManager the ReferenceManifestManager object * @param referenceManifestManager the ReferenceManifestManager object
* @param referenceEventManager the referenceEventManager object * @param referenceDigestValueService the referenceDigestValueService object
*/ */
@Autowired @Autowired
public RimDatabasePageController( public RimDatabasePageController(
final DBReferenceManifestManager referenceManifestManager, final DBReferenceManifestManager referenceManifestManager,
final DBReferenceEventManager referenceEventManager) { final ReferenceDigestValueServiceImpl referenceDigestValueService) {
super(Page.RIM_DATABASE); super(Page.RIM_DATABASE);
this.referenceManifestManager = referenceManifestManager; this.referenceManifestManager = referenceManifestManager;
this.referenceEventManager = referenceEventManager; this.referenceDigestValueService = referenceDigestValueService;
this.biosValidator = new BiosDateValidator(BIOS_RELEASE_DATE_FORMAT); this.biosValidator = new BiosDateValidator(BIOS_RELEASE_DATE_FORMAT);
} }
@ -156,7 +155,7 @@ public class RimDatabasePageController
FilteredRecordsList<ReferenceDigestValue> referenceDigestValues = FilteredRecordsList<ReferenceDigestValue> referenceDigestValues =
OrderedListQueryDataTableAdapter.getOrderedList( OrderedListQueryDataTableAdapter.getOrderedList(
ReferenceDigestValue.class, ReferenceDigestValue.class,
referenceEventManager, referenceDigestValueService,
input, orderColumnName, criteriaModifier); input, orderColumnName, criteriaModifier);
SupportReferenceManifest support; SupportReferenceManifest support;
@ -168,7 +167,7 @@ public class RimDatabasePageController
if (support != null) { if (support != null) {
rdv.setBaseRimId(support.getAssociatedRim()); rdv.setBaseRimId(support.getAssociatedRim());
try { try {
referenceEventManager.updateEvent(rdv); referenceDigestValueService.updateDigestValue(rdv, rdv.getId());
} catch (DBManagerException e) { } catch (DBManagerException e) {
LOGGER.error("Failed to update TPM Event with Base RIM ID"); LOGGER.error("Failed to update TPM Event with Base RIM ID");
LOGGER.error(rdv); LOGGER.error(rdv);

View File

@ -13,10 +13,10 @@ import hirs.data.persist.certificate.Certificate;
import hirs.data.persist.certificate.PlatformCredential; import hirs.data.persist.certificate.PlatformCredential;
import hirs.data.persist.certificate.attributes.ComponentIdentifier; import hirs.data.persist.certificate.attributes.ComponentIdentifier;
import hirs.data.persist.certificate.attributes.V2.ComponentIdentifierV2; import hirs.data.persist.certificate.attributes.V2.ComponentIdentifierV2;
import hirs.persist.CertificateManager;
import hirs.persist.CriteriaModifier; import hirs.persist.CriteriaModifier;
import hirs.persist.CrudManager; import hirs.persist.CrudManager;
import hirs.persist.DeviceManager; import hirs.persist.DeviceManager;
import hirs.persist.service.CertificateService;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
@ -60,7 +60,7 @@ public class ValidationReportsPageController extends PageController<NoPageParams
@Autowired @Autowired
private final CrudManager<SupplyChainValidationSummary> supplyChainValidatorSummaryManager; private final CrudManager<SupplyChainValidationSummary> supplyChainValidatorSummaryManager;
@Autowired @Autowired
private final CertificateManager certificateManager; private final CertificateService certificateService;
@Autowired @Autowired
private final DeviceManager deviceManager; private final DeviceManager deviceManager;
@ -76,17 +76,17 @@ public class ValidationReportsPageController extends PageController<NoPageParams
/** /**
* Constructor providing the Page's display and routing specification. * Constructor providing the Page's display and routing specification.
* @param supplyChainValidatorSummaryManager the manager * @param supplyChainValidatorSummaryManager the manager
* @param certificateManager the certificate manager * @param certificateService the certificate service
* @param deviceManager the device manager * @param deviceManager the device manager
*/ */
@Autowired @Autowired
public ValidationReportsPageController( public ValidationReportsPageController(
final CrudManager<SupplyChainValidationSummary> supplyChainValidatorSummaryManager, final CrudManager<SupplyChainValidationSummary> supplyChainValidatorSummaryManager,
final CertificateManager certificateManager, final CertificateService certificateService,
final DeviceManager deviceManager) { final DeviceManager deviceManager) {
super(VALIDATION_REPORTS); super(VALIDATION_REPORTS);
this.supplyChainValidatorSummaryManager = supplyChainValidatorSummaryManager; this.supplyChainValidatorSummaryManager = supplyChainValidatorSummaryManager;
this.certificateManager = certificateManager; this.certificateService = certificateService;
this.deviceManager = deviceManager; this.deviceManager = deviceManager;
} }
@ -266,7 +266,7 @@ public class ValidationReportsPageController extends PageController<NoPageParams
&& (createTimes.get(i).isBefore(endDate) && (createTimes.get(i).isBefore(endDate)
|| createTimes.get(i).isEqual(endDate))) { || createTimes.get(i).isEqual(endDate))) {
UUID deviceId = deviceManager.getDevice(deviceNames[i]).getId(); UUID deviceId = deviceManager.getDevice(deviceNames[i]).getId();
PlatformCredential pc = PlatformCredential.select(certificateManager) PlatformCredential pc = PlatformCredential.select(certificateService)
.byDeviceId(deviceId).getCertificate(); .byDeviceId(deviceId).getCertificate();
if (jsonVersion) { if (jsonVersion) {
jsonReportData.add(assembleJsonContent(pc, parseComponents(pc), jsonReportData.add(assembleJsonContent(pc, parseComponents(pc),
@ -381,7 +381,7 @@ public class ValidationReportsPageController extends PageController<NoPageParams
componentFailureString.append(pc.getComponentFailures()); componentFailureString.append(pc.getComponentFailures());
// get all the certificates associated with the platform serial // get all the certificates associated with the platform serial
List<PlatformCredential> chainCertificates = PlatformCredential List<PlatformCredential> chainCertificates = PlatformCredential
.select(certificateManager) .select(certificateService)
.byBoardSerialNumber(pc.getPlatformSerial()) .byBoardSerialNumber(pc.getPlatformSerial())
.getCertificates().stream().collect(Collectors.toList()); .getCertificates().stream().collect(Collectors.toList());
// combine all components in each certificate // combine all components in each certificate

View File

@ -1,51 +0,0 @@
package hirs;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.util.Date;
/**
* Serializes <code>DeviceGroup</code> data for Json to process.
*/
public class DeviceGroupSerializer extends JsonSerializer<DeviceGroup> {
@Override
public void serialize(final DeviceGroup value, final JsonGenerator gen,
final SerializerProvider serializers) throws IOException {
gen.writeStartObject();
if (value.getId() != null) {
gen.writeStringField("id", value.getId().toString());
} else {
gen.writeNullField("id");
}
gen.writeNumberField("createTime", value.getCreateTime().getTime());
Date archivedTime = value.getArchivedTime();
if (archivedTime != null) {
gen.writeNumberField("archivedTime", archivedTime.getTime());
} else {
gen.writeNullField("archivedTime");
}
gen.writeStringField("archivedDescription", value.getArchivedDescription());
gen.writeStringField("name", value.getName());
gen.writeStringField("description", value.getDescription());
gen.writeNumberField("periodicReportDelayThreshold",
value.getPeriodicReportDelayThreshold());
gen.writeBooleanField("enablePeriodicReportDelayAlert",
value.isEnablePeriodicReportDelayAlert());
gen.writeNumberField("onDemandReportDelayThreshold",
value.getOnDemandReportDelayThreshold());
gen.writeBooleanField("enableOnDemandReportDelayAlert",
value.isEnableOnDemandReportDelayAlert());
gen.writeBooleanField("waitForAppraisalCompletionEnabled",
value.isWaitForAppraisalCompletionEnabled());
gen.writeObjectField("scheduledJobInfo", value.getScheduledJobInfo());
gen.writeNumberField("numberOfDevices", value.getNumberOfDevices());
gen.writeNumberField("numberOfTrustedDevices", value.getNumberOfTrustedDevices());
gen.writeStringField("healthStatus", value.getHealthStatus().toString());
gen.writeBooleanField("archived", value.isArchived());
gen.writeEndObject();
}
}

View File

@ -3,7 +3,6 @@ package hirs.data.persist;
import hirs.data.persist.enums.HealthStatus; import hirs.data.persist.enums.HealthStatus;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import hirs.DeviceGroupSerializer;
import hirs.foss.XMLCleaner; import hirs.foss.XMLCleaner;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;

View File

@ -9,7 +9,7 @@ import java.util.List;
* Interface defining database CRUD operations (Create, Read, Update, Delete). * Interface defining database CRUD operations (Create, Read, Update, Delete).
* @param <T> the object type, T. * @param <T> the object type, T.
*/ */
public interface CrudManager<T> extends OrderedListQuerier<T> { public interface CrudManager<T> extends OrderedQuery<T> {
/** /**
* *

View File

@ -1,7 +1,9 @@
package hirs.persist.service; package hirs.persist.service;
import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.Certificate;
import hirs.persist.CertificateSelector;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
/** /**
@ -29,4 +31,13 @@ public interface CertificateService {
* @return a Certificate object * @return a Certificate object
*/ */
Certificate updateCertificate(Certificate certificate, UUID uuid); Certificate updateCertificate(Certificate certificate, UUID uuid);
/**
* Retrieve Certificates according to the given {@link CertificateSelector}.
*
* @param <T> the type of certificate that will be retrieved
* @param certificateSelector a {@link CertificateSelector} to use for querying
* @return a Set of matching Certificates, which may be empty
*/
<T extends Certificate> Set<T> getCertificate(CertificateSelector certificateSelector);
} }