Search in sources :

Example 1 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method getTblSamlAssertionCount.

public int getTblSamlAssertionCount() {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        Root<TblSamlAssertion> rt = cq.from(TblSamlAssertion.class);
        cq.select(em.getCriteriaBuilder().count(rt));
        Query q = em.createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    } finally {
        em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion)

Example 2 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method findListByHostAndExpiry.

public List<TblSamlAssertion> findListByHostAndExpiry(String host) {
    //List<TblSamlAssertion> tblSamlAssertionList = null; //Variable was never read after null being assigned.
    List<TblSamlAssertion> tblSamlAssertionList;
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblSamlAssertion.findByHostAndExpiry");
        query.setParameter("now", new Date(System.currentTimeMillis()));
        query.setParameter("hostName", host);
        tblSamlAssertionList = query.getResultList();
    } finally {
        em.close();
    }
    return tblSamlAssertionList;
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion) Date(java.util.Date)

Example 3 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method destroy.

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

Example 4 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method edit.

public void edit(TblSamlAssertion tblSamlAssertion) throws NonexistentEntityException, ASDataException {
    EntityManager em = getEntityManager();
    try {
        em.getTransaction().begin();
        TblSamlAssertion persistentTblSamlAssertion = em.find(TblSamlAssertion.class, tblSamlAssertion.getId());
        TblHosts hostIdOld = persistentTblSamlAssertion.getHostId();
        TblHosts hostIdNew = tblSamlAssertion.getHostId();
        if (hostIdNew != null) {
            hostIdNew = em.getReference(hostIdNew.getClass(), hostIdNew.getId());
            tblSamlAssertion.setHostId(hostIdNew);
        }
        tblSamlAssertion = em.merge(tblSamlAssertion);
        if (hostIdOld != null && !hostIdOld.equals(hostIdNew)) {
            hostIdOld.getTblSamlAssertionCollection().remove(tblSamlAssertion);
            hostIdOld = em.merge(hostIdOld);
        }
        if (hostIdNew != null && !hostIdNew.equals(hostIdOld)) {
            hostIdNew.getTblSamlAssertionCollection().add(tblSamlAssertion);
            em.merge(hostIdNew);
        }
        em.getTransaction().commit();
    } catch (Exception ex) {
        String msg = ex.getLocalizedMessage();
        if (msg == null || msg.length() == 0) {
            Integer id = tblSamlAssertion.getId();
            if (findTblSamlAssertion(id) == null) {
                throw new NonexistentEntityException("The tblSamlAssertion with id " + id + " no longer exists.");
            }
        }
        throw new ASDataException(ex);
    } finally {
        em.close();
    }
}
Also used : ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) EntityManager(javax.persistence.EntityManager) TblHosts(com.intel.mtwilson.as.data.TblHosts) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) EntityNotFoundException(javax.persistence.EntityNotFoundException)

Example 5 with TblSamlAssertion

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

the class HostTrustBO method getTrustWithSaml.

