Search in sources :

Example 6 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method findByAssertionUuid.

public TblSamlAssertion findByAssertionUuid(String assertionUuid) {
    TblSamlAssertion tblSamlAssertion = null;
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblSamlAssertion.findByAssertionUuid");
        query.setParameter("assertionUuid", assertionUuid);
        List<TblSamlAssertion> list = query.getResultList();
        if (list != null && list.size() > 0) {
            tblSamlAssertion = list.get(0);
        }
    } finally {
        em.close();
    }
    return tblSamlAssertion;
}
Also used : EntityManager(javax.persistence.EntityManager) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) Query(javax.persistence.Query) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion)

Example 7 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method findTblSamlAssertionEntities.

private List<TblSamlAssertion> findTblSamlAssertionEntities(boolean all, int maxResults, int firstResult) {
    EntityManager em = getEntityManager();
    try {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(TblSamlAssertion.class));
        Query q = em.createQuery(cq);
        if (!all) {
            q.setMaxResults(maxResults);
            q.setFirstResult(firstResult);
        }
        return q.getResultList();
    } 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 8 with TblSamlAssertion

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

the class TblSamlAssertionJpaController method findByHostAndExpiry.

public TblSamlAssertion findByHostAndExpiry(String host) {
    TblSamlAssertion tblSamlAssertion = null;
    EntityManager em = getEntityManager();
    try {
        Query query = em.createNamedQuery("TblSamlAssertion.findByHostAndExpiry");
        query.setParameter("now", new Date(System.currentTimeMillis()));
        query.setParameter("hostName", host);
        List<TblSamlAssertion> list = query.getResultList();
        if (list != null && list.size() > 0) {
            tblSamlAssertion = list.get(0);
        }
    } finally {
        em.close();
    }
    return tblSamlAssertion;
}
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 9 with TblSamlAssertion

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

the class HostBO method deleteSAMLAssertions.

/**
         * Deletes all the SAML assertions for the specified host. This should
         * be called before deleting the host.
         *
         * @param hostId
         */
private void deleteSAMLAssertions(TblHosts hostId) throws IOException {
    TblSamlAssertionJpaController samlJpaController = getSamlAssertionJpaController();
    List<TblSamlAssertion> hostSAMLAssertions = samlJpaController.findByHostID(hostId);
    if (hostSAMLAssertions != null) {
        for (TblSamlAssertion hostSAML : hostSAMLAssertions) {
            try {
                samlJpaController.destroy(hostSAML.getId());
            } catch (NonexistentEntityException e) {
                log.error("Ta Log is already deleted " + hostSAML.getId());
            }
        }
        log.info("Deleted all the logs for the given host " + hostId);
    }
}
Also used : TblSamlAssertionJpaController(com.intel.mtwilson.as.controller.TblSamlAssertionJpaController) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion)

