Search in sources :

Example 21 with TblMle

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

the class MleBO method getTblMle.

/**
         * 
         * @param mleData
         * @return 
         */
private TblMle getTblMle(MleData mleData, String mleUuid, String osOemUuid) {
    TblMle tblMle = new TblMle();
    tblMle.setMLEType(mleData.getMleType());
    tblMle.setName(mleData.getName());
    tblMle.setVersion(mleData.getVersion());
    tblMle.setAttestationType(mleData.getAttestationType());
    tblMle.setDescription(mleData.getDescription());
    tblMle.setRequiredManifestList(getRequiredManifestList(mleData.getManifestList()));
    if (mleUuid != null && !mleUuid.isEmpty()) {
        tblMle.setUuid_hex(mleUuid);
    } else {
        tblMle.setUuid_hex(new UUID().toString());
    }
    if (mleData.getMleType().equals("VMM")) {
        tblMle.setOsId(getTblOs(mleData.getOsName(), mleData.getOsVersion()));
        tblMle.setOs_uuid_hex(osOemUuid);
    } else if (mleData.getMleType().equals("BIOS")) {
        tblMle.setOemId(getTblOem(mleData.getOemName()));
        tblMle.setOem_uuid_hex(osOemUuid);
    }
    return tblMle;
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) UUID(com.intel.mtwilson.util.io.UUID)

Example 22 with TblMle

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

the class MleBO method updateMleSource.

/**
    * Updates an existing MLE with the name of the white list host that was used to modify the white list values.
    * @param mleSourceObj
    * @return 
    */
