Search in sources :

Example 1 with MwMleSourceJpaController

use of com.intel.mtwilson.as.controller.MwMleSourceJpaController 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 2 with MwMleSourceJpaController

use of com.intel.mtwilson.as.controller.MwMleSourceJpaController 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 3 with MwMleSourceJpaController

use of com.intel.mtwilson.as.controller.MwMleSourceJpaController in project OpenAttestation by OpenAttestation.

the class MleBO method getMleSource.

/**
    * Retrieves the host name that was used to white list the MLE specified.
    * 
    * @param mleName
    * @param mleVersion
    * @param osName
    * @param osVersion
    * @param oemName
    * @return 
    */
public String getMleSource(String mleName, String mleVersion, String osName, String osVersion, String oemName) {
    TblMle tblMle;
    String hostName = null;
    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());
        // the MLE was configured manually. 
        if (mwMleSource == null) {
            hostName = "Manually configured white list";
        } else {
            hostName = mwMleSource.getHostName();
        }
        return hostName;
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
}
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 4 with MwMleSourceJpaController

use of com.intel.mtwilson.as.controller.MwMleSourceJpaController in project OpenAttestation by OpenAttestation.

the class MleBO method addMleSource.

/**
    * Creates a new mapping entry in the DB between the MLE and the host that was used for whitelisiting.
    * 
    * @param mleSourceObj : Object containing the details of the host and the MLE.
    * @return True or False
    */
public String addMleSource(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());
        // Let us check if there is a mapping entry already for this MLE. If it does, then we need to return
        // back appropriate error.
        MwMleSource mleSourceCurrentObj = mleSourceJpaController.findByMleId(tblMle.getId());
        if (mleSourceCurrentObj != null) {
            log.error("White List host is already mapped to the MLE - " + tblMle.getName());
            throw new ASException(ErrorCode.WS_MLE_SOURCE_MAPPING_ALREADY_EXISTS, mleData.getName());
        }
        // Else create a new entry in the DB.
        MwMleSource mleSourceData = new MwMleSource();
        mleSourceData.setMleId(tblMle);
        mleSourceData.setHostName(mleSourceObj.getHostName());
        mleSourceJpaController.create(mleSourceData);
    } 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)

Aggregations

ASException (com.intel.mountwilson.as.common.ASException)4 MwMleSourceJpaController (com.intel.mtwilson.as.controller.MwMleSourceJpaController)4 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)4 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)4 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)4 MwMleSource (com.intel.mtwilson.as.data.MwMleSource)4 TblMle (com.intel.mtwilson.as.data.TblMle)4 NoResultException (javax.persistence.NoResultException)4 MleData (com.intel.mtwilson.datatypes.MleData)2