Example 10 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, boolean forceVerify) throws IOException {
    log.debug("getTrustWithSaml: Getting trust for host: " + tblHosts.getName() + " Force verify flag: " + forceVerify);
    // Bug: 702: For host not supporting TXT, we need to return back a proper error
    // make sure the DEK is set for this thread
    //        My.initDataEncryptionKey();
    //        TblHosts tblHosts = getHostByName(new Hostname((host)));
    HostAgentFactory factory = new HostAgentFactory();
    HostAgent agent = factory.getHostAgent(tblHosts);
    if (!agent.isTpmAvailable()) {
        throw new ASException(ErrorCode.AS_TPM_NOT_SUPPORTED, hostId);
    }
    if (forceVerify != true) {
        //TblSamlAssertion tblSamlAssertion = new TblSamlAssertionJpaController((getEntityManagerFactory())).findByHostAndExpiry(hostId);
        //TblSamlAssertion tblSamlAssertion = My.jpa().mwSamlAssertion().findByHostAndExpiry(tblHosts.getName()); //hostId);
        TblSamlAssertionJpaController tblSamlAssertionJpa = getSamlAssertionJpaController();
        TblSamlAssertion tblSamlAssertion = tblSamlAssertionJpa.findByHostAndExpiry(tblHosts.getName());
        if (tblSamlAssertion != null) {
            if (tblSamlAssertion.getErrorMessage() == null || tblSamlAssertion.getErrorMessage().isEmpty()) {
                log.debug("Found assertion in cache. Expiry time : " + tblSamlAssertion.getExpiryTs());
                //HostAttestation ha = new HostAttestation();
                return buildHostAttestation(tblHosts, tblSamlAssertion).getSaml();
            } else {
                log.debug("Found assertion in cache with error set, returning that.");
                throw new ASException(new Exception("(" + tblSamlAssertion.getErrorCode() + ") " + tblSamlAssertion.getErrorMessage() + " (cached on " + tblSamlAssertion.getCreatedTs().toString() + ")"));
            }
        }
    }
    log.debug("Getting trust and saml assertion from host.");
    try {
        //            return getTrustWithSaml(tblHosts, hostId);
        return getTrustWithSaml(tblHosts, hostId, hostAttestationUuid);
    } catch (Exception e) {
        TblSamlAssertion tblSamlAssertion = new TblSamlAssertion();
        tblSamlAssertion.setAssertionUuid(hostAttestationUuid);
        tblSamlAssertion.setHostId(tblHosts);
        //TxtHost hostTxt = getHostWithTrust(new Hostname(host),tblSamlAssertion); 
        //TxtHostRecord tmp = new TxtHostRecord();
        //tmp.HostName = host;
        //tmp.IPAddress = host;
        //TxtHost hostTxt = new TxtHost(tmp);
        tblSamlAssertion.setBiosTrust(false);
        tblSamlAssertion.setVmmTrust(false);
        try {
            log.error("Caught exception, generating saml assertion");
            log.error("Printing stacktrace first");
            e.printStackTrace();
            tblSamlAssertion.setSaml("");
            int cacheTimeout = ASConfig.getConfiguration().getInt("saml.validity.seconds", 3600);
            tblSamlAssertion.setCreatedTs(Calendar.getInstance().getTime());
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.SECOND, cacheTimeout);
            tblSamlAssertion.setExpiryTs(cal.getTime());
            if (e instanceof ASException) {
                ASException ase = (ASException) e;
                log.debug("e is an instance of ASExpection: " + String.valueOf(ase.getErrorCode()));
                tblSamlAssertion.setErrorCode(String.valueOf(ase.getErrorCode()));
            } else {
                log.debug("e is NOT an instance of ASExpection: " + String.valueOf(ErrorCode.AS_HOST_TRUST_ERROR.getErrorCode()));
                tblSamlAssertion.setErrorCode(String.valueOf(ErrorCode.AS_HOST_TRUST_ERROR.getErrorCode()));
            }
            // tblSamlAssertion.setErrorMessage(e.getMessage());
            // Bug fix for 1038
            tblSamlAssertion.setErrorMessage(e.getClass().getSimpleName());
            getSamlAssertionJpaController().create(tblSamlAssertion);
        } catch (Exception ex) {
            //log.debug("getTrustwithSaml caugh exception while generating error saml assertion");
            log.error("getTrustwithSaml caugh exception while generating error saml assertion", ex);
            // String msg = ex.getMessage();
            String msg = ex.getClass().getSimpleName();
            // throw new ASException(new Exception("getTrustWithSaml " + msg));
            throw new ASException(ex, ErrorCode.AS_HOST_TRUST_ERROR, msg);
        //throw new ASException(new Exception("Host Manifest is missing required PCRs."));
        }
        //Daniel, change the messages into meaningful thiings here
        //log.debug("e.getMessage = "+e.getMessage());
        //throw new ASException(new Exception(e.getMessage()));
        log.error("Error during retrieval of host trust status.", e);
        throw new ASException(e, ErrorCode.AS_HOST_TRUST_ERROR, e.getClass().getSimpleName());
    //throw new ASException(new Exception("Host Manifest is missing required PCRs."));
    }
}
Also used : TblSamlAssertionJpaController(com.intel.mtwilson.as.controller.TblSamlAssertionJpaController) Calendar(java.util.Calendar) TblSamlAssertion(com.intel.mtwilson.as.data.TblSamlAssertion) 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