diff --git a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java index 1a2b6387..bc701ff1 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/AbstractAttestationCertificateAuthority.java @@ -988,14 +988,15 @@ public abstract class AbstractAttestationCertificateAuthority rdr = referenceDigestManager.saveRecord(dbObj); } // right now this will not deal with updating - if (this.referenceEventManager.getValuesByRecordId(rdr).isEmpty()) { + if (this.referenceEventManager.getValuesByRimId(dbSupport).isEmpty()) { try { TCGEventLog logProcessor = new TCGEventLog(dbSupport.getRimBytes()); ReferenceDigestValue rdv; for (TpmPcrEvent tpe : logProcessor.getEventList()) { - rdv = new ReferenceDigestValue(rdr.getId(), tpe.getPcrIndex(), + rdv = new ReferenceDigestValue(dbSupport.getAssociatedRim(), + dbSupport.getId(), manufacturer, model, tpe.getPcrIndex(), tpe.getEventDigestStr(), tpe.getEventTypeStr(), - false, false); + false, false, tpe.getEventContent()); this.referenceEventManager.saveValue(rdv); } } catch (CertificateException cEx) { @@ -1027,25 +1028,22 @@ public abstract class AbstractAttestationCertificateAuthority } } } else if (dbSupport.isSwidSupplemental() && !dbSupport.isProcessed()) { - if (rdr != null) { - try { - TCGEventLog logProcessor = new TCGEventLog(dbSupport.getRimBytes()); - ReferenceDigestValue rdv; - for (TpmPcrEvent tpe : logProcessor.getEventList()) { - rdv = new ReferenceDigestValue(rdr.getId(), tpe.getPcrIndex(), - tpe.getEventDigestStr(), tpe.getEventTypeStr(), - false, false); - this.referenceEventManager.saveValue(rdv); - } - dbSupport.setProcessed(true); - this.referenceManifestManager.update(dbSupport); - } catch (CertificateException cEx) { - LOG.error(cEx); - } catch (NoSuchAlgorithmException noSaEx) { - LOG.error(noSaEx); - } catch (IOException ioEx) { - LOG.error(ioEx); + try { + TCGEventLog logProcessor = new TCGEventLog(dbSupport.getRimBytes()); + ReferenceDigestValue rdv; + for (TpmPcrEvent tpe : logProcessor.getEventList()) { + rdv = new ReferenceDigestValue(dbSupport.getAssociatedRim(), + dbSupport.getId(), manufacturer, model, tpe.getPcrIndex(), + tpe.getEventDigestStr(), tpe.getEventTypeStr(), + false, false, tpe.getEventContent()); + this.referenceEventManager.saveValue(rdv); } + } catch (CertificateException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); } } } 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 1f4dbb6d..aff91d09 100644 --- a/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java +++ b/HIRS_AttestationCA/src/main/java/hirs/attestationca/service/SupplyChainValidationServiceImpl.java @@ -9,7 +9,6 @@ import hirs.data.persist.Device; import hirs.data.persist.DeviceInfoReport; import hirs.data.persist.EventLogMeasurements; import hirs.data.persist.PCRPolicy; -import hirs.data.persist.ReferenceDigestRecord; import hirs.data.persist.ReferenceDigestValue; import hirs.data.persist.ReferenceManifest; import hirs.data.persist.SupplyChainPolicy; @@ -390,7 +389,6 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe BaseReferenceManifest baseReferenceManifest = null; ReferenceManifest supportReferenceManifest = null; ReferenceManifest measurement = null; - ReferenceDigestRecord digestRecord = null; baseReferenceManifests = BaseReferenceManifest.select(referenceManifestManager) .byDeviceName(device.getDeviceInfo().getNetworkInfo().getHostname()).getRIMs(); @@ -528,7 +526,6 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe // vs baseline tcg event log // find the measurement TCGEventLog tcgMeasurementLog; - digestRecord = this.referenceDigestManager.getRecord(manufacturer, model); LinkedList tpmPcrEvents = new LinkedList<>(); List eventValue; HashMap eventValueMap = new HashMap<>(); @@ -536,7 +533,7 @@ public class SupplyChainValidationServiceImpl implements SupplyChainValidationSe if (measurement.getPlatformManufacturer().equals(manufacturer)) { tcgMeasurementLog = new TCGEventLog(measurement.getRimBytes()); eventValue = this.referenceEventManager - .getValuesByRecordId(digestRecord); + .getValuesByRimId(supportReferenceManifest); for (ReferenceDigestValue rdv : eventValue) { eventValueMap.put(rdv.getDigestValue(), rdv); } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java index 1931e62a..73290a56 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/ReferenceManifestDetailsPageController.java @@ -7,7 +7,6 @@ import hirs.attestationca.portal.page.params.ReferenceManifestDetailsPageParams; import hirs.attestationca.service.SupplyChainValidationServiceImpl; import hirs.data.persist.BaseReferenceManifest; import hirs.data.persist.EventLogMeasurements; -import hirs.data.persist.ReferenceDigestRecord; import hirs.data.persist.ReferenceDigestValue; import hirs.data.persist.ReferenceManifest; import hirs.data.persist.SupportReferenceManifest; @@ -522,7 +521,6 @@ public class ReferenceManifestDetailsPageController BaseReferenceManifest base = null; List supports = new ArrayList<>(); SupportReferenceManifest baseSupport = null; - List digestRecords = new LinkedList<>(); data.put("supportFilename", "Blank"); data.put("supportId", ""); @@ -532,9 +530,8 @@ public class ReferenceManifestDetailsPageController data.put("validationResult", measurements.getOverallValidationResult()); data.put("swidBase", true); + List eventValues = new ArrayList<>(); if (measurements.getDeviceName() != null) { - digestRecords = referenceDigestManager - .getRecordsByDeviceName(measurements.getDeviceName()); supports.addAll(SupportReferenceManifest .select(referenceManifestManager) .byDeviceName(measurements @@ -558,24 +555,20 @@ public class ReferenceManifestDetailsPageController if (base != null) { data.put("associatedRim", base.getId()); } + + eventValues.addAll(referenceEventManager.getValuesByRimId(base)); } } TCGEventLog measurementLog = new TCGEventLog(measurements.getRimBytes()); - List eventValue = new ArrayList<>(); Map eventValueMap = new HashMap<>(); - if (!digestRecords.isEmpty()) { - for (ReferenceDigestRecord rdr : digestRecords) { - eventValue.addAll(referenceEventManager - .getValuesByRecordId(rdr)); - } - for (ReferenceDigestValue rdv : eventValue) { - eventValueMap.put(rdv.getDigestValue(), rdv); - } - for (TpmPcrEvent measurementEvent : measurementLog.getEventList()) { - if (!eventValueMap.containsKey(measurementEvent.getEventDigestStr())) { - livelogEvents.add(measurementEvent); - } + + for (ReferenceDigestValue rdv : eventValues) { + eventValueMap.put(rdv.getDigestValue(), rdv); + } + for (TpmPcrEvent measurementEvent : measurementLog.getEventList()) { + if (!eventValueMap.containsKey(measurementEvent.getEventDigestStr())) { + livelogEvents.add(measurementEvent); } } diff --git a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java index 10d447e9..98ef4169 100644 --- a/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java +++ b/HIRS_AttestationCAPortal/src/main/java/hirs/attestationca/portal/page/controllers/TpmEventsPageController.java @@ -32,7 +32,6 @@ import org.springframework.web.servlet.ModelAndView; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -45,7 +44,6 @@ public class TpmEventsPageController extends PageController { private static final String BIOS_RELEASE_DATE_FORMAT = "yyyy-MM-dd"; - private static final String LOG_FILE_PATTERN = "([^\\s]+(\\.(?i)(rimpcr|rimel|bin|log))$)"; private final BiosDateValidator biosValidator; private final ReferenceDigestManager referenceDigestManager; @@ -137,7 +135,7 @@ public class TpmEventsPageController @RequestMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET) - public DataTableResponse getTableData( + public DataTableResponse getTableData( final DataTableInput input) { LOGGER.info("Handling request for summary list: " + input); @@ -153,18 +151,14 @@ public class TpmEventsPageController }; LOGGER.info("Querying with the following datatableinput: " + input.toString()); - FilteredRecordsList referenceDigestRecords - = OrderedListQueryDataTableAdapter.getOrderedList( - ReferenceDigestRecord.class, - referenceDigestManager, - input, orderColumnName, criteriaModifier); - LOGGER.info("ReferenceDigestManager returned: " - + Arrays.toString(referenceDigestRecords.toArray())); - FilteredRecordsList> - mappedRecordValues = mapRecordToValues(referenceDigestRecords); - LOGGER.info("Returning list mapping: " + Arrays.toString(mappedRecordValues.toArray())); - return new DataTableResponse<>(referenceDigestRecords, input); + FilteredRecordsList referenceDigestValues = + OrderedListQueryDataTableAdapter.getOrderedList( + ReferenceDigestValue.class, + referenceEventManager, + input, orderColumnName, criteriaModifier); + + return new DataTableResponse<>(referenceDigestValues, input); } /** diff --git a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/tpm-events.jsp b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/tpm-events.jsp index a523247a..c9551bb3 100644 --- a/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/tpm-events.jsp +++ b/HIRS_AttestationCAPortal/src/main/webapp/WEB-INF/jsp/tpm-events.jsp @@ -17,12 +17,14 @@
- +
- + + +
Manufacturer ModelSupport RIMEvent TypePCR IndexDigest Value
@@ -32,13 +34,25 @@ $(document).ready(function() { var url = pagePath +'/list'; var columns = [ - {data: 'manufacturer'}, - {data: 'model'}, - {data: 'supportRim'} + {data: 'manufacturer', + orderable: true, + searchable:false}, + {data: 'model', + orderable: false, + searchable:false}, + {data: 'eventType', + orderable: false, + searchable:false,}, + {data: 'pcrIndex', + orderable: true, + searchable:false}, + {data: 'digestValue', + orderable: false, + searchable:false} ]; //Set data tables - setDataTables("#tpmEventTable", url, columns); + setDataTables("#digestValueTable", url, columns); }); diff --git a/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceDigestValue.java b/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceDigestValue.java index 37379ac0..fefacba3 100644 --- a/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceDigestValue.java +++ b/HIRS_Utils/src/main/java/hirs/data/persist/ReferenceDigestValue.java @@ -1,11 +1,16 @@ package hirs.data.persist; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import org.bouncycastle.util.Arrays; import org.hibernate.annotations.Type; +import javax.persistence.Access; +import javax.persistence.AccessType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.Table; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; import java.util.Objects; import java.util.UUID; @@ -14,70 +19,144 @@ import java.util.UUID; * Digest Value, Event Type, index, RIM Tagid */ @Entity -public class ReferenceDigestValue extends AbstractEntity { +@Table(name = "ReferenceDigestValue") +@XmlRootElement(name = "ReferenceDigestValue") +@XmlAccessorType(XmlAccessType.FIELD) +@Access(AccessType.FIELD) +public class ReferenceDigestValue extends ArchivableEntity { - private static final Logger LOGGER = LogManager.getLogger(ReferenceDigestValue.class); @Type(type = "uuid-char") @Column - private UUID digestRecordId; + private UUID baseRimId; + @Type(type = "uuid-char") + @Column + private UUID supportRimId; + @Column(nullable = false) + private String manufacturer; + @Column(nullable = false) + private String model; @Column(nullable = false) private int pcrIndex; @Column(nullable = false) private String digestValue; @Column(nullable = false) private String eventType; + @Column(columnDefinition = "blob", nullable = true) + private byte[] contentBlob; @Column(nullable = false) private boolean matchFail; @Column(nullable = false) private boolean patched = false; /** - * Default Constructor. + * Default constructor necessary for Hibernate. */ - public ReferenceDigestValue() { + protected ReferenceDigestValue() { super(); - this.digestRecordId = UUID.randomUUID(); + this.baseRimId = null; + this.supportRimId = null; + this.manufacturer = ""; + this.model = ""; this.pcrIndex = -1; this.digestValue = ""; this.eventType = ""; this.matchFail = false; this.patched = false; + this.contentBlob = null; } /** * Default Constructor with parameters for all associated data. - * @param digestRecordId the UUID of the associated record + * @param baseRimId the UUID of the associated record + * @param supportRimId the UUID of the associated record + * @param manufacturer associated creator for this information + * @param model the specific device type * @param pcrIndex the event number * @param digestValue the key digest value * @param eventType the event type to store * @param matchFail the status of the baseline check * @param patched the status of the value being updated to to patch + * @param contentBlob the data value of the content */ - public ReferenceDigestValue(final UUID digestRecordId, final int pcrIndex, - final String digestValue, final String eventType, - final boolean matchFail, final boolean patched) { - this.digestRecordId = digestRecordId; + public ReferenceDigestValue(final UUID baseRimId, final UUID supportRimId, + final String manufacturer, final String model, + final int pcrIndex, final String digestValue, + final String eventType, final boolean matchFail, + final boolean patched, final byte[] contentBlob) { + this.baseRimId = baseRimId; + this.supportRimId = supportRimId; + this.manufacturer = manufacturer; + this.model = model; this.pcrIndex = pcrIndex; this.digestValue = digestValue; this.eventType = eventType; this.matchFail = matchFail; this.patched = patched; + this.contentBlob = Arrays.clone(contentBlob); } /** * Getter for the digest record UUID. * @return the string of the UUID */ - public UUID getDigestRecordId() { - return digestRecordId; + public UUID getBaseRimId() { + return baseRimId; } /** * Setter for the digest record UUID. - * @param digestRecordId the value to store + * @param baseRimId the value to store */ - public void setDigestRecordId(final UUID digestRecordId) { - this.digestRecordId = digestRecordId; + public void setBaseRimId(final UUID baseRimId) { + this.baseRimId = baseRimId; + } + + /** + * Getter for the digest record UUID. + * @return the string of the UUID + */ + public UUID getSupportRimId() { + return supportRimId; + } + + /** + * Setter for the digest record UUID. + * @param supportRimId the value to store + */ + public void setSupportRimId(final UUID supportRimId) { + this.supportRimId = supportRimId; + } + + /** + * Getter for the manufacturer value. + * @return the stored value + */ + public String getManufacturer() { + return manufacturer; + } + + /** + * Setter for the manufacturer value. + * @param manufacturer the value to store + */ + public void setManufacturer(final String manufacturer) { + this.manufacturer = manufacturer; + } + + /** + * Getter for the model value. + * @return the stored value + */ + public String getModel() { + return model; + } + + /** + * Setter for the model value. + * @param model the value to store + */ + public void setModel(final String model) { + this.model = model; } /** @@ -160,6 +239,24 @@ public class ReferenceDigestValue extends AbstractEntity { this.patched = patched; } + /** + * Getter for the byte array of event values. + * @return a clone of the byte array + */ + public byte[] getContentBlob() { + return contentBlob.clone(); + } + + /** + * Setter for the byte array of values. + * @param contentBlob non-null array. + */ + public void setContentBlob(final byte[] contentBlob) { + if (contentBlob != null) { + this.contentBlob = contentBlob.clone(); + } + } + @Override public boolean equals(final Object obj) { if (this == obj) { @@ -171,13 +268,14 @@ public class ReferenceDigestValue extends AbstractEntity { ReferenceDigestValue that = (ReferenceDigestValue) obj; return pcrIndex == that.pcrIndex && matchFail == that.matchFail && Objects.equals(digestValue, that.digestValue) - && Objects.equals(digestRecordId, that.digestRecordId) + && Objects.equals(baseRimId, that.baseRimId) + && Objects.equals(supportRimId, that.supportRimId) && Objects.equals(eventType, that.eventType); } @Override public int hashCode() { - int result = Objects.hash(pcrIndex, digestValue, digestRecordId, + int result = Objects.hash(pcrIndex, digestValue, baseRimId, supportRimId, eventType, matchFail, patched); return result; } diff --git a/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java b/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java index 73b0e308..2ac2d0c6 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/AbstractDbManager.java @@ -767,7 +767,7 @@ public abstract class AbstractDbManager implements CrudManager { searchClass = this.clazz; } - LOGGER.info(clazz.getName() + " querying for " + LOGGER.info(searchClass.getName() + " querying for " + Arrays.toString(searchableColumns.entrySet().toArray()) + " with search strings \"" + search + "\""); @@ -793,7 +793,7 @@ public abstract class AbstractDbManager implements CrudManager { if (totalResultCount != 0) { LOGGER.info("Total result count greater than 0"); //Builds the search criteria from all of the searchable columns - if (searchableColumns != null) { + if (!searchableColumns.isEmpty()) { // Search for all words in all searchable columns String[] searchWords = search.split(" "); for (String word : searchWords) { @@ -818,9 +818,7 @@ public abstract class AbstractDbManager implements CrudManager { LOGGER.info("Get unique result from criteria object"); recordsFiltered = (Long) criteria.uniqueResult(); } catch (HibernateException e) { - LOGGER.info(e.getMessage()); - } catch (Exception e) { - LOGGER.info("Error while getting unique result: " + e.getMessage()); + LOGGER.error(e.getMessage()); } } @@ -881,7 +879,7 @@ public abstract class AbstractDbManager implements CrudManager { } throw e; } - LOGGER.info(clazz.getName() + " found " + aqr.getRecordsTotal() + " records"); + LOGGER.info(searchClass.getName() + " found " + aqr.getRecordsTotal() + " records"); return aqr; } diff --git a/HIRS_Utils/src/main/java/hirs/persist/DBReferenceEventManager.java b/HIRS_Utils/src/main/java/hirs/persist/DBReferenceEventManager.java index f742ca59..e3609fcf 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/DBReferenceEventManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/DBReferenceEventManager.java @@ -1,16 +1,23 @@ package hirs.persist; +import hirs.FilteredRecordsList; +import hirs.data.persist.BaseReferenceManifest; import hirs.data.persist.ReferenceDigestRecord; import hirs.data.persist.ReferenceDigestValue; +import hirs.data.persist.ReferenceManifest; +import hirs.data.persist.SupportReferenceManifest; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.criterion.Restrictions; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; /** @@ -30,6 +37,7 @@ public class DBReferenceEventManager extends DBManager public DBReferenceEventManager(final SessionFactory sessionFactory) { super(ReferenceDigestValue.class, sessionFactory); } + @Override public ReferenceDigestValue saveValue(final ReferenceDigestValue referenceDigestValue) { LOGGER.debug("saving event digest value: {}", referenceDigestValue); @@ -48,7 +56,7 @@ public class DBReferenceEventManager extends DBManager return null; } - if (referenceDigestValue.getDigestRecordId() == null + if (referenceDigestValue.getSupportRimId() == null || referenceDigestValue.getDigestValue() == null || referenceDigestValue.getPcrIndex() == -1) { LOGGER.error("No reference to get record from db {}", referenceDigestValue); @@ -62,8 +70,8 @@ public class DBReferenceEventManager extends DBManager LOGGER.debug("retrieving referenceDigestValue from db"); tx = session.beginTransaction(); dbRecord = (ReferenceDigestValue) session.createCriteria(ReferenceDigestValue.class) - .add(Restrictions.eq("digestRecordId", - referenceDigestValue.getDigestRecordId())) + .add(Restrictions.eq("supportRimId", + referenceDigestValue.getSupportRimId())) .add(Restrictions.eq("digestValue", referenceDigestValue.getDigestValue())) .add(Restrictions.eq("eventNumber", @@ -118,24 +126,107 @@ public class DBReferenceEventManager extends DBManager } @Override - public List getValuesByRecordId( - final ReferenceDigestRecord referenceDigestRecord) { - LOGGER.debug("Getting digest values for {}", referenceDigestRecord); - if (referenceDigestRecord == null) { - LOGGER.error("null referenceDigestRecord argument"); - throw new NullPointerException("null referenceDigestRecord"); - } - if (referenceDigestRecord.getId() == null) { - LOGGER.error("null referenceDigestRecord ID argument"); - throw new NullPointerException("null referenceDigestRecord ID"); + public List getValueByManufacturer(final String manufacturer) { + if (manufacturer == null) { + LOGGER.error("null manufacturer argument"); + throw new NullPointerException("null manufacturer parameter"); } List dbDigestValues = new ArrayList<>(); - UUID uuid = referenceDigestRecord.getId(); try { List dbTempList = super.getList(ReferenceDigestValue.class); for (ReferenceDigestValue rdv : dbTempList) { - if (rdv.getDigestRecordId().equals(uuid)) { + if (rdv.getManufacturer().equals(manufacturer)) { + dbDigestValues.add(rdv); + } + } + } catch (DBManagerException dbMEx) { + throw new RuntimeException(dbMEx); + } + return dbDigestValues; + } + + @Override + public List getValueByModel(final String model) { + if (model == null) { + LOGGER.error("null model argument"); + throw new NullPointerException("null model parameter"); + } + + List dbDigestValues = new ArrayList<>(); + try { + List dbTempList = super.getList(ReferenceDigestValue.class); + for (ReferenceDigestValue rdv : dbTempList) { + if (rdv.getModel().equals(model)) { + dbDigestValues.add(rdv); + } + } + } catch (DBManagerException dbMEx) { + throw new RuntimeException(dbMEx); + } + return dbDigestValues; + } + + @Override + public List getValueByManufacturerModel( + final String manufacturer, final String model) { + if (model == null) { + LOGGER.error("null model argument"); + throw new NullPointerException("null model parameter"); + } + if (manufacturer == null) { + LOGGER.error("null manufacturer argument"); + throw new NullPointerException("null manufacturer parameter"); + } + + List dbDigestValues = new ArrayList<>(); + try { + List dbTempList = super.getList(ReferenceDigestValue.class); + for (ReferenceDigestValue rdv : dbTempList) { + if (rdv.getManufacturer().equals(manufacturer) + && rdv.getModel().equals(model)) { + dbDigestValues.add(rdv); + } + } + } catch (DBManagerException dbMEx) { + throw new RuntimeException(dbMEx); + } + return dbDigestValues; + } + + @Override + public List getValuesByRecordId( + final ReferenceDigestRecord referenceDigestRecord) { + List dbDigestValues = new ArrayList<>(0); + + return dbDigestValues; + } + + @Override + public List getValuesByRimId( + final ReferenceManifest referenceManifest) { + LOGGER.debug("Getting digest values for {}", referenceManifest); + if (referenceManifest == null) { + LOGGER.error("null referenceManifest argument"); + throw new NullPointerException("null referenceManifest"); + } + if (referenceManifest.getId() == null) { + LOGGER.error("null referenceManifest ID argument"); + throw new NullPointerException("null referenceManifest ID"); + } + + List dbDigestValues = new ArrayList<>(); + UUID uuid = referenceManifest.getId(); + UUID rdvUuid = UUID.randomUUID(); + try { + List dbTempList = super.getList(ReferenceDigestValue.class); + for (ReferenceDigestValue rdv : dbTempList) { + if (referenceManifest instanceof BaseReferenceManifest) { + rdvUuid = rdv.getBaseRimId(); + } else if (referenceManifest instanceof SupportReferenceManifest) { + rdvUuid = rdv.getSupportRimId(); + } + if (rdvUuid.equals(uuid)) { dbDigestValues.add(rdv); } } @@ -167,6 +258,53 @@ public class DBReferenceEventManager extends DBManager return dbDigestValues; } + /** + * 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 + */ + @Override + public final FilteredRecordsList getOrderedDigestValueList( + final String columnToOrder, + final boolean ascending, final int firstResult, + final int maxResults, final String search) { + 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("group.name", true); + searchableColumns.put("last_report_timestamp", false); + + CriteriaModifier modifier = new CriteriaModifier() { + @Override + public void modify(final Criteria criteria) { + criteria.createAlias("valueGroup", "group"); + } + }; + + try { + LOGGER.debug("Getting baseline list"); + return super.getOrderedList(ReferenceDigestValue.class, columnToOrder, ascending, + firstResult, + maxResults, search, searchableColumns, modifier); + } catch (DBManagerException e) { + throw new AlertManagerException(e); + } + } + @Override public void updateRecord(final ReferenceDigestValue referenceDigestValue) { try { diff --git a/HIRS_Utils/src/main/java/hirs/persist/ReferenceDigestManager.java b/HIRS_Utils/src/main/java/hirs/persist/ReferenceDigestManager.java index 952ddfbd..33717457 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/ReferenceDigestManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/ReferenceDigestManager.java @@ -10,7 +10,7 @@ import java.util.UUID; * This class facilitates the persistence of {@link hirs.data.persist.ReferenceDigestRecord}s * including storage, retrieval, and deletion. */ -public interface ReferenceDigestManager extends OrderedListQuerier{ +public interface ReferenceDigestManager extends OrderedListQuerier { /** * Persists a new Reference Digest. diff --git a/HIRS_Utils/src/main/java/hirs/persist/ReferenceEventManager.java b/HIRS_Utils/src/main/java/hirs/persist/ReferenceEventManager.java index 89c02ebc..7d3dd6bb 100644 --- a/HIRS_Utils/src/main/java/hirs/persist/ReferenceEventManager.java +++ b/HIRS_Utils/src/main/java/hirs/persist/ReferenceEventManager.java @@ -1,7 +1,9 @@ package hirs.persist; +import hirs.FilteredRecordsList; import hirs.data.persist.ReferenceDigestRecord; import hirs.data.persist.ReferenceDigestValue; +import hirs.data.persist.ReferenceManifest; import java.util.List; @@ -9,7 +11,7 @@ import java.util.List; * This class facilitates the persistence of {@link hirs.data.persist.ReferenceDigestValue}s * including storage, retrieval, and deletion. */ -public interface ReferenceEventManager { +public interface ReferenceEventManager extends OrderedListQuerier { /** * Persists a new Reference Digest value. * @@ -34,6 +36,31 @@ public interface ReferenceEventManager { */ ReferenceDigestValue getValueById(ReferenceDigestValue referenceDigestValue); + /** + * Persists a new Reference Digest Value. + * + * @param manufacturer the string value to search for + * @return the persisted ReferenceDigestValue + */ + List getValueByManufacturer(String manufacturer); + + /** + * Persists a new Reference Digest. + * + * @param model the string value to search for + * @return the persisted ReferenceDigestValue + */ + List getValueByModel(String model); + + /** + * Persists a new Reference Digest. + * + * @param manufacturer the string value to search for + * @param model the string value to search for + * @return the persisted ReferenceDigestValue + */ + List getValueByManufacturerModel(String manufacturer, String model); + /** * Persists a new Reference Digest value. * @@ -42,6 +69,14 @@ public interface ReferenceEventManager { */ List getValuesByRecordId(ReferenceDigestRecord referenceDigestRecord); + /** + * Persists a new Reference Digest value. + * + * @param referenceManifest the referenceManifest + * @return the persisted list of ReferenceDigestValue + */ + List getValuesByRimId(ReferenceManifest referenceManifest); + /** * Persists a new Reference Digest value. * @@ -50,6 +85,23 @@ public interface ReferenceEventManager { */ List getValueByEventType(String eventType); + /** + * Returns a list of all ReferenceDigestValues 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 + */ + FilteredRecordsList getOrderedDigestValueList( + String columnToOrder, boolean ascending, int firstResult, + int maxResults, String search); + /** * Updates an existing ReferenceDigestRecord. * @param referenceDigestValue the Reference Event update