airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shame...@apache.org
Subject [1/2] airavata git commit: use compute resource preference and storeage preference instead of property file to read ssh keys and username
Date Mon, 14 Dec 2015 20:49:47 GMT
Repository: airavata
Updated Branches:
  refs/heads/master 8f820e5a5 -> c09cc861c


use compute resource preference and storeage preference instead of property file to read ssh
keys and username


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/f1c4c970
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/f1c4c970
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/f1c4c970

Branch: refs/heads/master
Commit: f1c4c9707d5984e1ae409f8178b62bc06c393e14
Parents: bd457c2
Author: Shameera Rathnayaka <shameerainfo@gmail.com>
Authored: Mon Dec 14 15:49:21 2015 -0500
Committer: Shameera Rathnayaka <shameerainfo@gmail.com>
Committed: Mon Dec 14 15:49:21 2015 -0500

----------------------------------------------------------------------
 .../authentication/SSHKeyAuthentication.java    | 20 ++---
 .../gfac/core/context/ProcessContext.java       | 11 +++
 .../org/apache/airavata/gfac/impl/Factory.java  | 92 +++++++++++++++-----
 .../airavata/gfac/impl/GFacEngineImpl.java      |  3 +-
 .../airavata/gfac/impl/HPCRemoteCluster.java    |  3 +-
 .../gfac/impl/task/SCPDataStageTask.java        | 61 +------------
 .../gfac/impl/task/utils/StreamData.java        | 44 +---------
 7 files changed, 99 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java
