use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class AbstractSMSHandler method initSecurityProperties.
protected void initSecurityProperties(JobExecutionContext jobExecutionContext) throws GFacHandlerException {
log.debug("Initializing SMSInHandler security properties ..");
if (secProperties != null) {
secProperties = secProperties.clone();
return;
}
UNICORESecurityContext unicoreContext;
try {
if (jobExecutionContext.getSecurityContext(X509SecurityContext.X509_SECURITY_CONTEXT) == null) {
SecurityUtils.addSecurityContext(jobExecutionContext);
log.info("Successfully added the UNICORE Security Context");
}
} catch (Exception e) {
log.error(e.getMessage());
try {
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
GFacUtils.saveErrorDetails(jobExecutionContext, errors.toString(), CorrectiveAction.CONTACT_SUPPORT, ErrorCategory.AIRAVATA_INTERNAL_ERROR);
} catch (GFacException e1) {
log.error(e1.getLocalizedMessage());
}
throw new GFacHandlerException("Error while creating UNICORESecurityContext", e, e.getLocalizedMessage());
}
try {
unicoreContext = (UNICORESecurityContext) jobExecutionContext.getSecurityContext(X509SecurityContext.X509_SECURITY_CONTEXT);
log.info("Successfully retrieved the UNICORE Security Context");
} catch (GFacException e) {
throw new GFacHandlerException(e);
}
if (log.isDebugEnabled()) {
log.debug("Generating client's default security configuration..");
}
// TODO: check what kind of credential (server signed or myproxy) should be used
try {
secProperties = unicoreContext.getDefaultConfiguration(false);
} catch (Exception e) {
throw new GFacHandlerException(e);
}
if (log.isDebugEnabled()) {
log.debug("Security properties are initialized.");
}
jobExecutionContext.setProperty(PROP_CLIENT_CONF, secProperties);
}
use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class UNICORESecurityContext method getServerSignedConfiguration.
/**
* Get server signed credentials. Each time it is invoked new certificate
* is returned.
*
* @param userID
* @param userDN
* @param caCertPath
* @param caKeyPath
* @param caKeyPwd
* @return
* @throws GFacException
*/
public DefaultClientConfiguration getServerSignedConfiguration(String userID, String userDN, String caCertPath, String caKeyPath, String caKeyPwd) throws GFacException {
try {
KeyAndCertCredential cred = SecurityUtils.generateShortLivedCertificate(userDN, caCertPath, caKeyPath, caKeyPwd);
secProperties = new DefaultClientConfiguration(dcValidator, cred);
setExtraSettings();
} catch (Exception e) {
throw new GFacException(e.getMessage(), e);
}
return secProperties;
}
use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class UNICORESecurityContext method getDefaultConfiguration.
public DefaultClientConfiguration getDefaultConfiguration(Boolean enableMessageLogging) throws GFacException, ApplicationSettingsException {
try {
X509Credential cred = getX509Credentials();
secProperties = new DefaultClientConfiguration(dcValidator, cred);
setExtraSettings();
} catch (Exception e) {
throw new GFacException(e.getMessage(), e);
}
if (enableMessageLogging)
secProperties.setMessageLogging(true);
return secProperties;
}
use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class X509SecurityContext method getDefaultCredentials.
/**
* Gets the default proxy certificate.
* @return Default my proxy credentials.
* @throws org.apache.airavata.common.exception.ApplicationSettingsException
*/
public X509Credential getDefaultCredentials() throws GFacException, ApplicationSettingsException {
MyProxyLogon logon = new MyProxyLogon();
logon.setValidator(dcValidator);
logon.setHost(getRequestData().getMyProxyServerUrl());
logon.setPort(getRequestData().getMyProxyPort());
logon.setUsername(getRequestData().getMyProxyUserName());
logon.setPassphrase(getRequestData().getMyProxyPassword().toCharArray());
logon.setLifetime(getRequestData().getMyProxyLifeTime());
try {
logon.connect();
logon.logon();
logon.getCredentials();
logon.disconnect();
PrivateKey pk = logon.getPrivateKey();
return new KeyAndCertCredential(pk, new X509Certificate[] { logon.getCertificate() });
} catch (Exception e) {
throw new GFacException("An error occurred while retrieving default security credentials.", e);
}
}
use of org.apache.airavata.gfac.core.GFacException in project airavata by apache.
the class EmailBasedMonitor method stopMonitor.
@Override
public void stopMonitor(String jobId, boolean runOutflow) {
TaskContext taskContext = jobMonitorMap.remove(jobId);
if (taskContext != null && runOutflow) {
try {
ProcessContext pc = taskContext.getParentProcessContext();
if (taskContext.isCancel()) {
// Moved job status to cancel
JobModel jobModel = pc.getJobModel();
JobStatus newJobStatus = new JobStatus(JobState.CANCELED);
newJobStatus.setReason("Moving job status to cancel, as we didn't see any email from this job " + "for a while after execute job cancel command. This may happen if job was in queued state " + "when we run the cancel command");
jobModel.setJobStatuses(Arrays.asList(newJobStatus));
GFacUtils.saveJobStatus(pc, jobModel);
}
ProcessStatus pStatus = new ProcessStatus(ProcessState.CANCELLING);
pStatus.setReason("Job cancelled");
pc.setProcessStatus(pStatus);
GFacUtils.saveAndPublishProcessStatus(pc);
GFacThreadPoolExecutor.getCachedThreadPool().execute(new GFacWorker(pc));
} catch (GFacException e) {
log.info("[EJM]: Error while running output tasks", e);
}
}
}
Aggregations