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);
}
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);
}
}
Aggregations