b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java
index 191d7a8..6457d7b 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/authentication/SSHKeyAuthentication.java
@@ -31,8 +31,8 @@ package org.apache.airavata.gfac.core.authentication;/*
 public class SSHKeyAuthentication implements AuthenticationInfo {
 
 	private String userName;
-	private String privateKeyFilePath;
-	private String publicKeyFilePath;
+	private byte[] privateKey;
+	private byte[] publicKey;
 	private String passphrase;
 	private String knownHostsFilePath;
 	private String strictHostKeyChecking; // yes or no
@@ -48,20 +48,20 @@ public class SSHKeyAuthentication implements AuthenticationInfo {
 		this.userName = userName;
 	}
 
-	public String getPrivateKeyFilePath() {
-		return privateKeyFilePath;
+	public byte[] getPrivateKey() {
+		return privateKey;
 	}
 
-	public void setPrivateKeyFilePath(String privateKeyFilePath) {
-		this.privateKeyFilePath = privateKeyFilePath;
+	public void setPrivateKey(byte[] privateKey) {
+		this.privateKey = privateKey;
 	}
 
-	public String getPublicKeyFilePath() {
-		return publicKeyFilePath;
+	public byte[] getPublicKey() {
+		return publicKey;
 	}
 
-	public void setPublicKeyFilePath(String publicKeyFilePath) {
-		this.publicKeyFilePath = publicKeyFilePath;
+	public void setPublicKey(byte[] publicKey) {
+		this.publicKey = publicKey;
 	}
 
 	public String getPassphrase() {

http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
index 49b323c..02d4cbc 100644
--- a/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
+++ b/modules/gfac/gfac-core/src/main/java/org/apache/airavata/gfac/core/context/ProcessContext.java
@@ -22,6 +22,7 @@
 package org.apache.airavata.gfac.core.context;
 
 import org.apache.airavata.common.utils.AiravataUtils;
+import org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication;
 import org.apache.airavata.gfac.core.cluster.RemoteCluster;
 import org.apache.airavata.gfac.core.cluster.ServerInfo;
 import org.apache.airavata.messaging.core.Publisher;
@@ -95,6 +96,7 @@ public class ProcessContext {
     private boolean recovery = false; // is process in recovery mode?
     private TaskModel currentExecutingTaskModel; // current execution task model in case
we pause process execution we need this to continue process exectuion again
 	private boolean acknowledge;
+	private SSHKeyAuthentication sshKeyAuthentication;
 
 	/**
 	 * Note: process context property use lazy loading approach. In runtime you will see some
properties as null
@@ -491,4 +493,13 @@ public class ProcessContext {
 	public boolean isAcknowledge() {
 		return acknowledge;
 	}
+
+	public SSHKeyAuthentication getSshKeyAuthentication() {
+		return sshKeyAuthentication;
+	}
+
+	public void setSshKeyAuthentication(SSHKeyAuthentication sshKeyAuthentication) {
+		this.sshKeyAuthentication = sshKeyAuthentication;
+	}
 }
+

http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
index 328ddd3..e571701 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/Factory.java
@@ -27,8 +27,13 @@ import com.jcraft.jsch.UserInfo;
 import org.apache.airavata.common.exception.AiravataException;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.ServerSettings;
+import org.apache.airavata.credential.store.credential.Credential;
+import org.apache.airavata.credential.store.credential.impl.ssh.SSHCredential;
+import org.apache.airavata.credential.store.store.CredentialReader;
+import org.apache.airavata.credential.store.store.CredentialStoreException;
 import org.apache.airavata.gfac.core.GFacEngine;
 import org.apache.airavata.gfac.core.GFacException;
+import org.apache.airavata.gfac.core.GFacUtils;
 import org.apache.airavata.gfac.core.JobManagerConfiguration;
 import org.apache.airavata.gfac.core.authentication.AuthenticationInfo;
 import org.apache.airavata.gfac.core.authentication.SSHKeyAuthentication;
@@ -55,7 +60,11 @@ import org.apache.airavata.messaging.core.Publisher;
 import org.apache.airavata.messaging.core.impl.RabbitMQProcessLaunchConsumer;
 import org.apache.airavata.messaging.core.impl.RabbitMQStatusPublisher;
 import org.apache.airavata.model.appcatalog.computeresource.*;
+import org.apache.airavata.model.appcatalog.gatewayprofile.ComputeResourcePreference;
+import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
+import org.apache.airavata.model.commons.ErrorModel;
 import org.apache.airavata.model.data.movement.DataMovementProtocol;
+import org.apache.airavata.model.status.TaskState;
 import org.apache.airavata.registry.core.experiment.catalog.impl.RegistryFactory;
 import org.apache.airavata.registry.cpi.AppCatalog;
 import org.apache.airavata.registry.cpi.AppCatalogException;
@@ -71,6 +80,7 @@ import org.slf4j.LoggerFactory;
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.UUID;
 
 public abstract class Factory {
 
@@ -209,7 +219,6 @@ public abstract class Factory {
         JobSubmissionProtocol jobSubmissionProtocol = processContext.getJobSubmissionProtocol();
         String key = jobSubmissionProtocol.name() + ":" + computeResourceId;
 		RemoteCluster remoteCluster = remoteClusterMap.get(key);
-        String loginUserName = processContext.getComputeResourcePreference().getLoginUserName();
         if (remoteCluster == null) {
             JobManagerConfiguration jobManagerConfiguration = getJobManagerConfiguration(processContext.getResourceJobManager());
             if (jobSubmissionProtocol == JobSubmissionProtocol.LOCAL ||
@@ -217,8 +226,8 @@ public abstract class Factory {
                 remoteCluster = new LocalRemoteCluster(processContext.getServerInfo(), jobManagerConfiguration,
null);
             } else if (jobSubmissionProtocol == JobSubmissionProtocol.SSH ||
                     jobSubmissionProtocol == JobSubmissionProtocol.SSH_FORK) {
-                AuthenticationInfo authenticationInfo = getSSHKeyAuthentication(loginUserName);
-                remoteCluster = new HPCRemoteCluster(processContext.getServerInfo(), jobManagerConfiguration,
authenticationInfo);
+                remoteCluster = new HPCRemoteCluster(processContext.getServerInfo(), jobManagerConfiguration,
+                        processContext.getSshKeyAuthentication());
             }
             remoteClusterMap.put(key, remoteCluster);
 		}
@@ -231,15 +240,14 @@ public abstract class Factory {
         String computeResourceId = processContext.getComputeResourceId();
         DataMovementProtocol dataMovementProtocol = processContext.getDataMovementProtocol();
         String key = dataMovementProtocol.name() + ":" + computeResourceId;
-        String loginUserName = processContext.getComputeResourcePreference().getLoginUserName();
         RemoteCluster remoteCluster = remoteClusterMap.get(key);
         if (remoteCluster == null) {
             JobManagerConfiguration jobManagerConfiguration = getJobManagerConfiguration(processContext.getResourceJobManager());
             if (dataMovementProtocol == DataMovementProtocol.LOCAL) {
                 remoteCluster = new LocalRemoteCluster(processContext.getServerInfo(), jobManagerConfiguration,
null);
             } else if (dataMovementProtocol == DataMovementProtocol.SCP) {
-                AuthenticationInfo authenticationInfo = getSSHKeyAuthentication(loginUserName);
-                remoteCluster = new HPCRemoteCluster(processContext.getServerInfo(), jobManagerConfiguration,
authenticationInfo);
+                remoteCluster = new HPCRemoteCluster(processContext.getServerInfo(), jobManagerConfiguration,
+                        processContext.getSshKeyAuthentication());
             }
 
             remoteClusterMap.put(key, remoteCluster);
@@ -247,24 +255,64 @@ public abstract class Factory {
         return remoteCluster;
     }
 
-	private static SSHKeyAuthentication getSSHKeyAuthentication(String loginUserName) throws
ApplicationSettingsException {
-		SSHKeyAuthentication sshKA = new SSHKeyAuthentication();
-        if (loginUserName != null && !loginUserName.isEmpty()) {
+	public static SSHKeyAuthentication getComputerResourceSSHKeyAuthentication(ProcessContext
pc) throws GFacException {
+        try {
+            ComputeResourcePreference computeResourcePreference = pc.getComputeResourcePreference();
+            String loginUserName = computeResourcePreference.getLoginUserName();
+            String credentialStoreToken = computeResourcePreference.getResourceSpecificCredentialStoreToken();
+            if (credentialStoreToken == null) {
+                credentialStoreToken = pc.getGatewayResourceProfile().getCredentialStoreToken();
+            }
+            return getSshKeyAuthentication(pc.getGatewayId(),loginUserName, credentialStoreToken);
+        } catch (ApplicationSettingsException | IllegalAccessException | InstantiationException
| CredentialStoreException e) {
+            throw new GFacException("Couldn't build ssh authentication object", e);
+        }
+    }
+
+    public static SSHKeyAuthentication getStorageSSHKeyAuthentication(ProcessContext pc)
throws GFacException {
+        try {
+            StoragePreference storagePreference = pc.getStoragePreference();
+            String loginUserName = storagePreference.getLoginUserName();
+            String credentialStoreToken = storagePreference.getResourceSpecificCredentialStoreToken();
+            if (credentialStoreToken == null) {
+                credentialStoreToken = pc.getGatewayResourceProfile().getCredentialStoreToken();
+            }
+            return getSshKeyAuthentication(pc.getGatewayId(), loginUserName, credentialStoreToken);
+        }  catch (ApplicationSettingsException | IllegalAccessException | InstantiationException
| CredentialStoreException e) {
+            throw new GFacException("Couldn't build ssh authentication object", e);
+        }
+    }
+
+    private static SSHKeyAuthentication getSshKeyAuthentication(String gatewayId,
+                                                                String loginUserName,
+                                                                String credentialStoreToken)
+            throws ApplicationSettingsException, IllegalAccessException, InstantiationException,
+            CredentialStoreException, GFacException {
+
+        SSHKeyAuthentication sshKA;CredentialReader credentialReader = GFacUtils.getCredentialReader();
+        Credential credential = credentialReader.getCredential(gatewayId, credentialStoreToken);
+        if (credential instanceof SSHCredential) {
+            sshKA = new SSHKeyAuthentication();
             sshKA.setUserName(loginUserName);
+            SSHCredential sshCredential = (SSHCredential) credential;
+            sshKA.setPublicKey(sshCredential.getPublicKey());
+            sshKA.setPrivateKey(sshCredential.getPrivateKey());
+            sshKA.setPassphrase(sshCredential.getPassphrase());
+            sshKA.setStrictHostKeyChecking("no");
+/*            sshKA.setStrictHostKeyChecking(ServerSettings.getSetting("ssh.strict.hostKey.checking",
"no"));
+            sshKA.setKnownHostsFilePath(ServerSettings.getSetting("ssh.known.hosts.file",
null));
+            if (sshKA.getStrictHostKeyChecking().equals("yes") && sshKA.getKnownHostsFilePath()
== null) {
+                throw new ApplicationSettingsException("If ssh strict hostkey checking property
is set to yes, you must " +
+                        "provide known host file path");
+            }*/
+            return sshKA;
         } else {
-            sshKA.setUserName(ServerSettings.getSetting("ssh.username"));
+            String msg = "Provided credential store token is not valid. Please provide the
correct credential store token";
+            log.error(msg);
+            throw new GFacException("Invalid credential store token:" + credentialStoreToken);
         }
