Search in sources :

Example 41 with GFacException

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);
}
Also used : StringWriter(java.io.StringWriter) GFacException(org.apache.airavata.gfac.core.GFacException) UNICORESecurityContext(org.apache.airavata.gfac.bes.security.UNICORESecurityContext) AppCatalogException(org.apache.airavata.registry.cpi.AppCatalogException) GFacException(org.apache.airavata.gfac.core.GFacException) GFacHandlerException(org.apache.airavata.gfac.core.handler.GFacHandlerException) GFacHandlerException(org.apache.airavata.gfac.core.handler.GFacHandlerException) PrintWriter(java.io.PrintWriter)

Example 42 with GFacException

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;
}
Also used : GFacException(org.apache.airavata.gfac.core.GFacException) DefaultClientConfiguration(eu.unicore.util.httpclient.DefaultClientConfiguration) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) GFacException(org.apache.airavata.gfac.core.GFacException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 43 with GFacException

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;
}
Also used : X509Credential(eu.emi.security.authn.x509.X509Credential) GFacException(org.apache.airavata.gfac.core.GFacException) DefaultClientConfiguration(eu.unicore.util.httpclient.DefaultClientConfiguration) GFacException(org.apache.airavata.gfac.core.GFacException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 44 with GFacException

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);
    }
}
Also used : PrivateKey(java.security.PrivateKey) GFacException(org.apache.airavata.gfac.core.GFacException) KeyAndCertCredential(eu.emi.security.authn.x509.impl.KeyAndCertCredential) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Example 45 with GFacException

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);
        }
    }
}
Also used : TaskContext(org.apache.airavata.gfac.core.context.TaskContext) GFacException(org.apache.airavata.gfac.core.GFacException) GFacWorker(org.apache.airavata.gfac.impl.GFacWorker) JobModel(org.apache.airavata.model.job.JobModel) ProcessContext(org.apache.airavata.gfac.core.context.ProcessContext)

Aggregations

GFacException (org.apache.airavata.gfac.core.GFacException)73 IOException (java.io.IOException)24 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)19 ProcessContext (org.apache.airavata.gfac.core.context.ProcessContext)16 JSchException (com.jcraft.jsch.JSchException)15 RegistryException (org.apache.airavata.registry.cpi.RegistryException)15 AiravataException (org.apache.airavata.common.exception.AiravataException)14 TaskStatus (org.apache.airavata.model.status.TaskStatus)13 URISyntaxException (java.net.URISyntaxException)12 ErrorModel (org.apache.airavata.model.commons.ErrorModel)11 CredentialStoreException (org.apache.airavata.credential.store.store.CredentialStoreException)10 TException (org.apache.thrift.TException)9 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)8 DefaultClientConfiguration (eu.unicore.util.httpclient.DefaultClientConfiguration)7 URI (java.net.URI)7 OutputDataObjectType (org.apache.airavata.model.application.io.OutputDataObjectType)7 Session (com.jcraft.jsch.Session)6 InvalidKeyException (java.security.InvalidKeyException)6 RemoteCluster (org.apache.airavata.gfac.core.cluster.RemoteCluster)6 JobModel (org.apache.airavata.model.job.JobModel)6