Merge pull request #540 from nsacyber/v3_issue-534

[#534] Initial Display Fixes
This commit is contained in:
5B96790E3664F40075A67E6ADF737EDB15B4408DBC91A81228B31537B0CE3E26 2023-06-21 07:23:27 -04:00 committed by GitHub
commit 0bfb4ac8dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 10 additions and 409 deletions

View File

@ -1,6 +1,7 @@
package hirs.attestationca.persist.entity.manager; package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.Certificate; import hirs.attestationca.persist.entity.userdefined.Certificate;
import hirs.attestationca.persist.entity.userdefined.certificate.EndorsementCredential;
import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential; import hirs.attestationca.persist.entity.userdefined.certificate.PlatformCredential;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
@ -28,9 +29,9 @@ public interface CertificateRepository<T extends Certificate> extends JpaReposit
@Query(value = "SELECT * FROM Certificate where platformSerial = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where platformSerial = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true)
List<PlatformCredential> byBoardSerialNumber(String boardSerialNumber); List<PlatformCredential> byBoardSerialNumber(String boardSerialNumber);
@Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = 'PlatformCredential'", nativeQuery = true)
PlatformCredential byHolderSerialNumber(BigInteger holderSerialNumber); PlatformCredential getPcByHolderSerialNumber(BigInteger holderSerialNumber);
@Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = dType", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where holderSerialNumber = ?1 AND DTYPE = 'EndorsementCredential'", nativeQuery = true)
T byHolderSerialNumber(BigInteger holderSerialNumber, String dType); EndorsementCredential getEcByHolderSerialNumber(BigInteger holderSerialNumber);
@Query(value = "SELECT * FROM Certificate where certificateHash = ?1 AND DTYPE = ?2", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where certificateHash = ?1 AND DTYPE = ?2", nativeQuery = true)
T findByCertificateHash(int certificateHash, String dType); T findByCertificateHash(int certificateHash, String dType);
@Query(value = "SELECT * FROM Certificate where subjectKeyIdentifier = ?1", nativeQuery = true) @Query(value = "SELECT * FROM Certificate where subjectKeyIdentifier = ?1", nativeQuery = true)

View File

@ -1,12 +0,0 @@
package hirs.attestationca.persist.entity.manager;
import hirs.attestationca.persist.entity.userdefined.SupplyChainSettings;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.UUID;
@Repository
public interface SettingsRepository extends JpaRepository<SupplyChainSettings, UUID> {
SupplyChainSettings findByName(String name);
}

View File

@ -1,123 +0,0 @@
package hirs.attestationca.persist.entity.userdefined;
import hirs.attestationca.persist.entity.UserDefinedEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* Class represents Supply Chain policy. Supply Chain Policy identifies the methods in
* SupplyChainValidator that should be used in order to validate a supply chain.
* By default, the policy does not enable any validations.
*/
@Table(name = "SupplyChainSettings")
@Getter
@Setter
@Entity
@ToString(callSuper = true)
public class SupplyChainSettings extends UserDefinedEntity {
/**
* Name of the default Supply Chain Policy.
*/
public static final String DEFAULT_POLICY = "Default Supply Chain Policy";
/**
* Number of days in 10 years.
*/
public static final String TEN_YEARS = "3651";
/**
* Number of days in 1 year.
*/
public static final String YEAR = "365";
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean ecValidationEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean pcValidationEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean pcAttributeValidationEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean firmwareValidationEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean utcValidationEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean expiredCertificateValidationEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean replaceEC = false;
@Column(nullable = false, columnDefinition = "boolean default true")
private boolean issueAttestationCertificate = true;
@Column(nullable = false, columnDefinition = "boolean default true")
private boolean issueDevIdCertificate = true;
@Column(nullable = false)
private String validityDays = TEN_YEARS;
@Column(nullable = false)
private String devIdValidityDays = TEN_YEARS;
@Column(nullable = false)
private String reissueThreshold = YEAR;
@Column(nullable = false)
private String devIdReissueThreshold = YEAR;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean generateOnExpiration = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean devIdExpirationFlag = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean ignoreImaEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean ignoretBootEnabled = false;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean linuxOs = false;
@Column(nullable = false, columnDefinition = "boolean default true")
private boolean ignoreGptEnabled = true;
@Column(nullable = false, columnDefinition = "boolean default false")
private boolean ignoreOsEvtEnabled = false;
/**
* Default constructor necessary for Hibernate.
*/
protected SupplyChainSettings() {
super();
}
/**
* Constructor used to initialize SupplyChainSettings object.
*
* @param name
* A name used to uniquely identify and reference the Supply Chain policy.
*/
public SupplyChainSettings(final String name) {
super(name);
}
/**
* Constructor used to initialize SupplyChainSettings object.
*
* @param name
* A name used to uniquely identify and reference the supply chain policy.
* @param description
* Optional description of the policy that can be added by the user
*/
public SupplyChainSettings(final String name, final String description) {
super(name, description);
}
}

View File

@ -1,23 +0,0 @@
package hirs.attestationca.persist.service;
import hirs.attestationca.persist.entity.userdefined.Certificate;
import hirs.attestationca.persist.service.selector.CertificateSelector;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public interface CertificateService<T extends Certificate> {
Certificate saveCertificate(Certificate certificate);
<T extends Certificate> List<T> fetchCertificates(Class<T> classType);
Certificate updateCertificate(Certificate certificate, UUID certificateId);
Certificate updateCertificate(Certificate certificate);
void deleteCertificate(Certificate certificate);
<T extends Certificate> Set<T> get(CertificateSelector certificateSelector);
}

View File

@ -1,4 +0,0 @@
package hirs.attestationca.persist.service;
public interface DefaultService {
}

View File

@ -1,132 +0,0 @@
package hirs.attestationca.persist.service;
import hirs.attestationca.persist.DBManagerException;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import lombok.extern.log4j.Log4j2;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract class that has the underlying Hibernate commands used by other DB Managers.
* This class exists primarily to reduce code in {@link hirs.attestationca.persist.service.DefaultDbService} which retries these methods
* using a RetryTemplate.
*
* @param <T> type of objects to manage by this manager
*/
@Log4j2
public abstract class HibernateDbService<T> {
private static final int MAX_CLASS_CACHE_ENTRIES = 500;
private final Class<T> clazz;
@PersistenceContext
private EntityManager entityManager;
private CriteriaBuilder criteriaBuilder;
private CriteriaQuery<T> criteriaQuery;
/**
* Creates a new <code>AbstractDbManager</code>.
*
* @param clazz Class to search for when doing Hibernate queries,
* unfortunately class type of T cannot be determined using only T
* @param entityManager the session factory to use to interact with the database
*/
public HibernateDbService(final Class<T> clazz, final EntityManager entityManager) {
if (clazz == null) {
log.error("HibernateDbService cannot be instantiated with a null class");
throw new IllegalArgumentException(
"HibernateDbService cannot be instantiated with a null class"
);
}
// if (entityManager == null) {
// log.error("HibernateDbService cannot be instantiated with a null SessionFactory");
// throw new IllegalArgumentException(
// "HibernateDbService cannot be instantiated with a null SessionFactory"
// );
// }
this.clazz = clazz;
this.entityManager = entityManager;
}
public HibernateDbService() {
clazz = null;
}
/**
* Returns a list of all <code>T</code>s of type <code>clazz</code> in the database, with an
* additional restriction also specified in the query.
* <p>
* This would be useful if <code>T</code> has several subclasses being
* managed. This class argument allows the caller to limit which types of
* <code>T</code> should be returned.
*
* @param clazz class type of <code>T</code>s to search for (may be null to
* use Class&lt;T&gt;)
* @param additionalRestriction - an added Criterion to use in the query, null for none
* @return list of <code>T</code> names
* @throws DBManagerException if unable to search the database
*/
protected List<T> doGetList(final Class<? extends T> clazz)
throws DBManagerException {
log.debug("Getting object list");
Class<? extends T> searchClass = clazz;
if (clazz == null) {
log.debug("clazz is null");
searchClass = this.clazz;
}
List<T> objects = new ArrayList<>();
return objects;
}
/**
* Deletes the object from the database. This removes all of the database
* entries that stored information with regards to the this object.
* <p>
* If the object is referenced by any other tables then this will throw a
* <code>DBManagerException</code>.
*
* @param name name of the object to delete
* @return true if successfully found and deleted the object
* @throws DBManagerException if unable to find the baseline or delete it
* from the database
*/
// protected boolean doDelete(final String name) throws DBManagerException {
// log.debug("deleting object: {}", name);
// if (name == null) {
// log.debug("null name argument");
// return false;
// }
//
// boolean deleted = false;
// Session session = entityManager.unwrap(Session.class);
// try {
// log.debug("retrieving object from db");
// criteriaBuilder = session.getCriteriaBuilder();
// criteriaQuery = criteriaBuilder.createQuery(clazz);
// Root<T> root = criteriaQuery.from(clazz);
// criteriaQuery.select(root).where(criteriaBuilder.equal(root.get("name"), name));
//
// Object object = session.createQuery(criteriaQuery).getSingleResult();
//
// if (clazz.isInstance(object)) {
// T objectOfTypeT = clazz.cast(object);
// log.debug("found object, deleting it");
// session.delete(objectOfTypeT);
// deleted = true;
// }
// } catch (Exception e) {
// final String msg = "unable to retrieve object";
// log.error(msg, e);
// throw new DBManagerException(msg, e);
// }
// return deleted;
// }
}

View File

@ -1,20 +0,0 @@
package hirs.attestationca.persist.service;
import hirs.attestationca.persist.entity.userdefined.ReferenceManifest;
import hirs.attestationca.persist.entity.userdefined.rim.ReferenceDigestValue;
import java.util.List;
import java.util.UUID;
public interface ReferenceDigestValueService {
ReferenceDigestValue saveReferenceDigestValue(ReferenceDigestValue referenceDigestValue);
List<ReferenceDigestValue> fetchDigestValues();
ReferenceDigestValue updateRefDigestValue(ReferenceDigestValue referenceDigestValue, UUID rdvId);
List<ReferenceDigestValue> getValuesByRimId(ReferenceManifest baseRim);
void deleteRefDigestValueById(UUID rdvId);
}

View File

@ -1,23 +0,0 @@
package hirs.attestationca.persist.service;
import hirs.attestationca.persist.OrderedListQuerier;
import hirs.attestationca.persist.entity.userdefined.ReferenceManifest;
import hirs.attestationca.persist.service.selector.ReferenceManifestSelector;
import java.util.List;
import java.util.Set;
import java.util.UUID;
public interface ReferenceManifestService<T extends ReferenceManifest> extends OrderedListQuerier<T> {
ReferenceManifest saveReferenceManifest(ReferenceManifest referenceManifest);
List<ReferenceManifest> fetchReferenceManifests();
// DataTablesOutput<ReferenceManifest> fetchReferenceManifests(DataTablesInput input);
ReferenceManifest updateReferenceManifest(ReferenceManifest referenceManifest, UUID rimId);
void deleteReferenceManifestById(UUID rimId);
<T extends ReferenceManifest> Set<T> get(ReferenceManifestSelector referenceManifestSelector);
}

View File

@ -1,41 +0,0 @@
package hirs.attestationca.persist.service;
import hirs.attestationca.persist.entity.manager.SettingsRepository;
import hirs.attestationca.persist.entity.userdefined.SupplyChainSettings;
import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class SettingsServiceImpl {
@Autowired(required = false)
private EntityManager entityManager;
@Autowired
private SettingsRepository repository;
public SupplyChainSettings updateSettings(SupplyChainSettings settings) {
SupplyChainSettings existing = repository.findByName(settings.getName());
if (existing != null) {
settings.setId(existing.getId());
}
return repository.save(settings);
}
public void saveSettings(SupplyChainSettings settings) {
repository.save(settings);
}
public SupplyChainSettings getByName(String name) {
if (name == null) {
return null;
}
return repository.findByName(name);
}
// public Policy getDefaultPolicy(Appraiser appraiser) {
// return repository.findByAppraiser(appraiser);
// }
}

View File

@ -1,16 +0,0 @@
package hirs.attestationca.persist.service;
import hirs.attestationca.persist.entity.userdefined.SupplyChainValidation;
import java.util.List;
import java.util.UUID;
public interface SupplyChainValidationService {
SupplyChainValidation saveSupplyChainValidation(SupplyChainValidation supplyChainValidation);
List<SupplyChainValidation> fetchSupplyChainValidations();
SupplyChainValidation updateSupplyChainValidation(SupplyChainValidation supplyChainValidation, UUID scvId);
void deleteSupplyChainValidation(UUID scvId);
}

View File

@ -36,12 +36,5 @@ public class HIRSApplication extends SpringBootServletInitializer {
SpringApplication springApplication = new SpringApplication(HIRSApplication.class); SpringApplication springApplication = new SpringApplication(HIRSApplication.class);
springApplication.setDefaultProperties(Collections.singletonMap("server.servlet.context-path", "/portal")); springApplication.setDefaultProperties(Collections.singletonMap("server.servlet.context-path", "/portal"));
springApplication.run(args); springApplication.run(args);
// log.debug("Debug log message");
log.info("Info log message");
log.error("Error log message");
log.warn("Warn log message");
log.fatal("Fatal log message");
// log.trace("Trace log message");
} }
} }

