mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-19 04:58:00 +00:00
The event selector was removed. It was not needed, but the event
manager was modified to pull the right data.
This commit is contained in:
parent
035efad9d2
commit
c5e3823acd
@ -59,9 +59,9 @@ public enum Page {
|
||||
*/
|
||||
POLICY("Policy", "ic_subtitles"),
|
||||
/**
|
||||
* Page to display TPM event table.
|
||||
* Page to display RIM event digest table.
|
||||
*/
|
||||
TPM_EVENTS("TPM Events", null, "first"),
|
||||
TPM_EVENTS("RIM Database", null, "first"),
|
||||
/**
|
||||
* Help page.
|
||||
*/
|
||||
|
@ -183,14 +183,13 @@ public class ReferenceManifestPageController
|
||||
input, orderColumnName, criteriaModifier);
|
||||
|
||||
SupportReferenceManifest support;
|
||||
Set<ReferenceDigestValue> events;
|
||||
List<ReferenceDigestValue> events;
|
||||
for (ReferenceManifest rim : records) {
|
||||
if (rim instanceof SupportReferenceManifest) {
|
||||
support = (SupportReferenceManifest) rim;
|
||||
events = ReferenceDigestValue
|
||||
.select(referenceEventManager)
|
||||
.bySupportRim(support.getId()).getDigestValues();
|
||||
events = referenceEventManager.getValuesByRimId(support);
|
||||
for (ReferenceDigestValue rdv : events) {
|
||||
// the selector isn't giving me what I want
|
||||
if (support.getPlatformManufacturer() != null) {
|
||||
rdv.setManufacturer(support.getPlatformManufacturer());
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter;
|
||||
import hirs.attestationca.portal.page.Page;
|
||||
import hirs.attestationca.portal.page.PageController;
|
||||
import hirs.attestationca.portal.page.params.NoPageParams;
|
||||
import hirs.data.persist.ReferenceDigestRecord;
|
||||
import hirs.data.persist.ReferenceDigestValue;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
@ -32,8 +31,6 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Controller for the TPM Events page.
|
||||
@ -160,32 +157,4 @@ public class TpmEventsPageController
|
||||
|
||||
return new DataTableResponse<>(referenceDigestValues, input);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method returns a mapping of ReferenceDigestRecord to ReferenceDigestValue objects.
|
||||
*
|
||||
* @param records the list of ReferenceDigestRecords
|
||||
* @return the collection of HashMap mappings
|
||||
*/
|
||||
private FilteredRecordsList<HashMap<ReferenceDigestRecord, ReferenceDigestValue>>
|
||||
mapRecordToValues(final FilteredRecordsList<ReferenceDigestRecord> records) {
|
||||
|
||||
LOGGER.info("Mapping RDRs and RDVs");
|
||||
FilteredRecordsList<HashMap<ReferenceDigestRecord, ReferenceDigestValue>> filteredList =
|
||||
new FilteredRecordsList<>();
|
||||
HashMap<ReferenceDigestRecord, ReferenceDigestValue> mappingRecordToValues =
|
||||
new HashMap<>();
|
||||
for (ReferenceDigestRecord record : records) {
|
||||
List<ReferenceDigestValue> values = referenceEventManager.getValuesByRecordId(record);
|
||||
if (values != null && !values.isEmpty()) {
|
||||
mappingRecordToValues.put(record, values.get(0));
|
||||
} else {
|
||||
mappingRecordToValues.put(record, null);
|
||||
}
|
||||
filteredList.add(new HashMap<>(mappingRecordToValues));
|
||||
mappingRecordToValues.clear();
|
||||
}
|
||||
|
||||
return filteredList;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
<jsp:attribute name="script">
|
||||
<script type="text/javascript" src="${lib}/jquery.spring-friendly/jquery.spring-friendly.js"></script>
|
||||
</jsp:attribute>
|
||||
<jsp:attribute name="pageHeaderTitle">TPM Events</jsp:attribute>
|
||||
<jsp:attribute name="pageHeaderTitle">RIM Database</jsp:attribute>
|
||||
|
||||
<jsp:body>
|
||||
<br/>
|
||||
|
@ -1,7 +1,5 @@
|
||||
package hirs.data.persist;
|
||||
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceEventSelector;
|
||||
import org.bouncycastle.util.Arrays;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
@ -50,67 +48,6 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
@Column(nullable = false)
|
||||
private boolean patched = false;
|
||||
|
||||
/**
|
||||
* This class enables the retrieval of ReferenceDigestValue by their attributes.
|
||||
*/
|
||||
public static class Selector extends ReferenceEventSelector<ReferenceDigestValue> {
|
||||
/**
|
||||
* Construct a new ReferenceEventSelector that will
|
||||
* use the given (@link ReferenceEventManager}
|
||||
* to retrieve one or may ReferenceDigestValue.
|
||||
*
|
||||
* @param referenceEventManager the reference event manager to be used to retrieve
|
||||
* reference event.
|
||||
*/
|
||||
public Selector(final ReferenceEventManager referenceEventManager) {
|
||||
super(referenceEventManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the base rim id that rims must have to be considered
|
||||
* as matching.
|
||||
* @param baseRimId identifier for the support rim
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector byBaseRim(final UUID baseRimId) {
|
||||
setFieldValue("baseRimId", baseRimId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the support rim id that rims must have to be considered
|
||||
* as matching.
|
||||
* @param supportRimId identifier for the support rim
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector bySupportRim(final UUID supportRimId) {
|
||||
setFieldValue("supportRimId", supportRimId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the platform manufacturer that rims must have to be considered
|
||||
* as matching.
|
||||
* @param manufacturer string for the manufacturer
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector byManufacturer(final String manufacturer) {
|
||||
setFieldValue("manufacturer", manufacturer);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the platform model that rims must have to be considered
|
||||
* as matching.
|
||||
* @param model string for the model
|
||||
* @return this instance
|
||||
*/
|
||||
public Selector byModel(final String model) {
|
||||
setFieldValue("model", model);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor necessary for Hibernate.
|
||||
*/
|
||||
@ -158,17 +95,6 @@ public class ReferenceDigestValue extends ArchivableEntity {
|
||||
this.contentBlob = Arrays.clone(contentBlob);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Selector for use in retrieving ReferenceDigestValue.
|
||||
*
|
||||
* @param eventManager the ReferenceEventManager to be used to retrieve
|
||||
* persisted tpm events
|
||||
* @return a Selector instance to use for retrieving tpm events
|
||||
*/
|
||||
public static Selector select(final ReferenceEventManager eventManager) {
|
||||
return new Selector(eventManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the digest record UUID.
|
||||
* @return the string of the UUID
|
||||
|
@ -229,7 +229,8 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
|
||||
UUID uuid = referenceManifest.getId();
|
||||
UUID rdvUuid = UUID.randomUUID();
|
||||
try {
|
||||
List<ReferenceDigestValue> dbTempList = super.getList(ReferenceDigestValue.class);
|
||||
final List<ReferenceDigestValue> dbTempList
|
||||
= super.getList(ReferenceDigestValue.class);
|
||||
for (ReferenceDigestValue rdv : dbTempList) {
|
||||
if (referenceManifest instanceof BaseReferenceManifest) {
|
||||
rdvUuid = rdv.getBaseRimId();
|
||||
@ -256,7 +257,8 @@ public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
|
||||
|
||||
List<ReferenceDigestValue> dbDigestValues = new ArrayList<>();
|
||||
try {
|
||||
List<ReferenceDigestValue> dbTempList = super.getList(ReferenceDigestValue.class);
|
||||
final List<ReferenceDigestValue> dbTempList
|
||||
= super.getList(ReferenceDigestValue.class);
|
||||
for (ReferenceDigestValue rdv : dbTempList) {
|
||||
if (rdv.getEventType().equals(eventType)) {
|
||||
dbDigestValues.add(rdv);
|
||||
|
@ -1,157 +0,0 @@
|
||||
package hirs.persist;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.hibernate.criterion.Conjunction;
|
||||
import org.hibernate.criterion.Criterion;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class is used to select one or many TPM Events in conjunction
|
||||
* with a {@link hirs.persist.ReferenceEventManager}. To make use of this object,
|
||||
* use (some ReferenceDigestValue).select(ReferenceEventManager).
|
||||
*
|
||||
* @param <ReferenceDigestValue> the type of DB Object that will be retrieved.
|
||||
*/
|
||||
public abstract class ReferenceEventSelector<ReferenceDigestValue> {
|
||||
private static final String RIM_TYPE_FIELD = "rimType";
|
||||
private static final String DIGEST_VALUE_FIELD = "digestValue";
|
||||
|
||||
private final ReferenceEventManager referenceEventManager;
|
||||
|
||||
private final Map<String, Object> fieldValueSelections;
|
||||
private boolean excludeArchivedValues;
|
||||
|
||||
|
||||
/**
|
||||
* Standard Constructor for the Selector.
|
||||
*
|
||||
* @param referenceEventManager the RIM manager to be used to retrieve RIMs
|
||||
*/
|
||||
public ReferenceEventSelector(final ReferenceEventManager referenceEventManager) {
|
||||
this(referenceEventManager, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard Constructor for the Selector.
|
||||
*
|
||||
* @param referenceEventManager the RIM manager to be used to retrieve RIMs
|
||||
* @param excludeArchivedValues true if excluding archived RIMs
|
||||
*/
|
||||
public ReferenceEventSelector(final ReferenceEventManager referenceEventManager,
|
||||
final boolean excludeArchivedValues) {
|
||||
Preconditions.checkArgument(
|
||||
referenceEventManager != null,
|
||||
"reference event manager cannot be null"
|
||||
);
|
||||
|
||||
this.referenceEventManager = referenceEventManager;
|
||||
this.excludeArchivedValues = excludeArchivedValues;
|
||||
this.fieldValueSelections = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a field name and value to match.
|
||||
*
|
||||
* @param name the field name to query
|
||||
* @param value the value to query
|
||||
*/
|
||||
protected void setFieldValue(final String name, final Object value) {
|
||||
Object valueToAssign = value;
|
||||
|
||||
Preconditions.checkArgument(
|
||||
value != null,
|
||||
String.format("field value (%s) cannot be null.", name)
|
||||
);
|
||||
|
||||
if (value instanceof String) {
|
||||
Preconditions.checkArgument(
|
||||
StringUtils.isNotEmpty((String) value),
|
||||
"field value cannot be empty."
|
||||
);
|
||||
}
|
||||
|
||||
if (value instanceof byte[]) {
|
||||
byte[] valueBytes = (byte[]) value;
|
||||
|
||||
Preconditions.checkArgument(
|
||||
ArrayUtils.isNotEmpty(valueBytes),
|
||||
String.format("field value (%s) cannot be empty.", name)
|
||||
);
|
||||
|
||||
valueToAssign = Arrays.copyOf(valueBytes, valueBytes.length);
|
||||
}
|
||||
|
||||
fieldValueSelections.put(name, valueToAssign);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the result set as a single
|
||||
* {@link hirs.data.persist.ReferenceDigestValue}. This method is best used
|
||||
* when selecting on a unique attribute. If the result set contains more
|
||||
* than one RIM, one is chosen arbitrarily and returned. If no matching RIMs
|
||||
* are found, this method returns null.
|
||||
*
|
||||
* @return a matching ReferenceDigestValue or null if none is found
|
||||
*/
|
||||
public hirs.data.persist.ReferenceDigestValue getDigestValue() {
|
||||
Set<hirs.data.persist.ReferenceDigestValue> events = getDigestValues();
|
||||
if (events.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return events.iterator().next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the result set as a set of
|
||||
* {@link hirs.data.persist.ReferenceDigestValue}s. This method is best used
|
||||
* when selecting on non-unique attributes. ReferenceManifests are populated
|
||||
* into the set in no specific order. If no matching certificates are found,
|
||||
* the returned Set will be empty.
|
||||
*
|
||||
* @return a Set of matching ReferenceDigestValues, possibly empty
|
||||
*/
|
||||
public Set<hirs.data.persist.ReferenceDigestValue> getDigestValues() {
|
||||
return Collections.unmodifiableSet(new HashSet<hirs.data.persist.ReferenceDigestValue>(
|
||||
this.referenceEventManager.getEventList()));
|
||||
}
|
||||
/**
|
||||
* Construct the criterion that can be used to query for rims matching the
|
||||
* configuration of this {@link ReferenceEventSelector}.
|
||||
*
|
||||
* @return a Criterion that can be used to query for rims matching the
|
||||
* configuration of this instance
|
||||
*/
|
||||
Criterion getCriterion() {
|
||||
Conjunction conj = new Conjunction();
|
||||
|
||||
for (Map.Entry<String, Object> fieldValueEntry : fieldValueSelections.entrySet()) {
|
||||
conj.add(Restrictions.eq(fieldValueEntry.getKey(), fieldValueEntry.getValue()));
|
||||
}
|
||||
|
||||
if (this.excludeArchivedValues) {
|
||||
conj.add(Restrictions.isNull(Certificate.ARCHIVE_FIELD));
|
||||
}
|
||||
|
||||
return conj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the selector to query for archived and unarchived rims.
|
||||
*
|
||||
* @return the selector
|
||||
*/
|
||||
public ReferenceEventSelector includeArchived() {
|
||||
this.excludeArchivedValues = false;
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user