-		sshKA.setPassphrase(ServerSettings.getSetting("ssh.keypass"));
-		sshKA.setPrivateKeyFilePath(ServerSettings.getSetting("ssh.private.key"));
-		sshKA.setPublicKeyFilePath(ServerSettings.getSetting("ssh.public.key"));
-		sshKA.setStrictHostKeyChecking(ServerSettings.getSetting("ssh.strict.hostKey.checking",
"no"));
-		sshKA.setKnownHostsFilePath(ServerSettings.getSetting("ssh.known.hosts.file", null));
-		if (sshKA.getStrictHostKeyChecking().equals("yes") && sshKA.getKnownHostsFilePath()
== null) {
-			throw new ApplicationSettingsException("If ssh strict hostkey checking property is set
to yes, you must " +
-					"provide known host file path");
-		}
-		return sshKA;
-	}
+    }
+
 
 	public static JobSubmissionTask getJobSubmissionTask(JobSubmissionProtocol jobSubmissionProtocol)
{
 		return jobSubmissionTask.get(jobSubmissionProtocol);
@@ -353,7 +401,7 @@ public abstract class Factory {
 					throw new AiravataException("Support ssh key authentication only");
 				}
 				JSch jSch = new JSch();
-				jSch.addIdentity(authentication.getPrivateKeyFilePath(), authentication.getPublicKeyFilePath(),
+				jSch.addIdentity(UUID.randomUUID().toString(), authentication.getPrivateKey(), authentication.getPublicKey(),
 						authentication.getPassphrase().getBytes());
 				Session session = jSch.getSession(serverInfo.getUserName(), serverInfo.getHost(),
 						serverInfo.getPort());

http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/GFacEngineImpl.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/GFacEngineImpl.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/GFacEngineImpl.java
index e2f3ae8..87a0e54 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/GFacEngineImpl.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/GFacEngineImpl.java
@@ -41,7 +41,6 @@ import org.apache.airavata.model.appcatalog.appinterface.ApplicationInterfaceDes
 import org.apache.airavata.model.appcatalog.computeresource.*;
 import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
 import org.apache.airavata.model.appcatalog.gatewayprofile.StoragePreference;
-import org.apache.airavata.model.appcatalog.storageresource.StorageResourceDescription;
 import org.apache.airavata.model.application.io.DataType;
 import org.apache.airavata.model.application.io.InputDataObjectType;
 import org.apache.airavata.model.application.io.OutputDataObjectType;
@@ -140,6 +139,8 @@ public class GFacEngineImpl implements GFacEngine {
             }
             expCatalog.update(ExperimentCatalogModelType.PROCESS, processModel, processId);
             processModel.setProcessOutputs(applicationOutputs);
+
+            processContext.setSshKeyAuthentication(Factory.getComputerResourceSSHKeyAuthentication(processContext));
             processContext.setResourceJobManager(getResourceJobManager(processContext));
             processContext.setJobSubmissionRemoteCluster(Factory.getJobSubmissionRemoteCluster(processContext));
             processContext.setDataMovementRemoteCluster(Factory.getDataMovementRemoteCluster(processContext));

http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
index 3711f7c..8c4a4c0 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/HPCRemoteCluster.java
@@ -39,6 +39,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 
 /**
@@ -60,7 +61,7 @@ public class HPCRemoteCluster extends AbstractRemoteCluster{
 				throw new AiravataException("Support ssh key authentication only");
 			}
 			jSch = new JSch();
-			jSch.addIdentity(authentication.getPrivateKeyFilePath(), authentication.getPublicKeyFilePath(),
+			jSch.addIdentity(UUID.randomUUID().toString(), authentication.getPrivateKey(), authentication.getPublicKey(),
 					authentication.getPassphrase().getBytes());
 			session = getOpenSession();
 		} catch (JSchException e) {

http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/SCPDataStageTask.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/SCPDataStageTask.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/SCPDataStageTask.java
index c4ee228..5437717 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/SCPDataStageTask.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/SCPDataStageTask.java
@@ -73,10 +73,6 @@ import java.util.Map;
 public class SCPDataStageTask implements Task {
     private static final Logger log = LoggerFactory.getLogger(SCPDataStageTask.class);
     private static final int DEFAULT_SSH_PORT = 22;
-    private String password;
-    private String publicKeyPath;
-    private String passPhrase;
-    private String privateKeyPath;
     private String userName;
     private String hostName;
     private String inputPath;
@@ -154,34 +150,11 @@ public class SCPDataStageTask implements Task {
                 return status;
             }
 
-
-            String tokenId = taskContext.getParentProcessContext().getTokenId();
-            CredentialReader credentialReader = GFacUtils.getCredentialReader();
-            Credential credential = credentialReader.getCredential(taskContext.getParentProcessContext().getGatewayId(),
tokenId);
-            if (credential instanceof SSHCredential) {
-                SSHCredential sshCredential = (SSHCredential) credential;
-                byte[] publicKey = sshCredential.getPublicKey();
-                publicKeyPath = writeFileToDisk(publicKey);
-                byte[] privateKey = sshCredential.getPrivateKey();
-                privateKeyPath = writeFileToDisk(privateKey);
-                passPhrase = sshCredential.getPassphrase();
-//                userName = sshCredential.getPortalUserName(); // this might not same as
login user name
-                authenticationInfo = getSSHKeyAuthentication();
-            } else {
-                String msg = "Provided credential store token is not valid. Please provide
the correct credential store token";
-                log.error(msg);
-                status.setState(TaskState.FAILED);
-                status.setReason(msg);
-                ErrorModel errorModel = new ErrorModel();
-                errorModel.setActualErrorMessage(msg);
-                errorModel.setUserFriendlyMessage(msg);
-                taskContext.getTaskModel().setTaskError(errorModel);
-                return status;
-            }
+            authenticationInfo = Factory.getStorageSSHKeyAuthentication(taskContext.getParentProcessContext());
             status = new TaskStatus(TaskState.COMPLETED);
-
             StorageResourceDescription storageResource = taskContext.getParentProcessContext().getStorageResource();
             StoragePreference storagePreference = taskContext.getParentProcessContext().getStoragePreference();
+
             if (storageResource != null){
                 hostName = storageResource.getHostName();
             }
@@ -213,7 +186,7 @@ public class SCPDataStageTask implements Task {
             errorModel.setUserFriendlyMessage(msg);
             taskContext.getTaskModel().setTaskError(errorModel);
             return status;
-        } catch (ApplicationSettingsException | FileNotFoundException | CredentialStoreException
| IllegalAccessException | InstantiationException e) {
+        } catch (ApplicationSettingsException | FileNotFoundException e) {
             String msg = "Failed while reading credentials";
             log.error(msg, e);
             status.setState(TaskState.FAILED);
@@ -318,34 +291,6 @@ public class SCPDataStageTask implements Task {
         return TaskTypes.DATA_STAGING;
     }
 
-    private SSHPasswordAuthentication getSSHPasswordAuthentication() {
-        return new SSHPasswordAuthentication(userName, password);
-    }
-
-    private SSHKeyAuthentication getSSHKeyAuthentication() {
-        SSHKeyAuthentication sshKA = new SSHKeyAuthentication();
-        sshKA.setUserName(userName);
-        sshKA.setPassphrase(passPhrase);
-        sshKA.setPrivateKeyFilePath(privateKeyPath);
-        sshKA.setPublicKeyFilePath(publicKeyPath);
-        sshKA.setStrictHostKeyChecking("no");
-        return sshKA;
-    }
-
-    private String writeFileToDisk(byte[] data) {
-        File temp = null;
-        try {
-            temp = File.createTempFile("id_rsa", "");
-            //write it
-            FileOutputStream bw = new FileOutputStream(temp);
-            bw.write(data);
-            bw.close();
-        } catch (IOException e) {
-            log.error(e.getMessage(), e);
-        }
-        return temp.getAbsolutePath();
-    }
-
     public URI getDestinationURI(TaskContext taskContext, String fileName) throws URISyntaxException
{
         String filePath = (inputPath.endsWith(File.separator) ? inputPath : inputPath + File.separator)
+
                 taskContext.getParentProcessContext().getProcessId() + File.separator + fileName;

http://git-wip-us.apache.org/repos/asf/airavata/blob/f1c4c970/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/utils/StreamData.java
----------------------------------------------------------------------
diff --git a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/utils/StreamData.java
b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/utils/StreamData.java
index 1dbe9ba..d89c7d3 100644
--- a/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/utils/StreamData.java
+++ b/modules/gfac/gfac-impl/src/main/java/org/apache/airavata/gfac/impl/task/utils/StreamData.java
@@ -121,26 +121,7 @@ public class StreamData extends TimerTask  {
                     && sourceURI.getUserInfo().equalsIgnoreCase(destinationURI.getUserInfo()))
{
                 localDataCopy(taskContext, sourceURI, destinationURI);
             }
-
-            String tokenId = taskContext.getParentProcessContext().getTokenId();
-            CredentialReader credentialReader = GFacUtils.getCredentialReader();
-            Credential credential = credentialReader.getCredential(taskContext.getParentProcessContext().getGatewayId(),
tokenId);
-            if (credential instanceof SSHCredential) {
-                SSHCredential sshCredential = (SSHCredential) credential;
-                byte[] publicKey = sshCredential.getPublicKey();
-                publicKeyPath = writeFileToDisk(publicKey);
-                byte[] privateKey = sshCredential.getPrivateKey();
-                privateKeyPath = writeFileToDisk(privateKey);
-                passPhrase = sshCredential.getPassphrase();
-                authenticationInfo = getSSHKeyAuthentication();
-            } else {
-                String msg = "Provided credential store token is not valid. Please provide
the correct credential store token";
-                log.error(msg);
-                ErrorModel errorModel = new ErrorModel();
-                errorModel.setActualErrorMessage(msg);
-                errorModel.setUserFriendlyMessage(msg);
-                taskContext.getTaskModel().setTaskError(errorModel);
-            }
+            authenticationInfo = Factory.getStorageSSHKeyAuthentication(taskContext.getParentProcessContext());
 
             ServerInfo serverInfo = new ServerInfo(userName, hostName, DEFAULT_SSH_PORT);
             Session sshSession = Factory.getSSHSession(authenticationInfo, serverInfo);
@@ -184,27 +165,4 @@ public class StreamData extends TimerTask  {
 
     }
 
-    private String writeFileToDisk(byte[] data) {
-        File temp = null;
-        try {
-            temp = File.createTempFile("id_rsa", "");
-            //write it
-            FileOutputStream bw = new FileOutputStream(temp);
-            bw.write(data);
-            bw.close();
-        } catch (IOException e) {
-            log.error(e.getMessage(), e);
-        }
-        return temp.getAbsolutePath();
-    }
-
-    private SSHKeyAuthentication getSSHKeyAuthentication() {
-        SSHKeyAuthentication sshKA = new SSHKeyAuthentication();
-        sshKA.setUserName(userName);
-        sshKA.setPassphrase(passPhrase);
-        sshKA.setPrivateKeyFilePath(privateKeyPath);
-        sshKA.setPublicKeyFilePath(publicKeyPath);
-        sshKA.setStrictHostKeyChecking("no");
-        return sshKA;
-    }
 }


Mime
View raw message