View File

@ -28,7 +28,6 @@ public class HIRSDbInitializer extends AbstractAnnotationConfigDispatcherServlet
log.debug("Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided"); log.debug("Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided");
} }
} catch (Exception ex) { } catch (Exception ex) {
log.error("DAVY********************************************************************************");
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
} }

View File

@ -2,6 +2,7 @@ package hirs.attestationca.portal.datatables;
import hirs.attestationca.persist.CriteriaModifier; import hirs.attestationca.persist.CriteriaModifier;
import hirs.attestationca.persist.FilteredRecordsList; import hirs.attestationca.persist.FilteredRecordsList;
import lombok.extern.log4j.Log4j2;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -15,6 +16,7 @@ import java.util.UUID;
* of ordered lists. * of ordered lists.
* @param <T> The type of object to query * @param <T> The type of object to query
*/ */
@Log4j2
public final class OrderedListQueryDataTableAdapter<T> { public final class OrderedListQueryDataTableAdapter<T> {
private OrderedListQueryDataTableAdapter() { private OrderedListQueryDataTableAdapter() {
@ -67,6 +69,7 @@ public final class OrderedListQueryDataTableAdapter<T> {
//Object that will store query values //Object that will store query values
FilteredRecordsList<T> filteredRecordsList = new FilteredRecordsList<>(); FilteredRecordsList<T> filteredRecordsList = new FilteredRecordsList<>();
filteredRecordsList.setRecordsTotal(dbManager.count()); filteredRecordsList.setRecordsTotal(dbManager.count());
filteredRecordsList.addAll(dbManager.findAll()); filteredRecordsList.addAll(dbManager.findAll());
filteredRecordsList.setRecordsFiltered(10); filteredRecordsList.setRecordsFiltered(10);

View File

@ -213,9 +213,8 @@ public class CertificatePageController extends PageController<NoPageParams> {
for (int i = 0; i < records.size(); i++) { for (int i = 0; i < records.size(); i++) {
PlatformCredential pc = (PlatformCredential) records.get(i); PlatformCredential pc = (PlatformCredential) records.get(i);
// find the EC using the PC's "holder serial number" // find the EC using the PC's "holder serial number"
associatedEC = (EndorsementCredential) certificateRepository associatedEC = certificateRepository
.byHolderSerialNumber(pc.getHolderSerialNumber(), .getEcByHolderSerialNumber(pc.getHolderSerialNumber());
"EndorsementCredential");
if (associatedEC != null) { if (associatedEC != null) {
log.debug("EC ID for holder s/n " + pc log.debug("EC ID for holder s/n " + pc

View File

@ -340,7 +340,7 @@ public final class CertificateStringMapBuilder {
} }
PlatformCredential prevCertificate = certificateRepository PlatformCredential prevCertificate = certificateRepository
.byHolderSerialNumber(certificate.getSerialNumber()); .getPcByHolderSerialNumber(certificate.getSerialNumber());
if (prevCertificate != null) { if (prevCertificate != null) {
data.put("prevCertId", prevCertificate.getId().toString()); data.put("prevCertId", prevCertificate.getId().toString());