public String updateMleSource(MleSource mleSourceObj) {
    TblMle tblMle;
    MleData mleData = null;
    try {
        try {
            mleData = mleSourceObj.getMleData();
            // Verify if the MLE exists in the system.
            tblMle = getMleDetails(mleData.getName(), mleData.getVersion(), mleData.getOsName(), mleData.getOsVersion(), mleData.getOemName());
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleData.getName(), mleData.getVersion());
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        // If the mapping does not exist already in the db, then we need to return back error.
        MwMleSource mwMleSource = mleSourceJpaController.findByMleId(tblMle.getId());
        if (mwMleSource == null) {
            throw new ASException(ErrorCode.WS_MLE_SOURCE_MAPPING_DOES_NOT_EXIST, mleData.getName());
        }
        mwMleSource.setHostName(mleSourceObj.getHostName());
        mleSourceJpaController.edit(mwMleSource);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) MleData(com.intel.mtwilson.datatypes.MleData) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 23 with TblMle

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

the class MleBO method deleteMleSource.

/**
    * Deletes an existing mapping between the MLE and the WhiteList host that was used during the creation of MLE.
    * This method is called during the deletion of MLEs.
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public String deleteMleSource(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    TblMle tblMle;
    try {
        try {
            // First check if the entry exists in the MLE table.
            tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        } catch (NoResultException nre) {
            throw new ASException(nre, ErrorCode.WS_MLE_DOES_NOT_EXIST, mleName, mleVersion);
        }
        MwMleSourceJpaController mleSourceJpaController = new MwMleSourceJpaController(getEntityManagerFactory());
        MwMleSource mwMleSource = mleSourceJpaController.findByMleId(tblMle.getId());
        // configured manully, this entry does not exist.
        if (mwMleSource != null)
            mleSourceJpaController.destroy(mwMleSource.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : MwMleSourceJpaController(com.intel.mtwilson.as.controller.MwMleSourceJpaController) TblMle(com.intel.mtwilson.as.data.TblMle) NoResultException(javax.persistence.NoResultException) MwMleSource(com.intel.mtwilson.as.data.MwMleSource) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 24 with TblMle

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

the class MleBO method deleteMle.

/**
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public String deleteMle(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    try {
        TblMle tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        if (tblMle == null) {
            throw new ASException(ErrorCode.WS_MLE_DOES_NOT_EXIST, mleName, mleVersion);
        }
        Collection<TblHosts> tblHostsCollection;
        if (oemName == null || oemName.isEmpty()) {
            tblHostsCollection = tblMle.getTblHostsCollection();
        } else {
            tblHostsCollection = tblMle.getTblHostsCollection1();
        }
        if (tblHostsCollection != null) {
            log.info(String.format("MLE '%s' is currently associated with '%d' hosts. ", mleName, tblHostsCollection.size()));
            if (!tblHostsCollection.isEmpty()) {
                throw new ASException(ErrorCode.WS_MLE_ASSOCIATION_EXISTS, mleName, mleVersion, tblHostsCollection.size());
            }
        }
        for (TblPcrManifest manifest : tblMle.getTblPcrManifestCollection()) {
            pcrManifestJpaController.destroy(manifest.getId());
        }
        // We also need to delete entries in the MleSource table for the MLE. This table would store the host
        // name that was used to white list the MLE.
        deleteMleSource(mleName, mleVersion, osName, osVersion, oemName);
        mleJpaController.destroy(tblMle.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) TblHosts(com.intel.mtwilson.as.data.TblHosts) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Example 25 with TblMle

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

the class MleBO method deletePCRWhiteList.

/**
         * 
         * Added By: Sudhir on June 20, 2012
         * 
         * Processes the delete request for an existing PCR white list for the specified MLE.
         * 
         * @param pcrName : Name of the PCR, which is usually the number
         * @param mleName : Name of the associated MLE
         * @param mleVersion : Version of the associated MLE
         * @param osName : OS name associated with the VMM MLE
         * @param osVersion : OS version associated with the VMM MLE
         * @param oemName : OEM Name associated with the BIOS MLE
         * @return 
         */
public String deletePCRWhiteList(String pcrName, String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    TblPcrManifest tblPcr;
    TblMle tblMle;
    try {
        tblMle = getMleDetails(mleName, mleVersion, osName, osVersion, oemName);
        if (tblMle == null && oemName != null) {
            throw new ASException(ErrorCode.WS_MLE_OEM_DOES_NOT_EXIST, mleName, mleVersion, oemName);
        }
        if (tblMle == null && osName != null) {
            throw new ASException(ErrorCode.WS_MLE_OS_DOES_NOT_EXIST, mleName, mleVersion, osName, osVersion);
        }
        // Now we need to check if PCR value exists. If it does, then we do delete or else
        // we still return true since the data does not exist.
        tblPcr = getPCRWhiteListDetails(tblMle.getId(), pcrName);
        if (tblPcr == null) {
            return "true";
        }
        // Delete the PCR white list entry.
        pcrManifestJpaController.destroy(tblPcr.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException) NoResultException(javax.persistence.NoResultException) ASDataException(com.intel.mtwilson.as.controller.exceptions.ASDataException) NonexistentEntityException(com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException) IllegalOrphanException(com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)

Aggregations

TblMle (com.intel.mtwilson.as.data.TblMle)65 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)25 ASException (com.intel.mountwilson.as.common.ASException)20 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)20 EntityManager (javax.persistence.EntityManager)20 NoResultException (javax.persistence.NoResultException)19 TblPcrManifest (com.intel.mtwilson.as.data.TblPcrManifest)18 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)17 ArrayList (java.util.ArrayList)16 Matchers.anyString (org.mockito.Matchers.anyString)14 EntityNotFoundException (javax.persistence.EntityNotFoundException)11 TblHosts (com.intel.mtwilson.as.data.TblHosts)9 TblOem (com.intel.mtwilson.as.data.TblOem)9 TblOs (com.intel.mtwilson.as.data.TblOs)9 Query (javax.persistence.Query)8 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)8 Test (org.junit.Test)8 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)7 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 MwMleSource (com.intel.mtwilson.as.data.MwMleSource)6