public String getTrustWithSaml(TblHosts tblHosts, String hostId, String hostAttestationUuid) {
    try {
        //String location = hostTrustBO.getHostLocation(new Hostname(hostName)).location; // example: "San Jose"
        //HostTrustStatus trustStatus = hostTrustBO.getTrustStatus(new Hostname(hostName)); // example:  BIOS:1,VMM:1
        TblSamlAssertion tblSamlAssertion = new TblSamlAssertion();
        TxtHost host = getHostWithTrust(tblHosts, hostId, tblSamlAssertion);
        tblSamlAssertion.setAssertionUuid(hostAttestationUuid);
        tblSamlAssertion.setBiosTrust(host.isBiosTrusted());
        tblSamlAssertion.setVmmTrust(host.isVmmTrusted());
        // We need to add the Asset tag related data only if the host is provisioned for it. This is done
        // by verifying in the asset tag certificate table. 
        X509AttributeCertificate tagCertificate;
        AssetTagCertBO atagCertBO = new AssetTagCertBO();
        MwAssetTagCertificate atagCertForHost = atagCertBO.findValidAssetTagCertForHost(tblSamlAssertion.getHostId().getId());
        if (atagCertForHost != null) {
            log.debug("Host has been provisioned in the system with a TAG.");
            tagCertificate = X509AttributeCertificate.valueOf(atagCertForHost.getCertificate());
        } else {
            log.debug("Host has not been provisioned in the system with a TAG.");
            tagCertificate = null;
        }
        //            if (tblHosts.getBindingKeyCertificate() != null && !tblHosts.getBindingKeyCertificate().isEmpty()) {
        //                host.setBindingKeyCertificate(tblHosts.getBindingKeyCertificate());
        //            }
        SamlAssertion samlAssertion = getSamlGenerator().generateHostAssertion(host, tagCertificate, null);
        // We will check if the asset-tag was verified successfully for the host. If so, we need to retrieve
        // all the attributes for that asset-tag and send it to the saml generator.
        /*            X509AttributeCertificate tagCertificate = null; 
            if (host.isAssetTagTrusted()) {
                AssetTagCertBO atagCertBO = new AssetTagCertBO();
                MwAssetTagCertificate atagCertForHost = atagCertBO.findValidAssetTagCertForHost(tblSamlAssertion.getHostId().getId());
                if (atagCertForHost != null) {
                    tagCertificate = X509AttributeCertificate.valueOf(atagCertForHost.getCertificate());
//                        atags.add(new AttributeOidAndValue("UUID", atagCertForHost.getUuid())); // should already be the "Subject" attribute of the certificate, if not then we need to get it from one of the cert attributes
                }
            }

            SamlAssertion samlAssertion = getSamlGenerator().generateHostAssertion(host, tagCertificate);
*/
        log.debug("Expiry {}", samlAssertion.expiry_ts.toString());
        tblSamlAssertion.setSaml(samlAssertion.assertion);
        tblSamlAssertion.setExpiryTs(samlAssertion.expiry_ts);
        tblSamlAssertion.setCreatedTs(samlAssertion.created_ts);
        //            TrustReport hostTrustReport = getTrustReportForHost(tblHosts, tblHosts.getName());
        //            tblSamlAssertion.setTrustReport(mapper.writeValueAsString(hostTrustReport));
        //            logTrustReport(tblHosts, hostTrustReport); // Need to cache the attestation report ### v1 requirement to log to mw_ta_log
        getSamlAssertionJpaController().create(tblSamlAssertion);
        return samlAssertion.assertion;
    } catch (ASException e) {
        // We override that here to give more specific codes when possible:
        if (e.getErrorCode().equals(ErrorCode.AS_HOST_NOT_FOUND)) {
            throw new WebApplicationException(Status.NOT_FOUND);
        }
        /*
             * if( e.getErrorCode().equals(ErrorCode.TA_ERROR)) { throw new
             * WebApplicationException(Status.INTERNAL_SERVER_ERROR); }
             *
             */
        throw e;
    } catch (Exception ex) {
        // throw new ASException( e);
        log.error("Error during retrieval of host trust status.", ex);
        throw new ASException(ErrorCode.AS_HOST_TRUST_ERROR, ex.getClass().getSimpleName());
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) SamlAssertion(com.intel.mtwilson.saml.SamlAssertion) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion) AssetTagCertBO(com.intel.mtwilson.as.business.AssetTagCertBO) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion) MwAssetTagCertificate(com.intel.mtwilson.as.data.MwAssetTagCertificate) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Aggregations

TblSamlAssertion (com.intel.mtwilson.as.data.TblSamlAssertion)10 EntityManager (javax.persistence.EntityManager)7 Query (javax.persistence.Query)5 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)3 ASException (com.intel.mountwilson.as.common.ASException)2 TblSamlAssertionJpaController (com.intel.mtwilson.as.controller.TblSamlAssertionJpaController)2 TblHosts (com.intel.mtwilson.as.data.TblHosts)2 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)2 IOException (java.io.IOException)2 UnknownHostException (java.net.UnknownHostException)2 Date (java.util.Date)2 EntityNotFoundException (javax.persistence.EntityNotFoundException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 AssetTagCertBO (com.intel.mtwilson.as.business.AssetTagCertBO)1 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)1 MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)1 SamlAssertion (com.intel.mtwilson.saml.SamlAssertion)1 Calendar (java.util.Calendar)1