use of com.intel.mtwilson.as.controller.TblSamlAssertionJpaController in project OpenAttestation by OpenAttestation.
the class HostBO method deleteSAMLAssertions.
/**
* Deletes all the SAML assertions for the specified host. This should
* be called before deleting the host.
*
* @param hostId
*/
private void deleteSAMLAssertions(TblHosts hostId) throws IOException {
TblSamlAssertionJpaController samlJpaController = getSamlAssertionJpaController();
List<TblSamlAssertion> hostSAMLAssertions = samlJpaController.findByHostID(hostId);
if (hostSAMLAssertions != null) {
for (TblSamlAssertion hostSAML : hostSAMLAssertions) {
try {
samlJpaController.destroy(hostSAML.getId());
} catch (NonexistentEntityException e) {
log.error("Ta Log is already deleted " + hostSAML.getId());
}
}
log.info("Deleted all the logs for the given host " + hostId);
}
}
use of com.intel.mtwilson.as.controller.TblSamlAssertionJpaController in project OpenAttestation by OpenAttestation.
the class HostTrustBO method getTrustWithSaml.
public String getTrustWithSaml(TblHosts tblHosts, String hostId, String hostAttestationUuid, boolean forceVerify) throws IOException {
log.debug("getTrustWithSaml: Getting trust for host: " + tblHosts.getName() + " Force verify flag: " + forceVerify);
// Bug: 702: For host not supporting TXT, we need to return back a proper error
// make sure the DEK is set for this thread
// My.initDataEncryptionKey();
// TblHosts tblHosts = getHostByName(new Hostname((host)));
HostAgentFactory factory = new HostAgentFactory();
HostAgent agent = factory.getHostAgent(tblHosts);
if (!agent.isTpmAvailable()) {
throw new ASException(ErrorCode.AS_TPM_NOT_SUPPORTED, hostId);
}
if (forceVerify != true) {
//TblSamlAssertion tblSamlAssertion = new TblSamlAssertionJpaController((getEntityManagerFactory())).findByHostAndExpiry(hostId);
//TblSamlAssertion tblSamlAssertion = My.jpa().mwSamlAssertion().findByHostAndExpiry(tblHosts.getName()); //hostId);
TblSamlAssertionJpaController tblSamlAssertionJpa = getSamlAssertionJpaController();
TblSamlAssertion tblSamlAssertion = tblSamlAssertionJpa.findByHostAndExpiry(tblHosts.getName());
if (tblSamlAssertion != null) {
if (tblSamlAssertion.getErrorMessage() == null || tblSamlAssertion.getErrorMessage().isEmpty()) {
log.debug("Found assertion in cache. Expiry time : " + tblSamlAssertion.getExpiryTs());
//HostAttestation ha = new HostAttestation();
return buildHostAttestation(tblHosts, tblSamlAssertion).getSaml();
} else {
log.debug("Found assertion in cache with error set, returning that.");
throw new ASException(new Exception("(" + tblSamlAssertion.getErrorCode() + ") " + tblSamlAssertion.getErrorMessage() + " (cached on " + tblSamlAssertion.getCreatedTs().toString() + ")"));
}
}
}
log.debug("Getting trust and saml assertion from host.");
try {
// return getTrustWithSaml(tblHosts, hostId);
return getTrustWithSaml(tblHosts, hostId, hostAttestationUuid);
} catch (Exception e) {
TblSamlAssertion tblSamlAssertion = new TblSamlAssertion();
tblSamlAssertion.setAssertionUuid(hostAttestationUuid);
tblSamlAssertion.setHostId(tblHosts);
//TxtHost hostTxt = getHostWithTrust(new Hostname(host),tblSamlAssertion);
//TxtHostRecord tmp = new TxtHostRecord();
//tmp.HostName = host;
//tmp.IPAddress = host;
//TxtHost hostTxt = new TxtHost(tmp);
tblSamlAssertion.setBiosTrust(false);
tblSamlAssertion.setVmmTrust(false);
try {
log.error("Caught exception, generating saml assertion");
log.error("Printing stacktrace first");
e.printStackTrace();
tblSamlAssertion.setSaml("");
int cacheTimeout = ASConfig.getConfiguration().getInt("saml.validity.seconds", 3600);
tblSamlAssertion.setCreatedTs(Calendar.getInstance().getTime());
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, cacheTimeout);
tblSamlAssertion.setExpiryTs(cal.getTime());
if (e instanceof ASException) {
ASException ase = (ASException) e;
log.debug("e is an instance of ASExpection: " + String.valueOf(ase.getErrorCode()));
tblSamlAssertion.setErrorCode(String.valueOf(ase.getErrorCode()));
} else {
log.debug("e is NOT an instance of ASExpection: " + String.valueOf(ErrorCode.AS_HOST_TRUST_ERROR.getErrorCode()));
tblSamlAssertion.setErrorCode(String.valueOf(ErrorCode.AS_HOST_TRUST_ERROR.getErrorCode()));
}
// tblSamlAssertion.setErrorMessage(e.getMessage());
// Bug fix for 1038
tblSamlAssertion.setErrorMessage(e.getClass().getSimpleName());
getSamlAssertionJpaController().create(tblSamlAssertion);
} catch (Exception ex) {
//log.debug("getTrustwithSaml caugh exception while generating error saml assertion");
log.error("getTrustwithSaml caugh exception while generating error saml assertion", ex);
// String msg = ex.getMessage();
String msg = ex.getClass().getSimpleName();
// throw new ASException(new Exception("getTrustWithSaml " + msg));
throw new ASException(ex, ErrorCode.AS_HOST_TRUST_ERROR, msg);
//throw new ASException(new Exception("Host Manifest is missing required PCRs."));
}
//Daniel, change the messages into meaningful thiings here
//log.debug("e.getMessage = "+e.getMessage());
//throw new ASException(new Exception(e.getMessage()));
log.error("Error during retrieval of host trust status.", e);
throw new ASException(e, ErrorCode.AS_HOST_TRUST_ERROR, e.getClass().getSimpleName());
//throw new ASException(new Exception("Host Manifest is missing required PCRs."));
}
}
Aggregations