[#198] Reference Integrity Manifest Page List (#210)

* Initial commit of changes to display RIM information.
This commit is contained in:
Cyrus 2020-01-10 13:47:17 -05:00 committed by GitHub
parent d9b4e6a968
commit 84a76608f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 590 additions and 1 deletions

View File

@ -44,6 +44,11 @@ public enum Page {
* Page to display registered devices.
*/
DEVICES("Devices", "ic_devices", "first"),
/**
* Page to display RIMs.
*/
REFERENCE_MANIFESTS("Reference Integrity Manifests",
"ic_important_devices", "first"),
/**
* Page that manages Attestation CA Policy.
*/

View File

@ -22,6 +22,10 @@ import org.springframework.web.servlet.view.RedirectView;
* @param <P> PageParams class used by the subclass.
*/
public abstract class PageController<P extends PageParams> {
/**
* Model attribute name used by initPage for the initial data passed to the page.
*/
public static final String INITIAL_DATA = "initialData";
/**
* Reserved attribute used by page.tag to identify a page's general

View File

@ -0,0 +1,132 @@
package hirs.attestationca.portal.page.controllers;
import hirs.attestationca.portal.datatables.DataTableInput;
import hirs.attestationca.portal.datatables.DataTableResponse;
import hirs.attestationca.portal.page.Page;
import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.params.ReferenceManifestPageParams;
import hirs.FilteredRecordsList;
import hirs.persist.ReferenceManifestManager;
import hirs.data.persist.ReferenceManifest;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
/**
* Controller for the Certificate Details page.
*/
@Controller
@RequestMapping("/reference-manifests")
public class ReferenceManifestPageController
extends PageController<ReferenceManifestPageParams> {
private static final String BIOS_RELEASE_DATE_FORMAT = "yyyy-MM-dd";
private final BiosDateValidator biosValidator;
private final ReferenceManifestManager referenceManifestManager;
private static final Logger LOGGER =
LogManager.getLogger(ReferenceManifestPageController.class);
/**
* This class was created for the purposes of avoiding findbugs message:
* As the JavaDoc states, DateFormats are inherently unsafe for
* multithreaded use. The detector has found a call to an instance
* of DateFormat that has been obtained via a static field.
* This looks suspicous.
*
* This class can have uses elsewhere but for now it will remain here.
*/
private static final class BiosDateValidator {
private final String dateFormat;
/**
* Default constructor that sets the format to parse against.
* @param dateFormat
*/
public BiosDateValidator(final String dateFormat) {
this.dateFormat = dateFormat;
}
/**
* Validates a date by attempting to parse based on format provided.
* @param date string of the given date
* @return true if the format matches
*/
public boolean isValid(final String date) {
DateFormat validFormat = new SimpleDateFormat(this.dateFormat);
boolean result = true;
validFormat.setLenient(false);
try {
validFormat.parse(date);
} catch (ParseException pEx) {
result = false;
}
return result;
}
}
/**
* Constructor providing the Page's display and routing specification.
* @param referenceManifestManager the reference manifest manager
*/
@Autowired
public ReferenceManifestPageController(
final ReferenceManifestManager referenceManifestManager) {
super(Page.REFERENCE_MANIFESTS);
this.referenceManifestManager = referenceManifestManager;
this.biosValidator = new BiosDateValidator(BIOS_RELEASE_DATE_FORMAT);
}
/**
* Returns the path for the view and the data model for the page.
*
* @param params The object to map url parameters into.
* @param model The data model for the request. Can contain data from redirect.
* @return the path for the view and data model for the page.
*/
@Override
public ModelAndView initPage(final ReferenceManifestPageParams params,
final Model model) {
return getBaseModelAndView();
}
/**
* Returns the list of RIMs using the datatable input for paging,
* ordering, and filtering.
* @param input the data tables input
* @return the data tables response, including the result set
* and paging information
*/
@ResponseBody
@RequestMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET)
public DataTableResponse<ReferenceManifest> getTableData(
final DataTableInput input) {
LOGGER.debug("Handling request for summary list: " + input);
String orderColumnName = input.getOrderColumnName();
LOGGER.debug("Ordering on column: " + orderColumnName);
FilteredRecordsList<ReferenceManifest> records
= new FilteredRecordsList<>();
LOGGER.debug("Returning list of size: " + records.size());
return new DataTableResponse<>(records, input);
}
}

View File

@ -0,0 +1,91 @@
package hirs.attestationca.portal.page.params;
import hirs.attestationca.portal.page.PageParams;
import java.util.LinkedHashMap;
/**
* URL parameters object for the ReferenceManifest page and controller.
*/
public class ReferenceManifestPageParams implements PageParams {
private String id;
private String type;
/**
* Constructor to set all Reference Integrity Manifest URL parameters.
*
* @param id the String parameter to set
* @param type the Integer parameter to set
*/
public ReferenceManifestPageParams(final String id, final String type) {
this.id = id;
this.type = type;
}
/**
*Constructor to set all Reference Integrity Manifest URL parameters.
*
* @param id the String parameter to set
*/
public ReferenceManifestPageParams(final String id) {
this.id = id;
}
/**
* Default constructor for Spring.
*/
public ReferenceManifestPageParams() {
id = null;
type = null;
}
/**
* Returns the String id parameter.
*
* @return the String id parameter.
*/
public String getId() {
return id;
}
/**
* Sets the String id parameter.
*
* @param id the String id parameter.
*/
public void setId(final String id) {
this.id = id;
}
/**
* Returns the String type parameter.
*
* @return the String type parameter.
*/
public String getType() {
return type;
}
/**
* Sets the String type parameter.
*
* @param type the String type parameter.
*/
public void setType(final String type) {
this.type = type;
}
/**
* Allows PageController to iterate over the url parameters.
*
* @return map containing the object's URL parameters.
*/
@Override
public LinkedHashMap<String, ?> asMap() {
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
map.put("id", id);
map.put("type", type);
return map;
}
}

View File

@ -5,6 +5,7 @@ import hirs.persist.AppraiserManager;
import hirs.persist.CrudManager;
import hirs.persist.DBAppraiserManager;
import hirs.persist.DBCertificateManager;
import hirs.persist.DBReferenceManifestManager;
import hirs.persist.DBDeviceGroupManager;
import hirs.persist.DBDeviceManager;
import hirs.persist.DBManager;
@ -60,6 +61,16 @@ public class PersistenceConfiguration {
return new DBCertificateManager(sessionFactory.getObject());
}
/**
* Creates a {@link DBReferenceManifestManager} ready to use.
*
* @return {@link DBReferenceManifestManager}
*/
@Bean
public DBReferenceManifestManager referenceManifestManager() {
return new DBReferenceManifestManager(sessionFactory.getObject());
}
/**
* Creates a {@link AppraiserManager} ready to use.
*

View File

@ -20,6 +20,7 @@ import hirs.data.persist.certificate.IssuedAttestationCertificate;
import hirs.data.persist.certificate.attributes.ComponentIdentifier;
import hirs.data.persist.certificate.attributes.PlatformConfiguration;
import hirs.persist.CertificateManager;
import hirs.persist.ReferenceManifestManager;
import hirs.utils.BouncyCastleUtils;
import java.util.Collections;
@ -490,4 +491,20 @@ public final class CertificateStringMapBuilder {
}
return data;
}
/**
* Returns the Reference Integrity Manifest information.
*
* @param uuid ID for the reference integrity manifest.
* @param referenceManifestManager the reference manifest
* manager for retrieving certs.
* @return a hash map with the reference manifest manager.
*/
public static HashMap<String, String> getReferenceManifestInformation(final UUID uuid,
final ReferenceManifestManager referenceManifestManager) {
HashMap<String, String> data = new HashMap<>();
return data;
}
}

View File

@ -35,6 +35,12 @@
<img src="${icons}/ic_file_download_black_24dp.png" title="Download Certificate">
</a>
</c:when>
<c:when test="${param.type=='referencemanifest'}">
Reference Integrity Manifest
<a href="${portal}/certificate-request/reference-manifests/download?id=${param.id}">
<img src="${icons}/ic_file_download_black_24dp.png" title="Download Certificate">
</a>
</c:when>
<c:otherwise>
Unknown Certificate
</c:otherwise>

View File

@ -40,6 +40,12 @@
</a>
</h3>
<h4>Upload, view and manage endorsement credentials.</h4>
<h3>
<a href="${portal}/reference-manifests">
<img src="${icons}/ic_important_devices_black_24dp.png" /> Reference Integrity Manifests
</a>
</h3>
<h4>Upload, view and manage reference integrity manifests.</h4>
</div>
<div class="col col-md-6 index-right-side">
<div class="row">

View File

@ -0,0 +1,75 @@
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%-- JSP TAGS --%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="my" tagdir="/WEB-INF/tags"%>
<%-- CONTENT --%>
<my:page>
<jsp:attribute name="script">
<script type="text/javascript" src="${lib}/jquery.spring-friendly/jquery.spring-friendly.js"></script>
</jsp:attribute>
<jsp:attribute name="pageHeaderTitle">Reference Integrity Manifests</jsp:attribute>
<jsp:body>
<!-- text and icon resource variables -->
<div class="aca-input-box-header">
<form:form method="POST" action="${portal}/reference-manifests/upload" enctype="multipart/form-data">
Import RIMs
<my:file-chooser id="referenceManifestsEditor" label="Import RIMs">
<input id="importFile" type="file" name="file" multiple="multiple" />
</my:file-chooser>
</form:form>
</div>
<br/>
<div class="aca-data-table">
<table id="referenceManifestTable" class="display" width="100%">
<thead>
<tr>
<th>Tag ID</th>
<th>Type</th>
<th>Manufacturer</th>
<th>Model</th>
<th>Version</th>
<th>Options</th>
</tr>
</thead>
</table>
</div>
<script>
$(document).ready(function() {
var url = pagePath +'/list';
var columns = [
{data: 'tagId'},
{data: 'rimType'},
{data: 'manufacturer'},
{data: 'model'},
{data: 'firmwareVersion'},
{
data: 'id',
orderable: false,
searchable:false,
render: function(data, type, full, meta) {
// Set up a delete icon with link to handleDeleteRequest().
// sets up a hidden input field containing the ID which is
// used as a parameter to the REST POST call to delete
var html = '';
html += certificateDetailsLink('referencemanifest', full.id, true);
html += certificateDownloadLink(full.id, pagePath);
html += certificateDeleteLink(full.id, pagePath);
return html;
}
}
];
//Set data tables
setDataTables("#referenceManifestTable", url, columns);
});
</script>
</jsp:body>
</my:page>

View File

@ -0,0 +1,175 @@
package hirs.data.persist;
import java.io.StringReader;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
*/
@Entity
@Access(AccessType.FIELD)
public class ReferenceManifest extends ArchivableEntity {
private static final Logger LOGGER = LogManager.getLogger();
@Column
private String manufacturer = null;
@Column
private String model = null;
@Column
private String firmwareVersion = null;
@Column
private String tagId = null;
@Column
private String rimType = null;
/**
* Holds the different RIM types.
*/
public enum RimType {
/**
* Primary Reference Integrity Manifest.
*/
PRIMARY_RIM("Primary"),
/**
* Supplemental Reference Integrity Manifest.
*/
SUPPLEMENTAL_RIM("Supplemental"),
/**
* Patch Reference Integrity Manifest.
*/
PATCH_RIM("Patch");
private String type;
/**
* Default constructor.
* @param type a string for the type.
*/
RimType(final String type) {
this.type = type;
}
/**
* Assessor for RIM Type.
* @return string for type
*/
public String getType() {
return type;
}
}
/**
* Default constructor of given name.
*/
public ReferenceManifest() {
}
/**
* Returns a new <code>Device</code> instance from the XML string. This
* unmarshals the XML string and generates a <code>ReferenceManifest</code>
* object.
* This is a utility method for creating <code>ReferenceManifest</code>
* objects.
*
* @param xml
* XML representation of device
* @return device
* @throws JAXBException
* if unable to unmarshal the string
*/
public static ReferenceManifest getInstance(final String xml) throws JAXBException {
final JAXBContext context = JAXBContext.newInstance(Device.class);
final Unmarshaller unmarshaller = context.createUnmarshaller();
final StringReader reader = new StringReader(xml);
return (ReferenceManifest) unmarshaller.unmarshal(reader);
}
/**
* Getter for the manufacturuer info.
* @return string for the manufacturuer
*/
public String getManufacturer() {
return manufacturer;
}
/**
* Setter for the manufacturuer info.
* @param manufacturer passed in info.
*/
public void setManufacturer(final String manufacturer) {
this.manufacturer = manufacturer;
}
/**
* Getter for the model info.
* @return string for the model
*/
public String getModel() {
return model;
}
/**
* Setter for the Model info.
* @param model passed in model
*/
public void setModel(final String model) {
this.model = model;
}
/**
* Getter for the firmware version info.
* @return string for the firmware version
*/
public String getFirmwareVersion() {
return firmwareVersion;
}
/**
* Setter for the firmware version info.
* @param firmwareVersion passed in firmware version
*/
public void setFirmwareVersion(final String firmwareVersion) {
this.firmwareVersion = firmwareVersion;
}
/**
* Getter for the RIM Tag ID.
* @return string for the RIM tag id
*/
public String getTagId() {
return tagId;
}
/**
* Setter for the RIM Tag ID.
* @param tagId passed in RIM Tag ID
*/
public void setTagId(final String tagId) {
this.tagId = tagId;
}
/**
* Getter for the RIM Type (Primary, Supplemental, Patch).
* @return string for the RIM Type
*/
public String getRimType() {
return rimType;
}
/**
* Setter for the RIM Type.
* @param type passed in RIM Type
*/
public void setRimType(final String type) {
this.rimType = type;
}
}

View File

@ -16,7 +16,7 @@ import java.util.UUID;
* A <code>BaselineManager</code> manages <code>Baseline</code>s. A <code>BaselineManager</code> can
* read, update, and archive <code>Baseline</code>s.
*/
public interface BaselineManager {
public interface BaselineManager extends OrderedListQuerier<Baseline> {
/**
* Stores a new <code>Baseline</code>. This stores a new

View File

@ -0,0 +1,21 @@
package hirs.persist;
import hirs.data.persist.ReferenceManifest;
import org.hibernate.SessionFactory;
/**
* This class is used to persist and retrieve {@link ReferenceManifest}s into
* and from the database.
*/
public class DBReferenceManifestManager extends DBManager<ReferenceManifest>
implements ReferenceManifestManager {
/**
* Default Constructor.
* @param sessionFactory session factory used to access database connections
*/
public DBReferenceManifestManager(final SessionFactory sessionFactory) {
super(ReferenceManifest.class, sessionFactory);
}
}

View File

@ -141,6 +141,19 @@ public class PersistenceConfiguration {
return manager;
}
/**
* Creates a {@link ReferenceManifestManager} ready to use.
*
* @return {@link ReferenceManifestManager}
*/
@Bean
public ReferenceManifestManager referenceManifestManager() {
DBReferenceManifestManager manager
= new DBReferenceManifestManager(sessionFactory.getObject());
setDbManagerRetrySettings(manager);
return manager;
}
/**
* Creates a {@link DeviceStateManager} ready to use.
*

View File

@ -0,0 +1,33 @@
package hirs.persist;
import hirs.data.persist.ReferenceManifest;
/**
* This class facilitates the persistence of {@link ReferenceManifest}s
* including storage, retrieval, and deletion.
*/
public interface ReferenceManifestManager {
/**
* Persists a new Reference Manifest.
*
* @param referenceManifest the ReferenceManifest
* @return the persisted ReferenceManifest
*/
ReferenceManifest save(ReferenceManifest referenceManifest);
/**
* Updates an existing ReferenceManifest.
* @param referenceManifest the rim to update
*/
void update(ReferenceManifest referenceManifest);
/**
* Delete the given RIM.
*
* @param referenceManifest the RIM to delete
* @return true if the deletion succeeded, false otherwise.
*/
boolean delete(ReferenceManifest referenceManifest);
}