From 74a3cf9e21012c2224ea17ea7a6b5ba4868e27f8 Mon Sep 17 00:00:00 2001 From: Cyrus <24922493+cyrus-dev@users.noreply.github.com> Date: Tue, 2 Aug 2022 14:00:57 -0400 Subject: [PATCH] Removed DeviceGroup. Updated the serviceImpl classes with the retry and flush methods. Commit latest changes and transitioning to getting the properites linked. --- ...stractAttestationCertificateAuthority.java | 2 +- .../java/hirs/attestationca/AcaDbInit.java | 18 +- .../attestationca/InitializationListener.java | 2 - .../PersistenceConfiguration.java | 14 - .../repository/PolicyRepository.java | 2 +- .../service/CertificateServiceImpl.java | 39 +- .../attestationca/service/DbServiceImpl.java | 19 +- .../service/DeviceServiceImpl.java | 41 +- .../attestationca/service/PolicyService.java | 2 +- .../service/PolicyServiceImpl.java | 40 +- .../ReferenceDigestValueServiceImpl.java | 28 +- .../service/ReferenceManifestServiceImpl.java | 37 +- .../service/SupplyChainValidationService.java | 2 +- .../SupplyChainValidationServiceImpl.java | 4 +- .../servicemanager/DBDeviceGroupManager.java | 275 ---------- .../servicemanager/DBDeviceManager.java | 1 - .../servicemanager/DBPolicyManager.java | 3 +- .../data/persist/DeviceGroupTest.java | 1 - .../persist/DBCertificateManagerTest.java | 3 - .../persist/DBDeviceGroupManagerTest.java | 6 +- .../persist/DBDeviceManagerTest.java | 3 - .../persist/DBPolicyManagerTest.java | 5 +- .../DBReportRequestStateManagerTest.java | 2 - .../SupplyChainValidationServiceImplTest.java | 5 +- .../portal/model/PolicyPageModel.java | 2 +- .../controllers/PolicyPageController.java | 2 +- .../CertificateDetailsPageControllerTest.java | 2 - .../DevicesPageControllerTest.java | 2 - .../IssuedCertificatesPageControllerTest.java | 2 - .../controllers/PolicyPageControllerTest.java | 4 +- .../main/java/hirs/DeviceGroupSerializer.java | 1 - .../java/hirs/appraiser/AppraiserPlugin.java | 2 +- .../main/java/hirs/data/persist/Device.java | 55 -- .../java/hirs/data/persist/DeviceGroup.java | 488 ------------------ .../data/persist/{ => policy}/HIRSPolicy.java | 20 +- .../data/persist/{ => policy}/PCRPolicy.java | 4 +- .../data/persist/{ => policy}/Policy.java | 4 +- .../persist/{ => policy}/PolicyException.java | 2 +- .../{ => policy}/SupplyChainPolicy.java | 2 +- .../data/persist/{ => policy}/TPMPolicy.java | 3 +- .../data/persist/policy/package-info.java | 5 + .../hirs/data/service/DeviceRegisterImpl.java | 2 - .../java/hirs/persist/DeviceGroupManager.java | 114 ---- .../persist/DeviceGroupManagerException.java | 45 -- .../main/java/hirs/persist/PolicyManager.java | 13 +- .../main/java/hirs/persist/PolicyMapper.java | 3 +- .../java/hirs/DeviceGroupSerializerTest.java | 166 ------ .../hirs/appraiser/TestAppraiserPlugin.java | 2 +- .../hirs/data/persist/HIRSPolicyTest.java | 1 + .../java/hirs/data/persist/PCRPolicyTest.java | 1 + .../java/hirs/data/persist/PolicyTest.java | 1 + .../data/persist/SupplyChainPolicyTest.java | 1 + .../java/hirs/data/persist/TestPolicy.java | 2 + .../java/hirs/data/persist/TestPolicy2.java | 2 + .../data/service/DeviceRegisterImplTest.java | 2 - 55 files changed, 218 insertions(+), 1291 deletions(-) delete mode 100644 HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceGroupManager.java delete mode 100644 HIRS_Utils/src/main/java/hirs/data/persist/DeviceGroup.java rename HIRS_Utils/src/main/java/hirs/data/persist/{ => policy}/HIRSPolicy.java (90%) rename HIRS_Utils/src/main/java/hirs/data/persist/{ => policy}/PCRPolicy.java (98%) rename HIRS_Utils/src/main/java/hirs/data/persist/{ => policy}/Policy.java (96%) rename HIRS_Utils/src/main/java/hirs/data/persist/{ => policy}/PolicyException.java (96%) rename HIRS_Utils/src/main/java/hirs/data/persist/{ => policy}/SupplyChainPolicy.java (99%) rename HIRS_Utils/src/main/java/hirs/data/persist/{ => policy}/TPMPolicy.java (99%) create mode 100644 HIRS_Utils/src/main/java/hirs/data/persist/policy/package-info.java delete mode 100644 HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManager.java delete mode 100644 HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManagerException.java delete mode 100644 HIRS_Utils/src/test/java/hirs/DeviceGroupSerializerTest.java diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java index c0f9acf8..7d723282 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java @@ -14,7 +14,7 @@ import hirs.data.persist.DeviceInfoReport; import hirs.data.persist.EventLogMeasurements; import hirs.data.persist.ReferenceDigestValue; import hirs.data.persist.ReferenceManifest; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.data.persist.SupplyChainValidationSummary; import hirs.data.persist.SupportReferenceManifest; import hirs.data.persist.SwidResource; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AcaDbInit.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AcaDbInit.java index cde3ac79..32e9f2d1 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AcaDbInit.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AcaDbInit.java @@ -1,10 +1,8 @@ package hirs.attestationca; import hirs.appraiser.SupplyChainAppraiser; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.persist.AppraiserManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.PolicyManager; import static hirs.attestationca.AbstractAttestationCertificateAuthority.LOG; @@ -22,25 +20,13 @@ public final class AcaDbInit { * install of the HIRS_AttestationCA RPM. * * @param appraiserManager the AppraiserManager to use to persist appraisers - * @param deviceGroupManager the DeviceGroupManager to use to persist device groups * @param policyManager the PolicyManager to use to persist policies */ public static synchronized void insertDefaultEntries( final AppraiserManager appraiserManager, - final DeviceGroupManager deviceGroupManager, final PolicyManager policyManager) { LOG.info("Ensuring default ACA database entries are present."); - // Ensure the default group exists. It may have already been created by the Server RPM - DeviceGroup defaultGroup = deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP); - if (defaultGroup == null) { - LOG.info("Default group not found; saving..."); - defaultGroup = deviceGroupManager.saveDeviceGroup(new DeviceGroup( - DeviceGroup.DEFAULT_GROUP, - "This is the default group")); - LOG.info("Saved default group."); - } - // If the SupplyChainAppraiser exists, do not attempt to re-save the supply chain appraiser // or SupplyChainPolicy SupplyChainAppraiser supplyChainAppraiser = (SupplyChainAppraiser) @@ -62,7 +48,7 @@ public final class AcaDbInit { SupplyChainPolicy.DEFAULT_POLICY); policyManager.savePolicy(supplyChainPolicy); policyManager.setDefaultPolicy(supplyChainAppraiser, supplyChainPolicy); - policyManager.setPolicy(supplyChainAppraiser, defaultGroup, supplyChainPolicy); + policyManager.setPolicy(supplyChainAppraiser, supplyChainPolicy); LOG.info("ACA database initialization complete."); } diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/InitializationListener.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/InitializationListener.java index abb3ea03..154653ac 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/InitializationListener.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/InitializationListener.java @@ -1,7 +1,6 @@ package hirs.attestationca; import hirs.attestationca.servicemanager.DBAppraiserManager; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBPolicyManager; import hirs.utils.HIRSProfiles; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -31,7 +30,6 @@ public class InitializationListener implements ServletContextListener { .createEntityManager(); AcaDbInit.insertDefaultEntries( new DBAppraiserManager(entityManager), - new DBDeviceGroupManager(entityManager), new DBPolicyManager(entityManager) ); } diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/configuration/PersistenceConfiguration.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/configuration/PersistenceConfiguration.java index 912bdadb..fc1cd4f6 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/configuration/PersistenceConfiguration.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/configuration/PersistenceConfiguration.java @@ -2,7 +2,6 @@ package hirs.attestationca.configuration; import hirs.attestationca.AttestationCertificateAuthorityConfiguration; import hirs.attestationca.servicemanager.DBCertificateManager; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.attestationca.servicemanager.DBManager; import hirs.attestationca.servicemanager.DBPolicyManager; @@ -15,7 +14,6 @@ import hirs.attestationca.servicemanager.DBReportSummaryManager; import hirs.data.persist.SupplyChainValidationSummary; import hirs.persist.CertificateManager; import hirs.persist.CrudManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import hirs.persist.PolicyManager; import hirs.persist.PortalInfoManager; @@ -109,18 +107,6 @@ public class PersistenceConfiguration { return manager; } - /** - * Creates a {@link hirs.persist.DeviceGroupManager} ready to use. - * - * @return {@link hirs.persist.DeviceGroupManager} - */ - @Bean - public DeviceGroupManager deviceGroupManager() { - DBDeviceGroupManager manager = new DBDeviceGroupManager(entityManager); - setDbManagerRetrySettings(manager); - return manager; - } - /** * Creates a {@link hirs.persist.CertificateManager} ready to use. * diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/repository/PolicyRepository.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/repository/PolicyRepository.java index a5cf331c..13b0f329 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/repository/PolicyRepository.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/repository/PolicyRepository.java @@ -1,6 +1,6 @@ package hirs.attestationca.repository; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/CertificateServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/CertificateServiceImpl.java index 16a5bc93..26e38a5f 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/CertificateServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/CertificateServiceImpl.java @@ -13,6 +13,8 @@ import hirs.persist.OrderedQuery; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; import org.springframework.stereotype.Service; import java.util.List; @@ -36,7 +38,15 @@ public class CertificateServiceImpl extends DbServiceImpl @Override public Certificate saveCertificate(final Certificate certificate) { LOGGER.debug("Saving certificate: {}", certificate); - return certificateRepository.save(certificate); + + return getRetryTemplate().execute(new RetryCallback() { + @Override + public Certificate doWithRetry(final RetryContext context) + throws DBManagerException { + return certificateRepository.save(certificate); + } + }); } @Override @@ -58,15 +68,21 @@ public class CertificateServiceImpl extends DbServiceImpl } - certificateRepository.save(dbCertificate); - - return dbCertificate; + return saveCertificate(dbCertificate); } @Override public List getList() { LOGGER.debug("Getting all certificates..."); - return this.certificateRepository.findAll(); + + return getRetryTemplate().execute(new RetryCallback, + DBManagerException>() { + @Override + public List doWithRetry(final RetryContext context) + throws DBManagerException { + return certificateRepository.findAll(); + } + }); } @Override @@ -78,12 +94,23 @@ public class CertificateServiceImpl extends DbServiceImpl this.updateCertificate(certificate, certificate.getId()); } }); + certificateRepository.flush(); } @Override public void deleteObjectById(final UUID uuid) { LOGGER.debug("Deleting certificate by id: {}", uuid); - this.certificateRepository.deleteById(uuid); + + getRetryTemplate().execute(new RetryCallback() { + @Override + public Void doWithRetry(final RetryContext context) + throws DBManagerException { + certificateRepository.deleteById(uuid); + certificateRepository.flush(); + return null; + } + }); } @Override diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DbServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DbServiceImpl.java index 6e2bccb5..5540cbb5 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DbServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DbServiceImpl.java @@ -4,6 +4,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.hibernate.StaleObjectStateException; import org.hibernate.exception.LockAcquisitionException; +import org.springframework.retry.RetryListener; import org.springframework.retry.backoff.FixedBackOffPolicy; import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.support.RetryTemplate; @@ -36,7 +37,7 @@ public class DbServiceImpl { private RetryTemplate retryTemplate; /** - * Creates a new DBManager that uses the default database. The + * Creates a new DbServiceImpl that uses the default database. The * default database is used to store all of the objects. * */ @@ -69,4 +70,20 @@ public class DbServiceImpl { this.retryTemplate.setRetryPolicy(retryPolicy); this.retryTemplate.setBackOffPolicy(backoffPolicy); } + + /** + * Accessor method for the retry function. + * @return instance of the RetryTemplate + */ + protected RetryTemplate getRetryTemplate() { + return this.retryTemplate; + } + + /** + * Registers a retry listener to be notified of retry activity. + * @param retryListener the retry listener + */ + public void addRetryListener(final RetryListener retryListener) { + retryTemplate.registerListener(retryListener); + } } diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DeviceServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DeviceServiceImpl.java index 3af29b11..6a6f8554 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DeviceServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/DeviceServiceImpl.java @@ -10,6 +10,8 @@ import hirs.persist.OrderedQuery; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; import org.springframework.stereotype.Service; import java.util.List; @@ -32,7 +34,15 @@ public class DeviceServiceImpl extends DbServiceImpl implements DefaultS @Override public final Device saveDevice(final Device device) throws DeviceManagerException { LOGGER.debug("Saving device: {}", device); - return deviceRepository.save(device); + + return getRetryTemplate().execute(new RetryCallback() { + @Override + public Device doWithRetry(final RetryContext context) + throws DBManagerException { + return deviceRepository.save(device); + } + }); } @Override @@ -50,19 +60,22 @@ public class DeviceServiceImpl extends DbServiceImpl implements DefaultS // run through things that aren't equal and update + } - - } - - deviceRepository.save(dbDevice); - - return dbDevice; + return saveDevice(dbDevice); } @Override public final List getList() { LOGGER.debug("Getting all devices..."); - return deviceRepository.findAll(); + + return getRetryTemplate().execute(new RetryCallback, DBManagerException>() { + @Override + public List doWithRetry(final RetryContext context) + throws DBManagerException { + return deviceRepository.findAll(); + } + }); } @Override @@ -74,13 +87,23 @@ public class DeviceServiceImpl extends DbServiceImpl implements DefaultS this.updateDevice(device, device.getId()); } }); + deviceRepository.flush(); } @Override public final void deleteObjectById(final UUID uuid) throws DeviceManagerException { LOGGER.debug("Deleting deviceById: {}", uuid); - deviceRepository.deleteById(uuid); + + getRetryTemplate().execute(new RetryCallback() { + @Override + public Void doWithRetry(final RetryContext context) + throws DBManagerException { + deviceRepository.deleteById(uuid); + deviceRepository.flush(); + return null; + } + }); } @Override diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyService.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyService.java index 5be5a51f..d1067e5a 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyService.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyService.java @@ -1,6 +1,6 @@ package hirs.attestationca.service; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import java.util.UUID; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyServiceImpl.java index 6d8bdf2c..f2b630d7 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/PolicyServiceImpl.java @@ -2,13 +2,15 @@ package hirs.attestationca.service; import hirs.FilteredRecordsList; import hirs.attestationca.repository.PolicyRepository; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import hirs.persist.CriteriaModifier; import hirs.persist.DBManagerException; import hirs.persist.OrderedQuery; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; import org.springframework.stereotype.Service; import java.util.List; @@ -31,7 +33,15 @@ public class PolicyServiceImpl extends DbServiceImpl implements DefaultS @Override public List getList() { LOGGER.debug("Getting all policies..."); - return this.policyRepository.findAll(); + + return getRetryTemplate().execute(new RetryCallback, DBManagerException>() { + @Override + public List doWithRetry(final RetryContext context) + throws DBManagerException { + policyRepository.findAll(); + return null; + } + }); } @Override @@ -43,18 +53,35 @@ public class PolicyServiceImpl extends DbServiceImpl implements DefaultS this.updatePolicy(policy, policy.getId()); } }); + policyRepository.flush(); } @Override public void deleteObjectById(final UUID uuid) { LOGGER.debug("Deleting policy by id: {}", uuid); - this.policyRepository.deleteById(uuid); + + getRetryTemplate().execute(new RetryCallback() { + @Override + public Void doWithRetry(final RetryContext context) + throws DBManagerException { + policyRepository.deleteById(uuid); + policyRepository.flush(); + return null; + } + }); } @Override public Policy savePolicy(final Policy policy) { LOGGER.debug("Saving policy: {}", policy); - return policyRepository.save(policy); + + return getRetryTemplate().execute(new RetryCallback() { + @Override + public Policy doWithRetry(final RetryContext context) + throws DBManagerException { + return policyRepository.save(policy); + } + }); } @Override @@ -70,12 +97,9 @@ public class PolicyServiceImpl extends DbServiceImpl implements DefaultS dbPolicy = policyRepository.getReferenceById(uuid); // run through things that aren't equal and update - } - policyRepository.save(dbPolicy); - - return dbPolicy; + return savePolicy(dbPolicy); } @Override diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/ReferenceDigestValueServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/ReferenceDigestValueServiceImpl.java index 1ec32bf1..b5b52621 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/ReferenceDigestValueServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/ReferenceDigestValueServiceImpl.java @@ -9,6 +9,8 @@ import hirs.persist.OrderedQuery; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.retry.RetryCallback; +import org.springframework.retry.RetryContext; import org.springframework.stereotype.Service; import java.util.List; @@ -52,18 +54,36 @@ public class ReferenceDigestValueServiceImpl extends DbServiceImpl() { + @Override + public Void doWithRetry(final RetryContext context) + throws DBManagerException { + referenceDigestValueRepository.deleteById(uuid); + referenceDigestValueRepository.flush(); + return null; + } + }); } @Override public ReferenceDigestValue saveDigestValue(final ReferenceDigestValue digestValue) { LOGGER.debug("Saving reference digest value: {}", digestValue); - return this.referenceDigestValueRepository.save(digestValue); + + return getRetryTemplate().execute(new RetryCallback() { + @Override + public ReferenceDigestValue doWithRetry(final RetryContext context) + throws DBManagerException { + return referenceDigestValueRepository.save(digestValue); + } + }); } @Override @@ -88,9 +108,7 @@ public class ReferenceDigestValueServiceImpl extends DbServiceImpl() { + @Override + public ReferenceManifest doWithRetry(final RetryContext context) + throws DBManagerException { + return referenceManifestRepository.save(rim); + } + }); } @Override @@ -52,15 +62,21 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl getList() { LOGGER.debug("Getting all reference manifest..."); - return this.referenceManifestRepository.findAll(); + + return getRetryTemplate().execute(new RetryCallback, + DBManagerException>() { + @Override + public List doWithRetry(final RetryContext context) + throws DBManagerException { + return referenceManifestRepository.findAll(); + } + }); } @Override @@ -77,7 +93,16 @@ public class ReferenceManifestServiceImpl extends DbServiceImpl() { + @Override + public Void doWithRetry(final RetryContext context) + throws DBManagerException { + referenceManifestRepository.deleteById(uuid); + referenceManifestRepository.flush(); + return null; + } + }); } @Override diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationService.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationService.java index 7bb58a9e..3936272a 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationService.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationService.java @@ -3,7 +3,7 @@ package hirs.attestationca.service; import java.util.Set; import hirs.data.persist.Device; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.data.persist.SupplyChainValidationSummary; import hirs.data.persist.certificate.EndorsementCredential; import hirs.data.persist.certificate.PlatformCredential; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java index 57cafc60..65ead7b9 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java @@ -9,10 +9,10 @@ import hirs.data.persist.BaseReferenceManifest; import hirs.data.persist.Device; import hirs.data.persist.DeviceInfoReport; import hirs.data.persist.EventLogMeasurements; -import hirs.data.persist.PCRPolicy; +import hirs.data.persist.policy.PCRPolicy; import hirs.data.persist.ReferenceDigestValue; import hirs.data.persist.ReferenceManifest; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.data.persist.SupplyChainValidation; import hirs.data.persist.SupplyChainValidationSummary; import hirs.data.persist.SupportReferenceManifest; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceGroupManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceGroupManager.java deleted file mode 100644 index 4802a1c8..00000000 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceGroupManager.java +++ /dev/null @@ -1,275 +0,0 @@ -package hirs.attestationca.servicemanager; - -import hirs.FilteredRecordsList; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.Policy; -import hirs.persist.CriteriaModifier; -import hirs.persist.DBManagerException; -import hirs.persist.DeviceGroupManager; -import hirs.persist.DeviceGroupManagerException; -import hirs.persist.PolicyMapper; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.hibernate.Criteria; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.query.Query; -import org.springframework.stereotype.Service; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * This class defines the DBDeviceGroupManager that is used to - * store DeviceGroups in the database. - */ -@Service -public class DBDeviceGroupManager extends DBManager implements DeviceGroupManager { - - private static final Logger LOGGER = LogManager.getLogger(DBDeviceGroupManager.class); - - /** - * Creates a new DBDeviceGroupManager and sets the - * SessionFactory to the given instance. - * - * @param em session factory used to access database connections - */ - public DBDeviceGroupManager(final EntityManager em) { - super(DeviceGroup.class, em); - } - - /** - * Saves the DeviceGroup in the database. This creates a new - * database session and saves the device group. If the - * DeviceGroup had been previously saved, then a - * DeviceGroupManagerException is thrown. - * - * @param deviceGroup - * device group to save - * @return reference to saved device group - * @throws hirs.persist.DeviceGroupManagerException - * if device group had been previously saved or an error occurs - * while trying to save it to the database - */ - @Override - public final DeviceGroup saveDeviceGroup(final DeviceGroup deviceGroup) - throws DeviceGroupManagerException { - LOGGER.debug("saving device group: {}", deviceGroup); - try { - return super.save(deviceGroup); - } catch (DBManagerException e) { - throw new DeviceGroupManagerException(e); - } - } - - /** - * Updates a DeviceGroup. This updates the database entries to - * reflect the new values that should be set. - * - * @param deviceGroup - * device group - * @throws DeviceGroupManagerException - * if device group has not been previously saved or an error - * occurs while trying to save it to the database - * - */ - @Override - public final void updateDeviceGroup(final DeviceGroup deviceGroup) - throws DeviceGroupManagerException { - LOGGER.debug("updating device group: {}", deviceGroup); - try { - super.update(deviceGroup); - } catch (DBManagerException e) { - throw new DeviceGroupManagerException(e); - } - } - - /** - * Returns a set of all DeviceGroups. - * - * @return set of DeviceGroups - * @throws DeviceGroupManagerException - * if unable to search the database - */ - @Override - public final Set getDeviceGroupSet() - throws DeviceGroupManagerException { - LOGGER.debug("getting device group list"); - try { - final List deviceGroupList = - super.getList(DeviceGroup.class); - return new HashSet<>(deviceGroupList); - } catch (DBManagerException e) { - throw new DeviceGroupManagerException(e); - } - } - - /** - * Retrieves a DeviceGroup from the database. This searches the - * database for an entry whose name matches name. - * - * @param name - * name of the device group - * @return device group if found, otherwise null - * @throws DeviceGroupManagerException - * if unable to search the database - */ - @Override - public final DeviceGroup getDeviceGroup(final String name) - throws DeviceGroupManagerException { - LOGGER.debug("getting device group: {}", name); - try { - return super.get(name); - } catch (DBManagerException e) { - throw new DeviceGroupManagerException(e); - } - } - - /** - * Checks whether or not a {@link Policy} is currently associated with - * a group. The only instance at this time makes a determination whether - * or not the provided Policy is safe for deletion. - * - * @param policy - * {@link Policy} that has been selected for deletion. - * @return - * whether or not the provided policy is the member of a group - * @throws DeviceGroupManagerException - * if policy is null or unable to return query {@link Policy} - */ - @Override - public final Set getGroupsAssignedToPolicy(final Policy policy) - throws DeviceGroupManagerException { - - if (policy == null) { - LOGGER.error("policy provided was null"); - throw new DeviceGroupManagerException("policy provided was null"); - } - - Set groups = new HashSet<>(); - - Session session = getSession(); - Transaction tx = session.beginTransaction(); - - try { - LOGGER.debug("retrieving policy mapper from db where policy = {}", policy); - CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); - CriteriaQuery criteriaQuery = criteriaBuilder - .createQuery(PolicyMapper.class); - Root root = criteriaQuery.from(PolicyMapper.class); - Predicate recordPredicate = criteriaBuilder.and( - criteriaBuilder.equal(root.get("policy"), policy)); - criteriaQuery.select(root).where(recordPredicate); - Query query = session.createQuery(criteriaQuery); - List results = query.getResultList(); - - //Retrieves a list of PolicyMapper objects that are unique per group -// List policyMapperList = session.createCriteria(PolicyMapper.class) -// .add(Restrictions.eq("policy", policy)).list(); - - session.getTransaction().commit(); - - if (results == null) { - LOGGER.debug("no policy mapper found for policy {}", policy); - - } else { - for (PolicyMapper policyMapper : results) { - groups.add(policyMapper.getDeviceGroup()); - } - } - } catch (Exception e) { - - final String msg = "unable to get default policy"; - LOGGER.error(msg, e); - - LOGGER.debug("rolling back transaction"); - tx.rollback(); - - throw new DeviceGroupManagerException(msg, e); - - } - return groups; - } - /** - * Deletes the DeviceGroup from the database. This removes all - * of the database entries that stored information with regards to the - * DeviceGroup. - *

- * If the DeviceGroup is referenced by any other tables then - * this will throw a DeviceGroupManagerException. - * - * @param name - * name of the device group - * @return true if successfully found and deleted, false if otherwise - * @throws DeviceGroupManagerException - * if unable to find the device group or delete it from the - * database - */ - @Override - public final boolean deleteDeviceGroup(final String name) - throws DeviceGroupManagerException { - LOGGER.debug("deleting device group: {}", name); - try { - return super.delete(name); - } catch (DBManagerException e) { - throw new DeviceGroupManagerException(e); - } - } - - /** - * Returns a list of all Devices that are ordered by a column - * and direction (ASC, DESC) that is provided by the user. This method - * helps support the server-side processing in the JQuery DataTables. - * - * @param columnToOrder Column to be ordered - * @param ascending direction of sort - * @param firstResult starting point of first result in set - * @param maxResults total number we want returned for display in table - * @param search string of criteria to be matched to visible columns - * - * @return FilteredRecordsList object with fields for DataTables - * @throws DeviceGroupManagerException - * if unable to create the list - */ - @Override - public final FilteredRecordsList getOrderedDeviceGroupList( - final String columnToOrder, final boolean ascending, final int firstResult, - final int maxResults, final String search) - throws DeviceGroupManagerException { - - if (columnToOrder == null) { - LOGGER.debug("null object argument"); - throw new NullPointerException("object"); - } - - //Maps object types and their ability to be searched by Hibernate - //without modification - Map searchableColumns = new HashMap<>(); - searchableColumns.put("name", true); - searchableColumns.put("description", true); - - CriteriaModifier modifier = new CriteriaModifier() { - @Override - public void modify(final Criteria criteria) { - //criteria.createAlias("deviceGroup", "group"); - } - }; - - try { - LOGGER.debug("Getting baseline list"); - return super.getOrderedList(DeviceGroup.class, columnToOrder, ascending, firstResult, - maxResults, search, searchableColumns, modifier); - } catch (DBManagerException e) { - LOGGER.error(e); - return null; - } - } -} diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceManager.java index b54962da..bf8be5d8 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBDeviceManager.java @@ -2,7 +2,6 @@ package hirs.attestationca.servicemanager; import hirs.FilteredRecordsList; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.persist.CriteriaModifier; import hirs.persist.DBManagerException; import hirs.persist.DeviceManager; diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBPolicyManager.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBPolicyManager.java index 7a5249be..471cfa54 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBPolicyManager.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/servicemanager/DBPolicyManager.java @@ -3,8 +3,7 @@ package hirs.attestationca.servicemanager; import com.google.common.base.Preconditions; import hirs.appraiser.Appraiser; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import hirs.persist.DBManagerException; import hirs.persist.PolicyManager; import hirs.persist.PolicyManagerException; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/data/persist/DeviceGroupTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/data/persist/DeviceGroupTest.java index 2af0d00c..ca2342af 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/data/persist/DeviceGroupTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/data/persist/DeviceGroupTest.java @@ -1,7 +1,6 @@ package hirs.attestationca.data.persist; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.enums.HealthStatus; import hirs.persist.ScheduledJobInfo; import org.testng.Assert; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBCertificateManagerTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBCertificateManagerTest.java index c59fd2a1..53a5c5ec 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBCertificateManagerTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBCertificateManagerTest.java @@ -1,10 +1,8 @@ package hirs.attestationca.persist; import hirs.attestationca.servicemanager.DBCertificateManager; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.CertificateAuthorityCredential; import hirs.data.persist.certificate.CertificateTest; @@ -17,7 +15,6 @@ import hirs.data.persist.certificate.PlatformCredentialTest; import hirs.persist.CertificateManager; import hirs.persist.CertificateSelector; import hirs.persist.DBManagerException; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceGroupManagerTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceGroupManagerTest.java index 4591650f..a2baf7b8 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceGroupManagerTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceGroupManagerTest.java @@ -3,19 +3,15 @@ package hirs.attestationca.persist; import hirs.appraiser.Appraiser; import hirs.appraiser.TestAppraiser; import hirs.attestationca.servicemanager.DBAppraiserManager; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.attestationca.servicemanager.DBPolicyManager; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.DeviceInfoReport; import hirs.attestationca.data.persist.DeviceTest; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import hirs.data.persist.TestPolicy; import hirs.persist.AppraiserManager; import hirs.persist.DBUtility; -import hirs.persist.DeviceGroupManager; -import hirs.persist.DeviceGroupManagerException; import hirs.persist.DeviceManager; import hirs.persist.PolicyManager; import hirs.persist.PolicyMapper; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceManagerTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceManagerTest.java index a42c768a..05a05870 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceManagerTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBDeviceManagerTest.java @@ -1,16 +1,13 @@ package hirs.attestationca.persist; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.attestationca.servicemanager.DBReportManager; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.DeviceInfoReport; import hirs.attestationca.data.persist.DeviceTest; import hirs.data.persist.enums.HealthStatus; import hirs.data.persist.info.NetworkInfo; import hirs.persist.DBUtility; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import hirs.persist.DeviceManagerException; import hirs.persist.ReportManager; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBPolicyManagerTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBPolicyManagerTest.java index 7b8fe018..cccf0b82 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBPolicyManagerTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBPolicyManagerTest.java @@ -3,15 +3,12 @@ package hirs.attestationca.persist; import hirs.appraiser.Appraiser; import hirs.appraiser.TestAppraiser; import hirs.attestationca.data.persist.DeviceTest; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.attestationca.servicemanager.DBPolicyManager; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import hirs.data.persist.TestPolicy; import hirs.data.persist.TestPolicy2; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import hirs.persist.PolicyManager; import hirs.persist.PolicyManagerException; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBReportRequestStateManagerTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBReportRequestStateManagerTest.java index c6b87081..1b83bb19 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBReportRequestStateManagerTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/persist/DBReportRequestStateManagerTest.java @@ -1,10 +1,8 @@ package hirs.attestationca.persist; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; import hirs.attestationca.servicemanager.DBReportRequestStateManager; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.attestationca.data.persist.DeviceTest; import hirs.data.persist.ReportRequestState; import hirs.data.persist.type.ReportRequestType; diff --git a/HIRS_AttestationCA/src/test/java/hirs/attestationca/service/SupplyChainValidationServiceImplTest.java b/HIRS_AttestationCA/src/test/java/hirs/attestationca/service/SupplyChainValidationServiceImplTest.java index 5cb8b5bf..f5838b23 100644 --- a/HIRS_AttestationCA/src/test/java/hirs/attestationca/service/SupplyChainValidationServiceImplTest.java +++ b/HIRS_AttestationCA/src/test/java/hirs/attestationca/service/SupplyChainValidationServiceImplTest.java @@ -4,9 +4,8 @@ import hirs.attestationca.persist.SpringPersistenceTest; import hirs.appraiser.SupplyChainAppraiser; import hirs.data.persist.AppraisalStatus; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.DeviceInfoReport; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.data.persist.SupplyChainValidation; import hirs.data.persist.SupplyChainValidationSummary; import hirs.data.persist.certificate.Certificate; @@ -18,9 +17,7 @@ import hirs.persist.AppraiserManager; import hirs.persist.CertificateManager; import hirs.persist.CrudManager; import hirs.attestationca.servicemanager.DBCertificateManager; -import hirs.attestationca.servicemanager.DBDeviceGroupManager; import hirs.attestationca.servicemanager.DBDeviceManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import hirs.persist.PolicyManager; import hirs.persist.ReferenceDigestManager; diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/model/PolicyPageModel.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/model/PolicyPageModel.java index 78b529ec..1190b8e9 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/model/PolicyPageModel.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/model/PolicyPageModel.java @@ -1,6 +1,6 @@ package hirs.attestationca.portal.model; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; /** * PolicyPage model object to demonstrate data exchange between policy.jsp page diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java index 1e728454..ed403eea 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/PolicyPageController.java @@ -6,7 +6,7 @@ import hirs.attestationca.portal.model.PolicyPageModel; import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageMessages; import hirs.attestationca.portal.page.params.NoPageParams; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.persist.AppraiserManager; import hirs.persist.PolicyManager; import hirs.persist.PolicyManagerException; diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/CertificateDetailsPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/CertificateDetailsPageControllerTest.java index ae4c9431..b5079d33 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/CertificateDetailsPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/CertificateDetailsPageControllerTest.java @@ -4,14 +4,12 @@ import hirs.attestationca.portal.page.Page; import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageControllerTest; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.CertificateAuthorityCredential; import hirs.data.persist.certificate.EndorsementCredential; import hirs.data.persist.certificate.IssuedAttestationCertificate; import hirs.data.persist.certificate.PlatformCredential; import hirs.persist.CertificateManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.springframework.beans.factory.annotation.Autowired; diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/DevicesPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/DevicesPageControllerTest.java index 17ef84e5..62c5423a 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/DevicesPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/DevicesPageControllerTest.java @@ -3,12 +3,10 @@ package hirs.attestationca.portal.page.controllers; import hirs.attestationca.portal.page.PageControllerTest; import hirs.data.persist.AppraisalStatus; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.EndorsementCredential; import hirs.data.persist.certificate.PlatformCredential; import hirs.persist.CertificateManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java index bda8574e..984304a9 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/IssuedCertificatesPageControllerTest.java @@ -2,13 +2,11 @@ package hirs.attestationca.portal.page.controllers; import hirs.attestationca.portal.page.PageControllerTest; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.certificate.Certificate; import hirs.data.persist.certificate.EndorsementCredential; import hirs.data.persist.certificate.IssuedAttestationCertificate; import hirs.data.persist.certificate.PlatformCredential; import hirs.persist.CertificateManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; diff --git a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/PolicyPageControllerTest.java b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/PolicyPageControllerTest.java index 7df91643..651f71cc 100644 --- a/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/PolicyPageControllerTest.java +++ b/HIRS_AttestationCAPortal/src/test/java/hirs/attestationca/portal/page/controllers/PolicyPageControllerTest.java @@ -2,10 +2,8 @@ package hirs.attestationca.portal.page.controllers; import hirs.appraiser.Appraiser; import hirs.appraiser.SupplyChainAppraiser; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.SupplyChainPolicy; +import hirs.data.persist.policy.SupplyChainPolicy; import hirs.persist.AppraiserManager; -import hirs.persist.DeviceGroupManager; import hirs.persist.PolicyManager; import org.testng.Assert; import static hirs.attestationca.portal.page.Page.POLICY; diff --git a/HIRS_Utils/src/main/java/hirs/DeviceGroupSerializer.java b/HIRS_Utils/src/main/java/hirs/DeviceGroupSerializer.java index 9bd8bf0a..bd928e8c 100644 --- a/HIRS_Utils/src/main/java/hirs/DeviceGroupSerializer.java +++ b/HIRS_Utils/src/main/java/hirs/DeviceGroupSerializer.java @@ -3,7 +3,6 @@ package hirs; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; -import hirs.data.persist.DeviceGroup; import java.io.IOException; import java.util.Date; diff --git a/HIRS_Utils/src/main/java/hirs/appraiser/AppraiserPlugin.java b/HIRS_Utils/src/main/java/hirs/appraiser/AppraiserPlugin.java index 6bd14453..4d1cb54d 100644 --- a/HIRS_Utils/src/main/java/hirs/appraiser/AppraiserPlugin.java +++ b/HIRS_Utils/src/main/java/hirs/appraiser/AppraiserPlugin.java @@ -1,6 +1,6 @@ package hirs.appraiser; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import org.springframework.plugin.core.Plugin; /** diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/Device.java b/HIRS_Utils/src/main/java/hirs/data/persist/Device.java index 54084725..7df66f0a 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/Device.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/Device.java @@ -66,13 +66,6 @@ public class Device extends AbstractEntity { @XmlElement private DeviceInfoReport deviceInfo; - @XmlTransient - @JsonSerialize(using = DeviceGroupSerializer.class) - @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER, - optional = false) - @JoinColumn(name = "device_group_id", nullable = false) - private DeviceGroup deviceGroup; - @XmlTransient @Column @Enumerated(EnumType.ORDINAL) @@ -189,54 +182,6 @@ public class Device extends AbstractEntity { this.deviceInfo = deviceInfo; } - /** - * Returns the device group that is set for this device. May return null if - * no device group is set. Null represents the "default" device group. - * - * @return deviceGroup - */ - public final DeviceGroup getDeviceGroup() { - return deviceGroup; - } - - /** - * Sets the device group for this device. May be null if the "default" - * device group is desired. This method also adds or removes the Device - * from the Device Group as appropriate. - * - * @param deviceGroup - * deviceGroup or null - */ - public final void setDeviceGroup(final DeviceGroup deviceGroup) { - if (deviceGroup == null) { - LOGGER.error("could not add devicegroup -- null"); - throw new NullPointerException("deviceGroup"); - } - - if (this.deviceGroup != null) { - if (this.deviceGroup.equals(deviceGroup)) { - // Do nothing if the device is already in the group - return; - } - this.deviceGroup.removeDeviceProtected(this); - } - - deviceGroup.addDeviceProtected(this); - this.deviceGroup = deviceGroup; - } - - /** - * Sets the device group for this device. May be null if the "default" - * device group is desired. - * - * @param deviceGroup - * deviceGroup or null - */ - protected final void setOnlyDeviceGroup( - final DeviceGroup deviceGroup) { - this.deviceGroup = deviceGroup; - } - /** * Returns an XML string representation of this Device. * diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/DeviceGroup.java b/HIRS_Utils/src/main/java/hirs/data/persist/DeviceGroup.java deleted file mode 100644 index 0539922d..00000000 --- a/HIRS_Utils/src/main/java/hirs/data/persist/DeviceGroup.java +++ /dev/null @@ -1,488 +0,0 @@ -package hirs.data.persist; - -import hirs.data.persist.enums.HealthStatus; -import com.fasterxml.jackson.annotation.JsonIgnore; -import hirs.persist.ScheduledJobInfo; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; - -import javax.persistence.Access; -import javax.persistence.AccessType; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.OneToMany; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -/** - * This class represents a device group. A device group is used to manage a collection of devices - * and associated measurement policies. Devices associated with a machine group undergo an identical - * appraisal process and are expected to comply with the device group measurement policies and - * associated measurement baselines. - */ -@Entity -@Access(AccessType.FIELD) -public class DeviceGroup extends UserDefinedEntity { - - /** - * Name set for default instance of DeviceGroup. - */ - public static final String DEFAULT_GROUP = "Default Group"; - private static final Logger LOGGER = LogManager.getLogger(DeviceGroup.class); - - /** - * A second period in milliseconds. - */ - public static final long SECOND_MS_INTERVAL = 1000; - - /** - * A minute period in milliseconds. - */ - public static final long MINUTE_MS_INTERVAL = 60 * SECOND_MS_INTERVAL; - - /** - * five minutes period in milliseconds. - */ - public static final long FIVE_MINUTES_MS_INTERVAL = 5 * MINUTE_MS_INTERVAL; - - /** - * An hour period in milliseconds. - */ - public static final long HOUR_MS_INTERVAL = 60 * MINUTE_MS_INTERVAL; - - /** - * A day period in milliseconds. - */ - public static final long DAY_MS_INTERVAL = 24 * HOUR_MS_INTERVAL; - - /** - * The default for on demand and periodic report thresholds. - */ - public static final long DEFAULT_REPORT_DELAY_THRESHOLD = 12 * HOUR_MS_INTERVAL; - - /** - * Minimum Periodic report period is once every 500 millisecond. - */ - public static final long MINIMUM_PERIODIC_REPORT_INTERVAL = FIVE_MINUTES_MS_INTERVAL; - - /** - * Minimum allowed value for any report Threshold. - */ - public static final long MINIMUM_THRESHOLD_INTERVAL_MS = MINUTE_MS_INTERVAL; - - /** - * The default job frequency of 1 day in milliseconds. - */ - public static final long DEFAULT_JOB_FREQUENCY_MS = DAY_MS_INTERVAL; - - /** - * Creates a new ScheduledJobInfo with default values. - * - * @return the default ScheduledJobInfo - */ - public static ScheduledJobInfo createDefaultScheduledJobInfo() { - return new ScheduledJobInfo(DEFAULT_JOB_FREQUENCY_MS); - } - - @JsonIgnore - @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, - fetch = FetchType.EAGER, mappedBy = "deviceGroup") - private final Set devices = new HashSet<>(); - - @Column(nullable = false) - private long periodicReportDelayThreshold = DEFAULT_REPORT_DELAY_THRESHOLD; - - @Column(nullable = false) - private boolean enablePeriodicReportDelayAlert = false; - - @Column(nullable = false) - private long onDemandReportDelayThreshold = DEFAULT_REPORT_DELAY_THRESHOLD; - - @Column(nullable = false) - private boolean enableOnDemandReportDelayAlert = false; - - @Column(nullable = false) - private boolean waitForAppraisalCompletionEnabled = false; - - @Embedded - private ScheduledJobInfo scheduledJobInfo; - - /** - * Creates a new DeviceGroup with a specified name and a null description. - * - * @param name name of the device group - */ - public DeviceGroup(final String name) { - super(name); - scheduledJobInfo = createDefaultScheduledJobInfo(); - } - - /** - * Creates a new DeviceGroup with a specified name and description. The description - * may be null. - * - * @param name name of the device group - * @param description description for the device group - */ - public DeviceGroup(final String name, final String description) { - super(name, description); - scheduledJobInfo = createDefaultScheduledJobInfo(); - } - - /** - * Default constructor used by Hibernate. - */ - protected DeviceGroup() { - super(); - scheduledJobInfo = createDefaultScheduledJobInfo(); - } - - /** - * Returns an unmodifiable set of the Devices in the DeviceGroup. - * - * @return an unmodifiable Set of Devices - */ - public final Set getDevices() { - return Collections.unmodifiableSet(this.devices); - } - - /** - * Adds a device to this device group. If the device is not already part of the group, then it - * is added. If an equal device is already part of the group, then the request to add the device - * will be quietly ignored. This method also sets the DeviceGroup field on the Device. - * - * @param device device to add to the group - */ - public final void addDevice(final Device device) { - device.setDeviceGroup(this); - addDeviceProtected(device); - } - - /** - * Adds a device to this device group. If the device is not already part of the group, then it - * is added. If an equal device is already part of the group, then the request to add the device - * will be quietly ignored. - * - * @param device device to add to the group - */ - protected final void addDeviceProtected(final Device device) { - if (device == null) { - LOGGER.error("null device"); - throw new NullPointerException("device"); - } - LOGGER.debug("adding device '{}' to device group '{}'", - device.getName(), getName()); - - boolean isDeviceSuccessfullyAdded = devices.add(device); - if (isDeviceSuccessfullyAdded) { - LOGGER.debug(String.format( - "added device '%s' to device group '%s'", device.getName(), - getName())); - } else { - LOGGER.info("device '{}' already exists in device group '{}'", - device.getName(), getName()); - } - } - - /** - * Remove device from the device group. This method also sets the Device's Device Group to - * null. - * - * @param device device to remove - * @return a boolean indicating if the removal was successful - */ - public final boolean removeDevice(final Device device) { - if (device == null) { - LOGGER.error("null device"); - return false; - } - LOGGER.debug("removing device '{}' from device group '{}'", - device.getName(), getName()); - boolean deviceRemovedSuccessfully = devices.remove(device); - if (deviceRemovedSuccessfully) { - device.setOnlyDeviceGroup(null); - } - return deviceRemovedSuccessfully; - } - - /** - * Remove device from the device group. - * - * @param device device to remove - * @return a boolean indicating if the removal was successful - */ - protected final boolean removeDeviceProtected(final Device device) { - return devices.remove(device); - } - - /** - * Remove a device from the device group using the device's name. The device name is unique. - * - * @param deviceName unique name of device to be removed - * @return a boolean indicating if the removal was successful - */ - public final boolean removeDevice(final String deviceName) { - if (deviceName == null) { - LOGGER.error("null device"); - return false; - } - LOGGER.debug("removing device '{}' from device group '{}'", deviceName, - getName()); - for (Device device : devices) { - if (device.getName().equals(deviceName)) { - return devices.remove(device); - } - } - LOGGER.error( - "device with name '{}' was not found in device group '{}'", - deviceName, getName()); - return false; - } - - /** - * Sets the maximum number of milliseconds allowed to elapse without receiving a report from a - * client.

This period should be greater than two or three times the periodicReportInterval - * value. Note: this value should not be allowed to be set to a value less than the regular - * periodic report interval for the client (periodicReportInterval); This method prevents - * setting this value to very low setting (i.e. under MINIMUM_THRESHOLD_INTERVAL_MS)

This - * logic does not verify/enforce that limit is lower than periodicReportInterval to avoid - * restrictions on the order of setting various parameters of this policy. - * - * @param milliseconds the desired new threshold value - */ - public final void setPeriodicReportDelayThreshold(final long milliseconds) { - if (milliseconds < MINIMUM_THRESHOLD_INTERVAL_MS) { - throw new IllegalArgumentException( - "Periodic Report Delay Threshold must be greater than or " - + "equal to " - + String.valueOf(MINIMUM_THRESHOLD_INTERVAL_MS) - + " milliseconds. Received " - + String.valueOf(milliseconds)); - } - periodicReportDelayThreshold = milliseconds; - } - - /** - * Gets the maximum milliseconds allowed elapse without receiving a client report before - * considering the client periodic report is late. - *

- * HIRS appraiser would issue an alert whenever late periodic report condition is detected and - * the policy is configured to allow this type of alerts to be issued. - * - * @return periodicReportDelayThreshold maximum milliseconds for late periodic report condition - */ - public final long getPeriodicReportDelayThreshold() { - return periodicReportDelayThreshold; - } - - /** - * Sets the policy flag that controls if HIRS appraiser will issue a late periodic alert. - *

- * This flag should be set to false when portal user is not sure that it has set - * periodicReportDelayThreshold with sufficient tolerance to avoid unnecessary excessive alerts - * for clients. For example, if portal sets periodicReportDelayThreshold to value less than or - * equal to the periodicReportInterval, this will cause unnecessary excessive alerts. - * - * @param flag true enables the alert, and false otherwise - */ - public final void setEnablePeriodicReportDelayAlert(final boolean flag) { - enablePeriodicReportDelayAlert = flag; - } - - /** - * Determines if periodic alert delay alerts should be issued whenever time elapsed since last - * received report from a client exceeds the maximum allowed delay interval defined by - * periodicReportDelayThreshold period. - * - * @return enablePeriodicReportDelayAlert true enables the alert, and false otherwise - */ - public final boolean isEnablePeriodicReportDelayAlert() { - return enablePeriodicReportDelayAlert; - } - - /** - * Sets the time threshold that determines the maximum milliseconds allowed to elapse after the - * portal initiates a client on-demand report request without receiving a report from the - * client.

if a report was not received in this milliseconds interval, and the - * enableOndemandReportDelayAlert flag was set to true; HIRS appraiser will issue an alert.

- * This period must be set to a value greater than three times the duration of the client's cron - * invocation job that runs periodically to cause the client send ReportRequest query to HIRS - * appraiser plus sufficient time for the client to collect and send a report. - * - * @param milliseconds desired new threshold value - * @throws IllegalArgumentException thrown if less than MINIMUM_THRESHOLD_INTERVAL_MS - */ - - public final void setOnDemandReportDelayThreshold(final long milliseconds) - throws IllegalArgumentException { - if (milliseconds < MINIMUM_THRESHOLD_INTERVAL_MS) { - throw new IllegalArgumentException( - "On Demand Report Delay Threshold must be greater than or " - + "equal to " - + String.valueOf(MINIMUM_THRESHOLD_INTERVAL_MS) - + " milliseconds. Received " - + String.valueOf(milliseconds)); - } - onDemandReportDelayThreshold = milliseconds; - } - - /** - * Gets the maximum time HIRS appraiser will wait for a client to send a report after the portal - * initiates On-Demand report request. - *

- * If the appraiser does not receive the report on time and the policy is configured to enable - * On-demand report delay alert, this alert will be issued. - * - * @return onDemandReportDelayThreshold milliseconds time limit to trigger on-demand report late - * alert - */ - public final long getOnDemandReportDelayThreshold() { - return onDemandReportDelayThreshold; - } - - /** - * Sets the policy flag that controls on-Demand client report delay alert. - *

- * This alert will be issued by HIRS appraiser whenever the portal initiates on-demand report - * request and no client report is received within the maximum allowed milliseconds interval - * defined by the onDemandReportDelayThreshold. - * - * @param flag true enables the alert, and false otherwise - */ - public final void setEnableOnDemandReportDelayAlert(final boolean flag) { - enableOnDemandReportDelayAlert = flag; - } - - /** - * Determines if the OnDemand report delay alert is allowed to be issued by HIRS appraiser. - * - * @return enableOnDemandReportDelayAlert true to enables the alert, and false otherwise - */ - public final boolean isEnableOnDemandReportDelayAlert() { - return enableOnDemandReportDelayAlert; - } - - /** - * Gets flag indicating if devices in this group should wait for appraisal completion. - * @return true if devices are waiting for appraisal completion, false otherwise - */ - public boolean isWaitForAppraisalCompletionEnabled() { - return waitForAppraisalCompletionEnabled; - } - - /** - * Sets flag indicating if devices in this group should wait for appraisal completion. - * @param waitForAppraisalCompletionEnabled true if devices are waiting for - * appraisal completion, false otherwise - */ - public void setWaitForAppraisalCompletionEnabled(final boolean - waitForAppraisalCompletionEnabled) { - this.waitForAppraisalCompletionEnabled = waitForAppraisalCompletionEnabled; - } - - /** - * Gets the ScheduleJobInfo for this Repository. - * @return the SecheduleJobInfo - */ - public ScheduledJobInfo getScheduledJobInfo() { - return scheduledJobInfo; - } - - /** - * Sets the ScheduleJobInfo for this Repository. - * @param scheduledJobInfo the ScheduleJobInfo - */ - public void setScheduledJobInfo(final ScheduledJobInfo scheduledJobInfo) { - Assert.notNull(scheduledJobInfo, "scheduledJobInfo"); - this.scheduledJobInfo = scheduledJobInfo; - } - - /** - * Gets the health status of this group, which is a summary of the set of devices for this - * group. If at least one device is untrusted, then the group is untrusted. If at least one - * device has unknown trust, and there are no untrusted devices, then the trust will be - * unknown. If there are zero devices in this group, the trust will be unknown. - * Otherwise, the group will be trusted. - * - * @return the group health - */ - public HealthStatus getHealthStatus() { - if (CollectionUtils.isEmpty(devices)) { - return HealthStatus.UNKNOWN; - } - boolean hasUnknownTrusts = false; - for (Device device : devices) { - switch (device.getHealthStatus()) { - case UNTRUSTED: - return HealthStatus.UNTRUSTED; - case UNKNOWN: - hasUnknownTrusts = true; - break; - default: - break; - } - } - - if (hasUnknownTrusts) { - return HealthStatus.UNKNOWN; - } - return HealthStatus.TRUSTED; - } - - /** - * Gets the number of devices within the group. - * - * @return the number of devices - */ - public int getNumberOfDevices() { - int count = 0; - - if (devices != null) { - count = devices.size(); - } - - return count; - } - - /** - * Gets the number of devices currently trusted within the group. - * - * @return the number of trusted devices - */ - public int getNumberOfTrustedDevices() { - int count = 0; - - if (devices != null) { - for (final Device device : devices) { - if (device.getHealthStatus() == HealthStatus.TRUSTED) { - count++; - } - } - } - - return count; - } - - /** - * Gets only the devices for the device group. - * (Return a set of devices without any reference - * to the device groups to avoid an infinite loop.) - * - * @return a set of all the devices - */ - public Set getAllDevices() { - Set allDevices = new HashSet<>(); - - for (Device device: devices) { - device.setOnlyDeviceGroup(null); - allDevices.add(device); - } - return Collections.unmodifiableSet(allDevices); - } -} diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/HIRSPolicy.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/HIRSPolicy.java similarity index 90% rename from HIRS_Utils/src/main/java/hirs/data/persist/HIRSPolicy.java rename to HIRS_Utils/src/main/java/hirs/data/persist/policy/HIRSPolicy.java index 165d2fdf..80d650d2 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/HIRSPolicy.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/HIRSPolicy.java @@ -1,16 +1,15 @@ -package hirs.data.persist; +package hirs.data.persist.policy; import hirs.appraiser.Appraiser; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - import javax.persistence.CollectionTable; import javax.persistence.ElementCollection; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.JoinColumn; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; /** * A HIRSPolicy is a Policy that specifies the @@ -84,15 +83,4 @@ public class HIRSPolicy extends Policy { public final Set> getRequiredAppraisers() { return Collections.unmodifiableSet(requiredAppraisers); } - - - /** - * Generates the name for the HIRS Policy. - * - * @param group The group related to the HIRS Policy - * @return The name of the Policy - */ - public static String nameFromGroup(final DeviceGroup group) { - return "hirspolicy_" + group.getId(); - } } diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/PCRPolicy.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/PCRPolicy.java similarity index 98% rename from HIRS_Utils/src/main/java/hirs/data/persist/PCRPolicy.java rename to HIRS_Utils/src/main/java/hirs/data/persist/policy/PCRPolicy.java index 2312d345..be6ec789 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/PCRPolicy.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/PCRPolicy.java @@ -1,5 +1,7 @@ -package hirs.data.persist; +package hirs.data.persist.policy; +import hirs.data.persist.ReferenceDigestValue; +import hirs.data.persist.TPMMeasurementRecord; import hirs.data.persist.tpm.PcrComposite; import hirs.data.persist.tpm.PcrInfoShort; import hirs.data.persist.tpm.PcrSelection; diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/Policy.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/Policy.java similarity index 96% rename from HIRS_Utils/src/main/java/hirs/data/persist/Policy.java rename to HIRS_Utils/src/main/java/hirs/data/persist/policy/Policy.java index df4ab180..b15a1786 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/Policy.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/Policy.java @@ -1,4 +1,6 @@ -package hirs.data.persist; +package hirs.data.persist.policy; + +import hirs.data.persist.UserDefinedEntity; import javax.persistence.Access; import javax.persistence.AccessType; diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/PolicyException.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/PolicyException.java similarity index 96% rename from HIRS_Utils/src/main/java/hirs/data/persist/PolicyException.java rename to HIRS_Utils/src/main/java/hirs/data/persist/policy/PolicyException.java index 52c873cc..23e37a7f 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/PolicyException.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/PolicyException.java @@ -1,4 +1,4 @@ -package hirs.data.persist; +package hirs.data.persist.policy; /** * Represents an exception thrown when a Policy is misconfigured in diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/SupplyChainPolicy.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/SupplyChainPolicy.java similarity index 99% rename from HIRS_Utils/src/main/java/hirs/data/persist/SupplyChainPolicy.java rename to HIRS_Utils/src/main/java/hirs/data/persist/policy/SupplyChainPolicy.java index 4ba35856..8a94b877 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/SupplyChainPolicy.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/SupplyChainPolicy.java @@ -1,4 +1,4 @@ -package hirs.data.persist; +package hirs.data.persist.policy; import javax.persistence.Column; import javax.persistence.Embedded; diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/TPMPolicy.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/TPMPolicy.java similarity index 99% rename from HIRS_Utils/src/main/java/hirs/data/persist/TPMPolicy.java rename to HIRS_Utils/src/main/java/hirs/data/persist/policy/TPMPolicy.java index 234e9a67..679aba0d 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/TPMPolicy.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/TPMPolicy.java @@ -1,5 +1,6 @@ -package hirs.data.persist; +package hirs.data.persist.policy; +import hirs.data.persist.TPMMeasurementRecord; import hirs.data.persist.enums.AlertSeverity; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/policy/package-info.java b/HIRS_Utils/src/main/java/hirs/data/persist/policy/package-info.java new file mode 100644 index 00000000..3fd1afd0 --- /dev/null +++ b/HIRS_Utils/src/main/java/hirs/data/persist/policy/package-info.java @@ -0,0 +1,5 @@ +/** + * * This package contains a set of classes that persist policy. + */ +package hirs.data.persist.policy; + diff --git a/HIRS_Utils/src/main/java/hirs/data/service/DeviceRegisterImpl.java b/HIRS_Utils/src/main/java/hirs/data/service/DeviceRegisterImpl.java index 403561c5..4f17107f 100644 --- a/HIRS_Utils/src/main/java/hirs/data/service/DeviceRegisterImpl.java +++ b/HIRS_Utils/src/main/java/hirs/data/service/DeviceRegisterImpl.java @@ -1,9 +1,7 @@ package hirs.data.service; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.DeviceInfoReport; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManager.java b/HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManager.java deleted file mode 100644 index f8d95949..00000000 --- a/HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManager.java +++ /dev/null @@ -1,114 +0,0 @@ -package hirs.persist; - -import hirs.FilteredRecordsList; -import java.util.Set; - -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.Policy; - -/** - * A DeviceGroupManager manages DeviceGroups. It is used to store and manage - * device groups. It has support for the basic create, read, update, and delete - * methods. - */ -public interface DeviceGroupManager { - - /** - * Stores a new DeviceGroup to be managed by the - * DeviceGroupManager. If the DeviceGroup is - * successfully saved, then a reference to it is returned. - * - * @param deviceGroup - * device group to save - * @return reference to the saved device group - * @throws DeviceGroupManagerException - * if the device group has been previously saved or an - * unexpected error occurs - */ - DeviceGroup saveDeviceGroup(DeviceGroup deviceGroup) - throws DeviceGroupManagerException; - - /** - * Updates a DeviceGroup that is managed so subsequent calls to - * get this DeviceGroup will return the values set by the - * incoming DeviceGroup. - * - * @param deviceGroup - * device group to be updated - * @throws DeviceGroupManagerException - * if unable to update the device group - */ - void updateDeviceGroup(DeviceGroup deviceGroup) - throws DeviceGroupManagerException; - - /** - * Returns a set of all device groups managed by this manager. Every - * DeviceGroup must have a name that users can use to reference - * the DeviceGroup. - * - * @return a set containing the device groups - * @throws DeviceGroupManagerException - * if unable to create set - */ - Set getDeviceGroupSet() throws DeviceGroupManagerException; - - /** - * Retrieves the DeviceGroup identified by name. - * If the DeviceGroup cannot be found, then null is returned. - * - * @param name - * name of the DeviceGroup - * @return DeviceGroup or null if not found - * @throws DeviceGroupManagerException - * if unable to retrieve the device group - */ - DeviceGroup getDeviceGroup(String name) throws DeviceGroupManagerException; - - /** - * Checks whether or not a {@link Policy} is currently associated with - * a group. The only instance at this time makes a determination whether - * or not the provided Policy is safe for deletion. - * - * @param policy - * {@link Policy} that has been selected for deletion. - * @return - * whether or not the provided policy is the member of a group - * @throws DeviceGroupManagerException - * if policy is null or unable to return query {@link Policy} - */ - Set getGroupsAssignedToPolicy(Policy policy) - throws DeviceGroupManagerException; - - /** - * Delete the DeviceGroup identified by name. If - * the deletion is successful, true is returned. Otherwise, false is - * returned. - * - * @param name - * name of the DeviceGroup to delete - * @return boolean indicating outcome of the deletion - * @throws DeviceGroupManagerException - * if unable to delete the device group - */ - boolean deleteDeviceGroup(String name) throws DeviceGroupManagerException; - - /** - * Returns a list of all DeviceGroups that are ordered by a column - * and direction (ASC, DESC) that is provided by the user. This method - * helps support the server-side processing in the JQuery DataTables. - * - * @param columnToOrder Column to be ordered - * @param ascending direction of sort - * @param firstResult starting point of first result in set - * @param maxResults total number we want returned for display in table - * @param search string of criteria to be matched to visible columns - * - * @return FilteredRecordsList object with fields for DataTables - * @throws DeviceGroupManagerException - * if unable to create the list - */ - FilteredRecordsList getOrderedDeviceGroupList( - String columnToOrder, boolean ascending, int firstResult, - int maxResults, String search) - throws DeviceGroupManagerException; -} diff --git a/HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManagerException.java b/HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManagerException.java deleted file mode 100644 index 3ff40116..00000000 --- a/HIRS_Utils/src/main/java/hirs/persist/DeviceGroupManagerException.java +++ /dev/null @@ -1,45 +0,0 @@ -package hirs.persist; - -/** - * This class represents an Exception generated by a - * DeviceGroupManager. - */ -public class DeviceGroupManagerException extends RuntimeException { - - private static final long serialVersionUID = 972152768034191965L; - - /** - * Creates a new DeviceGroupManagerException that has the - * message msg. - * - * @param msg - * exception message - */ - public DeviceGroupManagerException(final String msg) { - super(msg); - } - - /** - * Creates a new DeviceGroupManagerException that wraps the - * given Throwable. - * - * @param t - * root cause - */ - public DeviceGroupManagerException(final Throwable t) { - super(t); - } - - /** - * Creates a new DeviceGroupManagerException that has the - * message msg and wraps the root cause. - * - * @param msg - * exception message - * @param t - * root cause - */ - public DeviceGroupManagerException(final String msg, final Throwable t) { - super(msg, t); - } -} diff --git a/HIRS_Utils/src/main/java/hirs/persist/PolicyManager.java b/HIRS_Utils/src/main/java/hirs/persist/PolicyManager.java index f9a0d376..90bcbb89 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/PolicyManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/PolicyManager.java @@ -2,8 +2,7 @@ package hirs.persist; import hirs.appraiser.Appraiser; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import java.io.Serializable; import java.util.List; @@ -157,27 +156,23 @@ public interface PolicyManager { * * @param appraiser * appraiser - * @param deviceGroup - * deviceGroup * @return policy or null if not set */ - Policy getPolicy(Appraiser appraiser, DeviceGroup deviceGroup); + Policy getPolicy(Appraiser appraiser); /** * Sets the Policy for the Appraiser and - * DeviceGroup. See {@link #getPolicy(Appraiser, DeviceGroup)} + * DeviceGroup. See {@link #getPolicy(Appraiser)} * for more details on the algorithm used. Policy can be null to remove * the policy for the appraiser-deviceGroup pair, which will retrieve the * default policy instead. * * @param appraiser * appraiser - * @param deviceGroup - * deviceGroup * @param policy * policy */ - void setPolicy(Appraiser appraiser, DeviceGroup deviceGroup, Policy policy); + void setPolicy(Appraiser appraiser, Policy policy); /** * Retrieves the Policy identified by name. If diff --git a/HIRS_Utils/src/main/java/hirs/persist/PolicyMapper.java b/HIRS_Utils/src/main/java/hirs/persist/PolicyMapper.java index 30f9c2a6..be62e356 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/PolicyMapper.java +++ b/HIRS_Utils/src/main/java/hirs/persist/PolicyMapper.java @@ -2,8 +2,7 @@ package hirs.persist; import static org.apache.logging.log4j.LogManager.getLogger; import hirs.appraiser.Appraiser; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/HIRS_Utils/src/test/java/hirs/DeviceGroupSerializerTest.java b/HIRS_Utils/src/test/java/hirs/DeviceGroupSerializerTest.java deleted file mode 100644 index 6c335f36..00000000 --- a/HIRS_Utils/src/test/java/hirs/DeviceGroupSerializerTest.java +++ /dev/null @@ -1,166 +0,0 @@ -package hirs; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import hirs.data.persist.AppraisalStatus; -import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; -import hirs.data.persist.DeviceInfoReport; -import hirs.data.persist.info.FirmwareInfo; -import hirs.data.persist.info.HardwareInfo; -import hirs.data.persist.info.NetworkInfo; -import hirs.data.persist.info.OSInfo; -import hirs.data.persist.info.TPMInfo; -import org.testng.Assert; -import org.testng.annotations.Test; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.nio.charset.StandardCharsets; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Unit tests for the {@link hirs.DeviceGroupSerializer}. - */ -public class DeviceGroupSerializerTest { - - private static final int COUNT_OF_ID_FIELD_OUTSIDE_DEVICE_GROUP = 2; - private static final int COUNT_OF_CREATION_DATE_FIELD_OUTSIDE_DEVICE_GROUP = 1; - private static final int COUNT_OF_NAME_FIELD_OUTSIDE_DEVICE_GROUP = 45; - private static final int COUNT_OF_HEALTH_STATUS_FIELD_OUTSIDE_DEVICE_GROUP = 1; - - /** - * Tests that Jackson correctly serializes the inner {@link DeviceGroup} on a single Device - * using the custom {@link hirs.DeviceGroupSerializer}. - */ - @Test - public void serializeDeviceGroupOnDevice() { - Device testDevice = getTestDevice("Device1"); - assertDeviceSerializedCorrectly(testDevice); - } - - /** - * Tests that Jackson correctly serializes the same inner {@link DeviceGroup} on multiple - * Devices using the custom {@link hirs.DeviceGroupSerializer}. - */ - @Test - public void serializeSameDeviceGroupOnDevices() { - List testDevices = new ArrayList<>(); - Device testDevice1 = getTestDevice("Device1"); - Device testDevice2 = getTestDevice("Device2"); - Assert.assertTrue(testDevice1.getDeviceGroup().equals(testDevice2.getDeviceGroup())); - testDevices.add(testDevice1); - testDevices.add(testDevice2); - assertDevicesSerializedCorrectly(testDevices); - } - - /** - * Tests that Jackson correctly serializes different inner {@link DeviceGroup DeviceGroups} on - * multiple Devices using the custom {@link hirs.DeviceGroupSerializer}. - */ - @Test - public void serializeDifferentDeviceGroupOnDevices() { - List testDevices = new ArrayList<>(); - Device testDevice1 = getTestDevice("Device1"); - Device testDevice2 = getTestDevice("Device2"); - testDevice2.setDeviceGroup(new DeviceGroup("Non-Default Device Group")); - Assert.assertTrue(!testDevice1.getDeviceGroup().equals(testDevice2.getDeviceGroup())); - testDevices.add(testDevice1); - testDevices.add(testDevice2); - assertDevicesSerializedCorrectly(testDevices); - } - - private DeviceInfoReport getTestDeviceInfoReport() throws UnknownHostException { - NetworkInfo testNetworkInfo = new NetworkInfo("TestHostname", - InetAddress.getLocalHost(), "FFFFFF".getBytes(StandardCharsets.UTF_8)); - OSInfo osInfo = new OSInfo(); - FirmwareInfo firmwareInfo = new FirmwareInfo(); - HardwareInfo hardwareInfo = new HardwareInfo(); - TPMInfo tpmInfo = new TPMInfo(); - return new DeviceInfoReport(testNetworkInfo, osInfo, firmwareInfo, hardwareInfo, tpmInfo); - } - - private Device getTestDevice(final String testDeviceName) { - Device testDevice = new Device(testDeviceName); - testDevice.setSupplyChainStatus(AppraisalStatus.Status.PASS); - testDevice.setLastReportTimestamp(new Timestamp(System.currentTimeMillis())); - try { - testDevice.setDeviceInfo(getTestDeviceInfoReport()); - } catch (UnknownHostException uhe) { - Assert.fail("Failed to Create Test DeviceInfoReport"); - } - testDevice.setDeviceGroup(new DeviceGroup("Default Device Group")); - return testDevice; - } - - private int countExactSubstringOccurrences(final String testString, final String substring) { - Pattern p = Pattern.compile("\\b" + substring + "\\b"); - Matcher m = p.matcher(testString); - int count = 0; - while (m.find()) { - count++; - } - return count; - } - - private void assertDeviceSerializedCorrectly(final Device testDevice) { - List testDevices = new ArrayList<>(); - testDevices.add(testDevice); - assertDevicesSerializedCorrectly(testDevices); - } - - private void assertDevicesSerializedCorrectly(final List testDevices) { - String serializedDevices = null; - try { - serializedDevices = new ObjectMapper().writeValueAsString(testDevices); - } catch (JsonProcessingException jpe) { - Assert.fail("Failed to successfully serialize the Test Devices"); - } - int numSerializedDeviceGroups = testDevices.size(); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "id") - (numSerializedDeviceGroups * COUNT_OF_ID_FIELD_OUTSIDE_DEVICE_GROUP) - == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "createTime") - - (numSerializedDeviceGroups * COUNT_OF_CREATION_DATE_FIELD_OUTSIDE_DEVICE_GROUP) - == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "archivedTime") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "archivedDescription") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "name") - - (numSerializedDeviceGroups * COUNT_OF_NAME_FIELD_OUTSIDE_DEVICE_GROUP) - == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "description") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "periodicReportDelayThreshold") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "enablePeriodicReportDelayAlert") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "onDemandReportDelayThreshold") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "enableOnDemandReportDelayAlert") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "waitForAppraisalCompletionEnabled") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "scheduledJobInfo") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "numberOfDevices") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "numberOfTrustedDevices") == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "healthStatus") - - (numSerializedDeviceGroups * COUNT_OF_HEALTH_STATUS_FIELD_OUTSIDE_DEVICE_GROUP) - == numSerializedDeviceGroups); - Assert.assertTrue(countExactSubstringOccurrences(serializedDevices, - "archived") == numSerializedDeviceGroups); - Assert.assertTrue(!serializedDevices.contains("devices")); - } - -} diff --git a/HIRS_Utils/src/test/java/hirs/appraiser/TestAppraiserPlugin.java b/HIRS_Utils/src/test/java/hirs/appraiser/TestAppraiserPlugin.java index ab82ae25..090d7747 100644 --- a/HIRS_Utils/src/test/java/hirs/appraiser/TestAppraiserPlugin.java +++ b/HIRS_Utils/src/test/java/hirs/appraiser/TestAppraiserPlugin.java @@ -1,6 +1,6 @@ package hirs.appraiser; -import hirs.data.persist.Policy; +import hirs.data.persist.policy.Policy; import org.springframework.stereotype.Component; /** diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/HIRSPolicyTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/HIRSPolicyTest.java index 0e9b6a31..601b805d 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/HIRSPolicyTest.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/HIRSPolicyTest.java @@ -9,6 +9,7 @@ import hirs.appraiser.TPMAppraiser; import java.util.HashSet; +import hirs.data.persist.policy.HIRSPolicy; import org.apache.logging.log4j.Logger; import org.hibernate.Session; import org.testng.Assert; diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/PCRPolicyTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/PCRPolicyTest.java index 94a437a5..dd138527 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/PCRPolicyTest.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/PCRPolicyTest.java @@ -1,5 +1,6 @@ package hirs.data.persist; +import hirs.data.persist.policy.PCRPolicy; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/PolicyTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/PolicyTest.java index fb6dc904..e5a694fc 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/PolicyTest.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/PolicyTest.java @@ -1,5 +1,6 @@ package hirs.data.persist; +import hirs.data.persist.policy.Policy; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/SupplyChainPolicyTest.java b/HIRS_Utils/src/test/java/hirs/data/persist/SupplyChainPolicyTest.java index ea8388b6..63cf51f3 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/SupplyChainPolicyTest.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/SupplyChainPolicyTest.java @@ -1,5 +1,6 @@ package hirs.data.persist; +import hirs.data.persist.policy.SupplyChainPolicy; import org.hibernate.Session; import org.testng.Assert; import org.testng.annotations.Test; diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy.java b/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy.java index 88608b99..41818d4b 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy.java @@ -1,5 +1,7 @@ package hirs.data.persist; +import hirs.data.persist.policy.Policy; + import javax.persistence.Entity; /** diff --git a/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy2.java b/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy2.java index 4006a19b..ea453784 100644 --- a/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy2.java +++ b/HIRS_Utils/src/test/java/hirs/data/persist/TestPolicy2.java @@ -1,5 +1,7 @@ package hirs.data.persist; +import hirs.data.persist.policy.Policy; + import javax.persistence.Entity; /** diff --git a/HIRS_Utils/src/test/java/hirs/data/service/DeviceRegisterImplTest.java b/HIRS_Utils/src/test/java/hirs/data/service/DeviceRegisterImplTest.java index bb74ad68..5e5896fe 100644 --- a/HIRS_Utils/src/test/java/hirs/data/service/DeviceRegisterImplTest.java +++ b/HIRS_Utils/src/test/java/hirs/data/service/DeviceRegisterImplTest.java @@ -1,14 +1,12 @@ package hirs.data.service; import hirs.data.persist.Device; -import hirs.data.persist.DeviceGroup; import hirs.data.persist.DeviceInfoReport; import hirs.data.persist.info.FirmwareInfo; import hirs.data.persist.info.HardwareInfo; import hirs.data.persist.info.NetworkInfo; import hirs.data.persist.info.OSInfo; import hirs.data.persist.info.TPMInfo; -import hirs.persist.DeviceGroupManager; import hirs.persist.DeviceManager; import org.testng.annotations.Test;