use of com.intel.mtwilson.as.controller.TblHostsJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method checkForDuplicate.
private void checkForDuplicate(TxtHost host) throws CryptographyException {
TblHostsJpaController tblHostsJpaController = getHostsJpaController();
TblHosts tblHosts1 = tblHostsJpaController.findByName(host.getHostName().toString());
TblHosts tblHosts2 = tblHostsJpaController.findByIPAddress(host.getIPAddress().toString());
if (tblHosts1 != null) {
throw new ASException(ErrorCode.AS_HOST_EXISTS, host.getHostName());
}
if (tblHosts2 != null) {
throw new ASException(ErrorCode.AS_IPADDRESS_EXISTS, host.getIPAddress().toString());
}
}
use of com.intel.mtwilson.as.controller.TblHostsJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method getHostByName.
/**
* This is not a REST API method, it is public because it is used by
* HostTrustBO.
*
* @param hostName
* @return
* @throws CryptographyException
*/
public TblHosts getHostByName(Hostname hostName) throws CryptographyException {
// datatype.Hostname
TblHosts tblHosts = new TblHosts();
try {
InetAddress addr = InetAddress.getByName(hostName.toString());
String hostname = addr.getHostName();
String ip = addr.getHostAddress();
tblHosts = new TblHostsJpaController(getEntityManagerFactory()).findByName(hostname);
tblHosts = tblHosts != null ? tblHosts : new TblHostsJpaController(getEntityManagerFactory()).findByName(ip);
} catch (UnknownHostException e) {
log.error("Unknown host", e);
}
return tblHosts;
}
use of com.intel.mtwilson.as.controller.TblHostsJpaController 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.controller.TblHostsJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method queryForHosts.
/**
* Author: Sudhir
*
* Searches for the hosts using the criteria specified.
*
* @param searchCriteria: If in case the user has not provided any
* search criteria, then all the hosts would be returned back to the
* caller
* @param includeHardwareUuid: if this is set to true, it causes the resulting
* TxtHostRecord to include the hardware_uuid field from the tblHost
* @return
*/
public List<TxtHostRecord> queryForHosts(String searchCriteria, boolean includeHardwareUuid) {
log.debug("queryForHost " + searchCriteria + " includeHardwareUuid[" + includeHardwareUuid + "]");
try {
//TblHostsJpaController tblHostsJpaController = My.jpa().mwHosts(); //new TblHostsJpaController(getEntityManagerFactory());
TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
List<TxtHostRecord> txtHostList = new ArrayList<TxtHostRecord>();
List<TblHosts> tblHostList;
if (searchCriteria != null && !searchCriteria.isEmpty()) {
tblHostList = tblHostsJpaController.findHostsByNameSearchCriteria(searchCriteria);
} else {
tblHostList = tblHostsJpaController.findTblHostsEntities();
}
if (tblHostList != null) {
log.debug(String.format("Found [%d] host results for search criteria [%s]", tblHostList.size(), searchCriteria));
for (TblHosts tblHosts : tblHostList) {
TxtHostRecord hostObj = createTxtHostFromDatabaseRecord(tblHosts, includeHardwareUuid);
txtHostList.add(hostObj);
}
} else {
log.debug(String.format("Found no hosts for search criteria [%s]", searchCriteria));
}
return txtHostList;
} catch (ASException e) {
throw e;
} catch (Exception e) {
// throw new ASException(e);
// Bug: 1038 - prevent leaks in error messages to client
log.error("Error during querying for registered hosts.", e);
throw new ASException(ErrorCode.AS_QUERY_HOST_ERROR, e.getClass().getSimpleName());
}
}
use of com.intel.mtwilson.as.controller.TblHostsJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method isHostRegistered.
public HostResponse isHostRegistered(String hostnameOrAddress) {
try {
TblHostsJpaController tblHostsJpaController = new TblHostsJpaController(getEntityManagerFactory());
TblHosts tblHosts = tblHostsJpaController.findByName(hostnameOrAddress);
if (tblHosts != null) {
// host name exists in database
return new HostResponse(ErrorCode.OK);
}
tblHosts = tblHostsJpaController.findByIPAddress(hostnameOrAddress);
if (tblHosts != null) {
// host IP address exists in database
return new HostResponse(ErrorCode.OK);
}
return new HostResponse(ErrorCode.AS_HOST_NOT_FOUND);
} catch (ASException e) {
throw e;
} catch (Exception e) {
throw new ASException(e);
}
}
Aggregations