mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-02-22 10:20:54 +00:00
Merge pull request #633 from nsacyber/v3_db-uuid-adjustment
DB Returning non-null but blank Objects
This commit is contained in:
commit
96bd8b97a2
@ -17,10 +17,10 @@ public interface CertificateRepository extends JpaRepository<Certificate, UUID>
|
|||||||
|
|
||||||
@Query(value = "SELECT * FROM Certificate where id = ?1", nativeQuery = true)
|
@Query(value = "SELECT * FROM Certificate where id = ?1", nativeQuery = true)
|
||||||
Certificate getCertificate(UUID uuid);
|
Certificate getCertificate(UUID uuid);
|
||||||
@Query(value = "SELECT * FROM Certificate where issuer = ?1 AND DTYPE = ?2", nativeQuery = true)
|
@Query(value = "SELECT * FROM Certificate where subject = ?1 AND DTYPE = ?2", nativeQuery = true)
|
||||||
List<Certificate> findBySubject(String issuer, String dType);
|
List<Certificate> findBySubject(String subject, String dType);
|
||||||
@Query(value = "SELECT * FROM Certificate where issuerSorted = ?1 AND DTYPE = ?2", nativeQuery = true)
|
@Query(value = "SELECT * FROM Certificate where subjectSorted = ?1 AND DTYPE = ?2", nativeQuery = true)
|
||||||
List<Certificate> findBySubjectSorted(String issuedSort, String dType);
|
List<Certificate> findBySubjectSorted(String subjectSorted, String dType);
|
||||||
@Query(value = "SELECT * FROM Certificate where DTYPE = ?1", nativeQuery = true)
|
@Query(value = "SELECT * FROM Certificate where DTYPE = ?1", nativeQuery = true)
|
||||||
List<Certificate> findByType(String dType);
|
List<Certificate> findByType(String dType);
|
||||||
@Query(value = "SELECT * FROM Certificate where serialNumber = ?1 AND DTYPE = ?2", nativeQuery = true)
|
@Query(value = "SELECT * FROM Certificate where serialNumber = ?1 AND DTYPE = ?2", nativeQuery = true)
|
||||||
|
@ -375,7 +375,8 @@ public class CertificatePageController extends PageController<NoPageParams> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
UUID uuid = UUID.fromString(id);
|
UUID uuid = UUID.fromString(id);
|
||||||
Certificate certificate = certificateRepository.getReferenceById(uuid);
|
Certificate certificate = getCertificateById(certificateType, uuid);
|
||||||
|
|
||||||
if (certificate == null) {
|
if (certificate == null) {
|
||||||
// Use the term "record" here to avoid user confusion b/t cert and cred
|
// Use the term "record" here to avoid user confusion b/t cert and cred
|
||||||
String notFoundMessage = "Unable to locate record with ID: " + uuid;
|
String notFoundMessage = "Unable to locate record with ID: " + uuid;
|
||||||
@ -748,6 +749,29 @@ public class CertificatePageController extends PageController<NoPageParams> {
|
|||||||
return associatedCertificates;
|
return associatedCertificates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Certificate getCertificateById(final String certificateType, final UUID uuid) {
|
||||||
|
switch (certificateType) {
|
||||||
|
case PLATFORMCREDENTIAL:
|
||||||
|
if (platformCertificateRepository.existsById(uuid)) {
|
||||||
|
return platformCertificateRepository.getReferenceById(uuid);
|
||||||
|
}
|
||||||
|
case ENDORSEMENTCREDENTIAL:
|
||||||
|
if (endorsementCredentialRepository.existsById(uuid)) {
|
||||||
|
return endorsementCredentialRepository.getReferenceById(uuid);
|
||||||
|
}
|
||||||
|
case ISSUEDCERTIFICATES:
|
||||||
|
if (issuedCertificateRepository.existsById(uuid)) {
|
||||||
|
return issuedCertificateRepository.getReferenceById(uuid);
|
||||||
|
}
|
||||||
|
case TRUSTCHAIN:
|
||||||
|
if (caCredentialRepository.existsById(uuid)) {
|
||||||
|
return caCredentialRepository.getReferenceById(uuid);
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses an uploaded file into a certificate and populates the given model
|
* Parses an uploaded file into a certificate and populates the given model
|
||||||
* with error messages if parsing fails.
|
* with error messages if parsing fails.
|
||||||
@ -821,7 +845,7 @@ public class CertificatePageController extends PageController<NoPageParams> {
|
|||||||
log.error(failMessage, dEx);
|
log.error(failMessage, dEx);
|
||||||
messages.addError(failMessage + dEx.getMessage());
|
messages.addError(failMessage + dEx.getMessage());
|
||||||
return null;
|
return null;
|
||||||
} catch (IllegalArgumentException | IllegalStateException iaEx) {
|
} catch (IllegalArgumentException iaEx) {
|
||||||
final String failMessage = String.format(
|
final String failMessage = String.format(
|
||||||
"Certificate format not recognized(%s): ", fileName);
|
"Certificate format not recognized(%s): ", fileName);
|
||||||
log.error(failMessage, iaEx);
|
log.error(failMessage, iaEx);
|
||||||
|
@ -350,20 +350,12 @@ public class ReferenceManifestPageController extends PageController<NoPageParams
|
|||||||
*/
|
*/
|
||||||
private ReferenceManifest getRimFromDb(final String id) throws IllegalArgumentException {
|
private ReferenceManifest getRimFromDb(final String id) throws IllegalArgumentException {
|
||||||
UUID uuid = UUID.fromString(id);
|
UUID uuid = UUID.fromString(id);
|
||||||
// ReferenceManifest rim = BaseReferenceManifest.select(referenceManifestManager)
|
|
||||||
// .byEntityId(uuid).getRIM();
|
|
||||||
//
|
|
||||||
// if (rim == null) {
|
|
||||||
// rim = SupportReferenceManifest.select(referenceManifestManager)
|
|
||||||
// .byEntityId(uuid).getRIM();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (rim == null) {
|
|
||||||
// rim = EventLogMeasurements.select(referenceManifestManager)
|
|
||||||
// .byEntityId(uuid).getRIM();
|
|
||||||
// }
|
|
||||||
|
|
||||||
return this.referenceManifestRepository.getReferenceById(uuid);
|
if (referenceManifestRepository.existsById(uuid)) {
|
||||||
|
return referenceManifestRepository.getReferenceById(uuid);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,18 +126,16 @@ public class RimDatabasePageController extends PageController<NoPageParams> {
|
|||||||
SupportReferenceManifest support;
|
SupportReferenceManifest support;
|
||||||
for (ReferenceDigestValue rdv : referenceDigestValues) {
|
for (ReferenceDigestValue rdv : referenceDigestValues) {
|
||||||
// We are updating the base rim ID field if necessary and
|
// We are updating the base rim ID field if necessary and
|
||||||
if (rdv.getBaseRimId() == null) {
|
if (rdv.getBaseRimId() == null && referenceManifestRepository.existsById(rdv.getSupportRimId())) {
|
||||||
support = (SupportReferenceManifest) referenceManifestRepository.getReferenceById(rdv.getSupportRimId());
|
support = (SupportReferenceManifest) referenceManifestRepository.getReferenceById(rdv.getSupportRimId());
|
||||||
if (support != null) {
|
|
||||||
rdv.setBaseRimId(support.getAssociatedRim());
|
rdv.setBaseRimId(support.getAssociatedRim());
|
||||||
try {
|
try {
|
||||||
referenceDigestValueRepository.save(rdv);
|
referenceDigestValueRepository.save(rdv);
|
||||||
} catch (DBManagerException e) {
|
} catch (DBManagerException dbMEx) {
|
||||||
log.error("Failed to update TPM Event with Base RIM ID");
|
log.error("Failed to update TPM Event with Base RIM ID");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Returning list of size: " + referenceDigestValues.size());
|
log.debug("Returning list of size: " + referenceDigestValues.size());
|
||||||
return new DataTableResponse<>(referenceDigestValues, input);
|
return new DataTableResponse<>(referenceDigestValues, input);
|
||||||
|
@ -150,7 +150,7 @@ public final class CertificateStringMapBuilder {
|
|||||||
final Certificate certificate,
|
final Certificate certificate,
|
||||||
final CertificateRepository certificateRepository,
|
final CertificateRepository certificateRepository,
|
||||||
final CACredentialRepository caCredentialRepository) {
|
final CACredentialRepository caCredentialRepository) {
|
||||||
List<Certificate> issuerCertificates = new ArrayList<>();
|
List<CertificateAuthorityCredential> issuerCertificates = new ArrayList<>();
|
||||||
CertificateAuthorityCredential skiCA = null;
|
CertificateAuthorityCredential skiCA = null;
|
||||||
String issuerResult;
|
String issuerResult;
|
||||||
|
|
||||||
@ -167,12 +167,10 @@ public final class CertificateStringMapBuilder {
|
|||||||
if (certificate.getIssuerSorted() == null
|
if (certificate.getIssuerSorted() == null
|
||||||
|| certificate.getIssuerSorted().isEmpty()) {
|
|| certificate.getIssuerSorted().isEmpty()) {
|
||||||
//Get certificates by subject
|
//Get certificates by subject
|
||||||
issuerCertificates = certificateRepository.findBySubject(certificate.getIssuer(),
|
issuerCertificates = caCredentialRepository.findBySubject(certificate.getIssuer());
|
||||||
"CertificateAuthorityCredential");
|
|
||||||
} else {
|
} else {
|
||||||
//Get certificates by subject organization
|
//Get certificates by subject organization
|
||||||
issuerCertificates = certificateRepository.findBySubjectSorted(certificate.getIssuerSorted(),
|
issuerCertificates = caCredentialRepository.findBySubjectSorted(certificate.getIssuerSorted());
|
||||||
"CertificateAuthorityCredential");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
issuerCertificates.add(skiCA);
|
issuerCertificates.add(skiCA);
|
||||||
@ -209,6 +207,9 @@ public final class CertificateStringMapBuilder {
|
|||||||
public static HashMap<String, String> getCertificateAuthorityInformation(final UUID uuid,
|
public static HashMap<String, String> getCertificateAuthorityInformation(final UUID uuid,
|
||||||
final CertificateRepository certificateRepository,
|
final CertificateRepository certificateRepository,
|
||||||
final CACredentialRepository caCertificateRepository) {
|
final CACredentialRepository caCertificateRepository) {
|
||||||
|
if (!caCertificateRepository.existsById(uuid)) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
CertificateAuthorityCredential certificate = caCertificateRepository.getReferenceById(uuid);
|
CertificateAuthorityCredential certificate = caCertificateRepository.getReferenceById(uuid);
|
||||||
|
|
||||||
String notFoundMessage = "Unable to find Certificate Authority "
|
String notFoundMessage = "Unable to find Certificate Authority "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user