Search in sources :

Example 1 with UNICORESecurityContext

use of org.apache.airavata.gfac.bes.security.UNICORESecurityContext 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 2 with UNICORESecurityContext

use of org.apache.airavata.gfac.bes.security.UNICORESecurityContext in project airavata by apache.

the class SecurityUtils method addSecurityContext.

public static void addSecurityContext(ProcessContext processContext) throws GFacException {
    if (!processContext.getJobSubmissionProtocol().equals(JobSubmissionProtocol.UNICORE)) {
        logger.error("This is a wrong method to invoke for UNICORE host types,please check your gfac-config.xml");
    } else {
        // set by the framework
        String credentialStoreToken = processContext.getTokenId();
        RequestData requestData;
        try {
            requestData = new RequestData(ServerSettings.getDefaultUserGateway());
        } catch (ApplicationSettingsException e1) {
            throw new GFacException(e1);
        }
        // coming from top tier
        requestData.setTokenId(credentialStoreToken);
        CredentialReader credentialReader = null;
        try {
            credentialReader = GFacUtils.getCredentialReader();
        } catch (Exception e) {
            logger.warn("Cannot get credential reader instance");
        }
        UNICORESecurityContext secCtx = new UNICORESecurityContext(credentialReader, requestData);
    // processContext.addSecurityContext(X509SecurityContext.X509_SECURITY_CONTEXT, secCtx);
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) GFacException(org.apache.airavata.gfac.core.GFacException) UNICORESecurityContext(org.apache.airavata.gfac.bes.security.UNICORESecurityContext) RequestData(org.apache.airavata.gfac.core.RequestData) CredentialReader(org.apache.airavata.credential.store.store.CredentialReader) GFacException(org.apache.airavata.gfac.core.GFacException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException)

Aggregations

UNICORESecurityContext (org.apache.airavata.gfac.bes.security.UNICORESecurityContext)2 GFacException (org.apache.airavata.gfac.core.GFacException)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 InvalidKeyException (java.security.InvalidKeyException)1 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)1 CredentialReader (org.apache.airavata.credential.store.store.CredentialReader)1 RequestData (org.apache.airavata.gfac.core.RequestData)1 GFacHandlerException (org.apache.airavata.gfac.core.handler.GFacHandlerException)1 AppCatalogException (org.apache.airavata.registry.cpi.AppCatalogException)1