Search in sources :

Example 1 with TblTaLog

use of com.intel.mtwilson.as.data.TblTaLog in project OpenAttestation by OpenAttestation.

the class TblModuleManifestLogJpaController method destroy.

public void destroy(Integer id) throws NonexistentEntityException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblModuleManifestLog tblModuleManifestLog;
        try {
            tblModuleManifestLog = em.getReference(TblModuleManifestLog.class, id);
            tblModuleManifestLog.getId();
        } catch (EntityNotFoundException enfe) {
            throw new NonexistentEntityException("The tblModuleManifestLog with id " + id + " no longer exists.", enfe);
        }
        TblTaLog taLogId = tblModuleManifestLog.getTaLogId();
        if (taLogId != null) {
            taLogId.getTblModuleManifestLogCollection().remove(tblModuleManifestLog);
            em.merge(taLogId);
        }
        em.remove(tblModuleManifestLog);
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException) TblModuleManifestLog(com.intel.mtwilson.as.data.TblModuleManifestLog)

Example 2 with TblTaLog

use of com.intel.mtwilson.as.data.TblTaLog in project OpenAttestation by OpenAttestation.

the class TblModuleManifestLogJpaController method create.

public void create(TblModuleManifestLog tblModuleManifestLog) {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblTaLog taLogId = tblModuleManifestLog.getTaLogId();
        if (taLogId != null) {
            taLogId = em.getReference(taLogId.getClass(), taLogId.getId());
            tblModuleManifestLog.setTaLogId(taLogId);
        }
        em.persist(tblModuleManifestLog);
        if (taLogId != null) {
            taLogId.getTblModuleManifestLogCollection().add(tblModuleManifestLog);
            em.merge(taLogId);
        }
        em.getTransaction().commit();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) TblTaLog(com.intel.mtwilson.as.data.TblTaLog)

Example 3 with TblTaLog

use of com.intel.mtwilson.as.data.TblTaLog in project OpenAttestation by OpenAttestation.

the class ReportsBO method getReportManifest.

public HostManifestReportType getReportManifest(Hostname hostName) {
    // datatype.Hostname
    HostManifestReportType hostManifestReportType = new HostManifestReportType();
    /*
         * if (hostName == null || hostName.isEmpty()) { throw new
         * ASException(ErrorCode.VALIDATION_ERROR, "Input Hostname " + hostName
         * + " is empty."); }
         *
         */
    TblHosts tblHosts = null;
    try {
        // datatype.Hostname
        tblHosts = getTblHostsJpaController().findByName(hostName.toString());
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    }
    if (tblHosts == null) {
        throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, hostName.toString());
    }
    Date lastStatusTs = getTblTaLogJpaController().findLastStatusTs(tblHosts.getId());
    if (lastStatusTs != null) {
        List<TblTaLog> logs = getTblTaLogJpaController().findLogsByHostId(tblHosts.getId(), lastStatusTs);
        com.intel.mountwilson.as.hostmanifestreport.data.HostType hostType = new com.intel.mountwilson.as.hostmanifestreport.data.HostType();
        // datatype.Hostname
        hostType.setName(hostName.toString());
        if (logs != null) {
            for (TblTaLog log : logs) {
                ManifestType manifest = new ManifestType();
                manifest.setName(Integer.parseInt(log.getManifestName()));
                manifest.setValue(log.getManifestValue());
                manifest.setVerifiedOn(Util.getCalendar(log.getUpdatedOn()));
                manifest.setTrustStatus(getTrustStatus(log.getTrustStatus()));
                hostType.getManifest().add(manifest);
            }
        }
        hostManifestReportType.setHost(hostType);
    }
    return hostManifestReportType;
}
Also used : ManifestType(com.intel.mountwilson.as.hostmanifestreport.data.ManifestType) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) HostManifestReportType(com.intel.mountwilson.as.hostmanifestreport.data.HostManifestReportType) HostType(com.intel.mountwilson.as.hosttrustreport.data.HostType) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) ASException(com.intel.mountwilson.as.common.ASException)

Example 4 with TblTaLog

use of com.intel.mtwilson.as.data.TblTaLog in project OpenAttestation by OpenAttestation.

the class ReportsBO method getTrustReport.

