use of com.intel.mtwilson.as.data.TblHosts 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";
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class TblMleJpaController method destroy.
public void destroy(Integer id) throws IllegalOrphanException, NonexistentEntityException {
EntityManager em = getEntityManager();
try {
em.getTransaction().begin();
TblMle tblMle;
try {
tblMle = em.getReference(TblMle.class, id);
tblMle.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The tblMle with id " + id + " no longer exists.", enfe);
}
List<String> illegalOrphanMessages = null;
Collection<TblHosts> tblHostsCollectionOrphanCheck = tblMle.getTblHostsCollection();
for (TblHosts tblHostsCollectionOrphanCheckTblHosts : tblHostsCollectionOrphanCheck) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblHosts " + tblHostsCollectionOrphanCheckTblHosts + " in its tblHostsCollection field has a non-nullable vmmMleId field.");
}
Collection<TblHosts> tblHostsCollection1OrphanCheck = tblMle.getTblHostsCollection1();
for (TblHosts tblHostsCollection1OrphanCheckTblHosts : tblHostsCollection1OrphanCheck) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblHosts " + tblHostsCollection1OrphanCheckTblHosts + " in its tblHostsCollection1 field has a non-nullable biosMleId field.");
}
Collection<TblPcrManifest> tblPcrManifestCollectionOrphanCheck = tblMle.getTblPcrManifestCollection();
for (TblPcrManifest tblPcrManifestCollectionOrphanCheckTblPcrManifest : tblPcrManifestCollectionOrphanCheck) {
if (illegalOrphanMessages == null) {
illegalOrphanMessages = new ArrayList<String>();
}
illegalOrphanMessages.add("This TblMle (" + tblMle + ") cannot be destroyed since the TblPcrManifest " + tblPcrManifestCollectionOrphanCheckTblPcrManifest + " in its tblPcrManifestCollection field has a non-nullable mleId field.");
}
if (illegalOrphanMessages != null) {
throw new IllegalOrphanException(illegalOrphanMessages);
}
em.remove(tblMle);
em.getTransaction().commit();
} finally {
em.close();
}
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class AssetTagCertBO method mapAssetTagCertToHost.
/**
* This function would be used to associate a asset tag certificate with the host for which it is
* provisioned for. It does not require you know the ID of the host you are associating to.
* Here you are giving the hash of the cert to the code and letting it find a matching host
* @param atagObj
* @return true if host was found, false if not
*/
public boolean mapAssetTagCertToHost(AssetTagCertAssociateRequest atagObj) throws CryptographyException {
boolean result = false;
log.debug("mapAssetTagCertToHost");
AssetTagCertAssociateRequest request = new AssetTagCertAssociateRequest();
if (atagObj.getSha1OfAssetCert() != null) {
log.debug("trying to associate tag to existing host using " + Hex.encodeHexString(atagObj.getSha1OfAssetCert()));
//List<MwAssetTagCertificate> atagCerts = My.jpa().mwAssetTagCertificate().findAssetTagCertificateBySha1Hash(atagObj.getSha1OfAssetCert());
MwAssetTagCertificateJpaController mwAssetTagCertificateJpaController = new MwAssetTagCertificateJpaController(getEntityManagerFactory());
List<MwAssetTagCertificate> atagCerts = mwAssetTagCertificateJpaController.findAssetTagCertificateBySha1Hash(atagObj.getSha1OfAssetCert());
// List<MwAssetTagCertificate> atagCerts = My.jpa().mwAssetTagCertificate().findAssetTagCertificatesByHostUUID("494cb5dc-a3e1-4e46-9b52-e694349b1654");
if (atagCerts.isEmpty()) {
log.error("mapAssetTagCertToHost: The asset tag certificate does not exist");
throw new ASException(ErrorCode.AS_INVALID_ASSET_TAG_CERTIFICATE_HASH);
} else if (atagCerts.size() > 1) {
log.error("mapAssetTagCertToHost: There were multiple matches for the specified hash");
throw new ASException(ErrorCode.AS_INVALID_ASSET_TAG_CERTIFICATE_HASH);
} else {
MwAssetTagCertificate atagCert = atagCerts.get(0);
request.setSha1OfAssetCert(atagCert.getSHA1Hash());
String uuid = atagCert.getUuid().toLowerCase().trim();
log.debug("searching using " + uuid);
//TblHosts tblHost = My.jpa().mwHosts().findByHwUUID(uuid);
TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
TblHosts tblHost = tblHostsJpaController.findByHwUUID(uuid);
if (tblHost != null) {
log.debug("found host matching uuid of cert, going to assoicate with host id = " + tblHost.getId());
request.setHostID(tblHost.getId());
//atagObj.setHostID(tblHost.getId());
result = mapAssetTagCertToHostById(request);
} else {
log.debug("found no matching uuid of cert");
result = false;
}
}
}
return result;
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class TblHostsJpaController method findByIPAddress.
public TblHosts findByIPAddress(String ipAddress) {
TblHosts host = null;
EntityManager em = getEntityManager();
try {
Query query = em.createNamedQuery("TblHosts.findByIPAddress");
query.setParameter("iPAddress", ipAddress);
List<TblHosts> list = query.getResultList();
if (list != null && list.size() > 0) {
host = list.get(0);
}
} finally {
em.close();
}
return host;
}
use of com.intel.mtwilson.as.data.TblHosts in project OpenAttestation by OpenAttestation.
the class TblHostsJpaController method findByName.
public TblHosts findByName(String name) {
TblHosts host = null;
EntityManager em = getEntityManager();
try {
Query query = em.createNamedQuery("TblHosts.findByName");
query.setParameter("name", name);
List<TblHosts> list = query.getResultList();
if (list != null && list.size() > 0) {
host = list.get(0);
}
} finally {
em.close();
}
return host;
}
Aggregations