Search in sources :

Example 1 with ApiException

use of com.intel.mtwilson.ApiException 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);
}
Also used : Hostname(com.intel.mtwilson.util.net.Hostname) IOException(java.io.IOException) SignatureException(java.security.SignatureException) HashSet(java.util.HashSet) ApiException(com.intel.mtwilson.ApiException)

Aggregations

ApiException (com.intel.mtwilson.ApiException)1 Hostname (com.intel.mtwilson.util.net.Hostname)1 IOException (java.io.IOException)1 SignatureException (java.security.SignatureException)1 HashSet (java.util.HashSet)1