public HostsTrustReportType getTrustReport(Collection<Hostname> hostNames) {
    // datatype.Hostname
    try {
        HostsTrustReportType hostsTrustReportType = new HostsTrustReportType();
        for (Hostname host : hostNames) {
            // datatype.Hostname
            TblHosts tblHosts = getTblHostsJpaController().findByName(host.toString());
            if (tblHosts == null) {
                throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, host);
            }
            List<TblTaLog> logs = getTblTaLogJpaController().findTrustStatusByHostId(tblHosts.getId(), 5);
            if (logs != null) {
                for (TblTaLog log : logs) {
                    HostType hostType = new HostType();
                    // datatype.Hostname
                    hostType.setHostName(host.toString());
                    hostType.setMLEInfo(getMleInfo(tblHosts));
                    hostType.setTrustStatus(getTrustStatus(log.getError()));
                    hostType.setVerifiedOn(Util.getCalendar(log.getUpdatedOn()));
                    hostsTrustReportType.getHost().add(hostType);
                }
            }
        }
        return hostsTrustReportType;
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    } catch (Exception e) {
        throw new ASException(e);
    }
}
Also used : HostType(com.intel.mountwilson.as.hosttrustreport.data.HostType) HostsTrustReportType(com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType) TblTaLog(com.intel.mtwilson.as.data.TblTaLog) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) Hostname(com.intel.mtwilson.util.net.Hostname) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException)

Example 5 with TblTaLog

use of com.intel.mtwilson.as.data.TblTaLog in project OpenAttestation by OpenAttestation.

the class ReportsBO method getAttestationReport.

public AttestationReport getAttestationReport(Hostname hostName, Boolean failureOnly) throws NumberFormatException, IOException {
    AttestationReport attestationReport = new AttestationReport();
    TblHosts tblHosts = null;
    try {
        // datatype.Hostname
        tblHosts = getTblHostsJpaController().findByName(hostName.toString());
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    }
    if (tblHosts == null) {
        throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, hostName.toString());
    }
    Date lastStatusTs = getTblTaLogJpaController().findLastStatusTs(tblHosts.getId());
    if (lastStatusTs != null) {
        List<TblTaLog> logs = getTblTaLogJpaController().findLogsByHostId(tblHosts.getId(), lastStatusTs);
        com.intel.mountwilson.as.hostmanifestreport.data.HostType hostType = new com.intel.mountwilson.as.hostmanifestreport.data.HostType();
        // datatype.Hostname
        hostType.setName(hostName.toString());
        if (logs != null) {
            for (TblTaLog log : logs) {
                boolean value = (failureOnly && log.getTrustStatus() == false);
                if (!failureOnly || value) {
                    if (log.getManifestName().equalsIgnoreCase(ASSET_TAG_PCR)) {
                        attestationReport.getPcrLogs().add(getPcrLogReportForAssetTag(log, tblHosts.getId()));
                    } else {
                        attestationReport.getPcrLogs().add(getPcrManifestLog(tblHosts, log, failureOnly));
                    }
                }
            }
        }
    }
    return attestationReport;
}
Also used : TblTaLog(com.intel.mtwilson.as.data.TblTaLog) HostType(com.intel.mountwilson.as.hosttrustreport.data.HostType) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) TblHosts(com.intel.mtwilson.as.data.TblHosts) ASException(com.intel.mountwilson.as.common.ASException)

Aggregations

TblTaLog (com.intel.mtwilson.as.data.TblTaLog)23 EntityManager (javax.persistence.EntityManager)11 Date (java.util.Date)9 Query (javax.persistence.Query)7 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)7 Hostname (com.intel.mtwilson.util.net.Hostname)6 TblHosts (com.intel.mtwilson.as.data.TblHosts)5 ASException (com.intel.mountwilson.as.common.ASException)4 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)4 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 HostType (com.intel.mountwilson.as.hosttrustreport.data.HostType)3 TblTaLogJpaController (com.intel.mtwilson.as.controller.TblTaLogJpaController)3 EntityNotFoundException (javax.persistence.EntityNotFoundException)3 HostManifestReportType (com.intel.mountwilson.as.hostmanifestreport.data.HostManifestReportType)2 HostsTrustReportType (com.intel.mountwilson.as.hosttrustreport.data.HostsTrustReportType)2 TblModuleManifestLog (com.intel.mtwilson.as.data.TblModuleManifestLog)2 IOException (java.io.IOException)2 ManifestType (com.intel.mountwilson.as.hostmanifestreport.data.ManifestType)1