use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class DemoPortalServicesImpl method deleteHostDetails.
/**
* This method will delete HOST information from Services.
* Also it will delete all entry from HOST VM Mapping information for that host, which is used to store Policy of VM.
*
* @param hostID
* @param hostName
* @param apiClientServices
* @param vmMappingData
* @return
* @throws DemoPortalException
*/
@Override
public boolean deleteHostDetails(String hostID, String hostName, AttestationService apiClientServices) throws DemoPortalException {
boolean result = false;
try {
//Call to Services to delete HOST.
apiClientServices.deleteHost(new Hostname(hostName));
result = true;
} catch (Exception e) {
log.error("Errror While Deleting Host.");
throw ConnectionUtil.handleException(e);
}
return result;
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class DemoPortalServicesImpl method trustVerificationDetails.
/**
* This method is used to get SAML Assertion data for a Host.
* This data is shown in pop-up window when user click on trust details button in Home page to TrustDashBoard.
*
* @param hostName
* @param apiClientServices
* @param trustedCertificates
* @return
* @throws DemoPortalException
* @throws java.io.IOException
* @throws com.intel.mtwilson.ApiException
*/
@Override
public String trustVerificationDetails(String hostName, AttestationService apiClientServices, X509Certificate[] trustedCertificates) throws DemoPortalException {
//return ConverterUtil.formateXMLString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<error>Not implemented</error>\n");
Set<Hostname> hostnames = new HashSet<Hostname>();
hostnames.add(new Hostname(hostName));
try {
return ConverterUtil.formateXMLString(apiClientServices.getSamlForMultipleHosts(hostnames, true));
} catch (IOException | ApiException | SignatureException e) {
log.error(e.getMessage());
return ConverterUtil.formateXMLString("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<error>Not implemented</error>\n");
}
// log.info("DemoPortalServicesImpl.trustVerificationDetails >>");
// String xmloutput = null;
// Set<Hostname> hostnames = new HashSet<Hostname>();
// //log.info("<<<<<<Hostname: " + hostName + ">>>>>>>");
// hostnames.add(new Hostname(hostName));
// try {
// //calling into Services to get SAML for a Host.
// List<HostTrustXmlResponse> trust = apiClientServices.getSamlForMultipleHosts(hostnames, false);
//
// for (HostTrustXmlResponse hostTrustXmlResponse : trust) {
// if(trustedCertificates != null)
// log.info("TrustCertificates: " + trustedCertificates.toString());
// else
// log.info("TrustCertificates is null");
// if(hostTrustXmlResponse != null)
// log.info("HostTrustXMLResponse: " + hostTrustXmlResponse.getAssertion());
// else
// log.info("HostTrustXMLResponse is null");
//
// TrustAssertion trustAssertion = new TrustAssertion(trustedCertificates, hostTrustXmlResponse.getAssertion());
//
// if(trustAssertion != null)
// log.info("TrustAssertion: " + trustAssertion.toString());
// else
// log.info("TrustAssertion is null");
// if (trustAssertion.isValid()) {
// //Store SAML Assertion into a String.
// xmloutput = hostTrustXmlResponse.getAssertion();
// } else {
// log.error("Error While Getting SAML ." + hostTrustXmlResponse.getErrorCode() + ". " + hostTrustXmlResponse.getErrorMessage());
// throw new DemoPortalException("Error While Getting SAML. " + hostTrustXmlResponse.getErrorCode() + ". " + hostTrustXmlResponse.getErrorMessage());
// }
// }
// } catch (Exception e) {
// log.error(e.getMessage());
// e.printStackTrace();
// throw ConnectionUtil.handleDemoPortalException(e);
// }
//format a SAML String into a XML type using helper Function.
// return ConverterUtil.formateXMLString(xmloutput);
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class DemoPortalServicesImpl method getSingleHostTrust.
/**
* This Method is used to get Trust Status for Single Host.
*
* @param hostName
* @param apiClientServices
* @param trustedCertificates
* @return
* @throws DemoPortalException
*/
@Override
public TrustedHostVO getSingleHostTrust(String hostName, AttestationService apiClientServices, X509Certificate[] trustedCertificates, boolean forceVerify) throws DemoPortalException {
TrustedHostVO hostVO = null;
HostDetailsEntityVO hostDetailsEntityVO = new HostDetailsEntityVO();
hostDetailsEntityVO.setHostName(hostName);
String xmloutput = null;
HostTrustResponse hostTrustResponse = null;
try {
log.info("Getting trust Information for Host " + hostName);
//xmloutput = apiClientServices.getSamlForHost(new Hostname(hostName), false);
// forceVerify=false when loading dashboard, it is true when refreshing host (Refresh button)
xmloutput = apiClientServices.getSamlForHost(new Hostname(hostName), forceVerify);
TrustAssertion trustAssertion = new TrustAssertion(trustedCertificates, xmloutput);
HostTrustAssertion hostTrustAssertion = trustAssertion.getTrustAssertion(hostName);
//Set<Hostname> hostnames = new HashSet<Hostname>();
//hostnames.add(new Hostname(hostName));
//xmloutput = ConverterUtil.formateXMLString(apiClientServices.getSamlForMultipleHosts(hostnames, false));
hostTrustResponse = apiClientServices.getHostTrust(new Hostname(hostDetailsEntityVO.getHostName()));
List<TxtHostRecord> hosts = apiClientServices.queryForHosts(hostDetailsEntityVO.getHostName());
TxtHostRecord txtHostRecord = null;
for (TxtHostRecord record : hosts) {
if (record.HostName.equals(hostDetailsEntityVO.getHostName())) {
txtHostRecord = record;
}
}
hostVO = ConverterUtil.getTrustedHostVoFromHostTrustResponseAndTxtHostRecord(hostTrustResponse, txtHostRecord, hostTrustAssertion);
} catch (Exception e) {
hostVO = ConverterUtil.getTrustedHostVoFromHostTrustResponseAndErrorMessage(hostName, e.getMessage());
}
return hostVO;
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class DemoPortalServicesImpl method getFailureReportData.
/**
* This method is used to get failure report for Host.
*
* @param hostName
* @param attestationService
* @return
* @throws DemoPortalException
* @throws Exception
*/
@Override
public List<PcrLogReport> getFailureReportData(String hostName, ApiClient attestationService) throws Exception {
log.info("DemoPortalServicesImpl.getFailureReportData >>");
AttestationReport report;
try {
report = attestationService.getAttestationReport(new Hostname(hostName));
} catch (Exception e) {
log.error(e.getMessage());
throw ConnectionUtil.handleException(e);
}
return report.getPcrLogs();
}
use of com.intel.mtwilson.util.net.Hostname in project OpenAttestation by OpenAttestation.
the class DemoPortalServicesImpl method updateHostData.
/**
* This method is used to Update Host information, which was already configure.
*
* @param dataVO
* @param apiClientServices
* @return
* @throws DemoPortalException
*/
@Override
public boolean updateHostData(HostDetailsEntityVO dataVO, AttestationService apiClientServices) throws DemoPortalException {
boolean result = false;
try {
//Call to Services to Update pre-configure host information.
apiClientServices.updateHost(ConverterUtil.getTxtHostFromHostVO(dataVO));
// Updating the SAML host report
apiClientServices.getSamlForHost(new Hostname(dataVO.getHostName()), true);
result = true;
} catch (Exception e) {
log.error("Errror While Updating Host.");
throw ConnectionUtil.handleException(e);
}
return result;
}
Aggregations