Search in sources :

Example 56 with ASException

use of com.intel.mountwilson.as.common.ASException 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 57 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class MleBO method listMles.

/**
    * 
    * @param searchCriteria
    * @return 
    */
public List<MleData> listMles(String searchCriteria) {
    List<MleData> mleDataList = new ArrayList<MleData>();
    List<TblMle> tblMleList;
    try {
        if (searchCriteria != null && !searchCriteria.isEmpty())
            tblMleList = mleJpaController.findMleByNameSearchCriteria(searchCriteria);
        else
            tblMleList = mleJpaController.findTblMleEntities();
        if (tblMleList != null) {
            log.info(String.format("Found [%d] mle results for search criteria [%s]", tblMleList.size(), searchCriteria));
            for (TblMle tblMle : tblMleList) {
                MleData mleData = createMleDataFromDatabaseRecord(tblMle, false);
                mleDataList.add(mleData);
            }
        } else {
            log.info(String.format("Found [%d] mle results for search criteria [%s]", 0, searchCriteria));
        }
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return mleDataList;
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) MleData(com.intel.mtwilson.datatypes.MleData) 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 58 with ASException

use of com.intel.mountwilson.as.common.ASException 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)

Example 59 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class OemBO method deleteOem.

/**
     * 
     * @param osName
     * @return 
     */
public String deleteOem(String osName) {
    try {
        TblOem tblOem = tblOemJpaController.findTblOemByName(osName);
        if (tblOem == null) {
            throw new ASException(ErrorCode.WS_OEM_DOES_NOT_EXIST, osName);
        }
        Collection<TblMle> tblMleCollection = tblOem.getTblMleCollection();
        if (tblMleCollection != null) {
            log.info("OEM is currently associated with # MLEs: " + tblMleCollection.size());
            if (!tblMleCollection.isEmpty()) {
                throw new ASException(ErrorCode.WS_OEM_ASSOCIATION_EXISTS, osName, tblMleCollection.size());
            }
        }
        tblOemJpaController.destroy(tblOem.getId());
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblMle(com.intel.mtwilson.as.data.TblMle) TblOem(com.intel.mtwilson.as.data.TblOem) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException)

Example 60 with ASException

use of com.intel.mountwilson.as.common.ASException in project OpenAttestation by OpenAttestation.

the class OemBO method createOem.

/**
     * 
     * @param oemData
     * @return 
     */
public String createOem(OemData oemData, String uuid) {
    try {
        TblOem tblOem = tblOemJpaController.findTblOemByName(oemData.getName());
        if (tblOem != null)
            throw new ASException(ErrorCode.WS_OEM_ALREADY_EXISTS, oemData.getName());
        tblOem = new TblOem();
        tblOem.setName(oemData.getName());
        tblOem.setDescription(oemData.getDescription());
        if (uuid != null && !uuid.isEmpty()) {
            tblOem.setUuid_hex(uuid);
        } else {
            tblOem.setUuid_hex(new UUID().toString());
        }
        tblOemJpaController.create(tblOem);
    } catch (ASException ase) {
        throw ase;
    } catch (Exception e) {
        throw new ASException(e);
    }
    return "true";
}
Also used : TblOem(com.intel.mtwilson.as.data.TblOem) UUID(com.intel.mtwilson.util.io.UUID) ASException(com.intel.mountwilson.as.common.ASException) ASException(com.intel.mountwilson.as.common.ASException)

Aggregations

ASException (com.intel.mountwilson.as.common.ASException)69 IOException (java.io.IOException)28 CryptographyException (com.intel.mtwilson.crypto.CryptographyException)26 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)20 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)20 TblMle (com.intel.mtwilson.as.data.TblMle)20 NoResultException (javax.persistence.NoResultException)19 UnknownHostException (java.net.UnknownHostException)18 TblHosts (com.intel.mtwilson.as.data.TblHosts)17 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)14 ASDataException (com.intel.mtwilson.as.controller.exceptions.ASDataException)12 KeyManagementException (java.security.KeyManagementException)10 MwAssetTagCertificate (com.intel.mtwilson.as.data.MwAssetTagCertificate)9 SignatureException (java.security.SignatureException)8 CertificateException (java.security.cert.CertificateException)8 WebApplicationException (javax.ws.rs.WebApplicationException)8 ConfigurationException (org.apache.commons.configuration.ConfigurationException)8 ApiException (com.intel.mtwilson.ApiException)7 MwAssetTagCertificateJpaController (com.intel.mtwilson.as.controller.MwAssetTagCertificateJpaController)7 TblMleJpaController (com.intel.mtwilson.as.controller.TblMleJpaController)7