http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gfac/gsi/ssh/util/SSHUtils.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gfac/gsi/ssh/util/SSHUtils.java b/tools/gsissh/src/main/java/org/apache/airavata/gfac/gsi/ssh/util/SSHUtils.java new file mode 100644 index 0000000..35f6a41 --- /dev/null +++ b/tools/gsissh/src/main/java/org/apache/airavata/gfac/gsi/ssh/util/SSHUtils.java @@ -0,0 +1,757 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ +package org.apache.airavata.gfac.ssh.util; + +import com.jcraft.jsch.*; + +import org.apache.airavata.gfac.ssh.api.authentication.GSIAuthenticationInfo; +import org.apache.airavata.gfac.ssh.api.SSHApiException; +import org.apache.airavata.gfac.ssh.api.ServerInfo; +import org.apache.airavata.gfac.ssh.config.ConfigReader; +import org.apache.airavata.gfac.ssh.impl.StandardOutReader; +import org.slf4j.*; + +import java.io.*; +import java.util.Arrays; +import java.util.List; + +/** + * This class is going to be useful to SCP a file to a remote grid machine using my proxy credentials + */ +public class SSHUtils { + private static final org.slf4j.Logger log = LoggerFactory.getLogger(SSHUtils.class); + + static { + JSch.setConfig("gssapi-with-mic.x509", "org.apache.airavata.gfac.ssh.GSSContextX509"); + JSch.setConfig("userauth.gssapi-with-mic", "com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials"); + + } + + private ServerInfo serverInfo; + + private GSIAuthenticationInfo authenticationInfo; + + private ConfigReader configReader; + + /** + * We need to pass certificateLocation when we use SCPTo method standalone + * + * @param serverInfo + * @param authenticationInfo + * @param certificateLocation + * @param configReader + */ + public SSHUtils(ServerInfo serverInfo, GSIAuthenticationInfo authenticationInfo, String certificateLocation, ConfigReader configReader) { + System.setProperty("X509_CERT_DIR", certificateLocation); + this.serverInfo = serverInfo; + this.authenticationInfo = authenticationInfo; + this.configReader = configReader; + } + + /** + * This can be used when use SCPTo method within SSHAPi because SSHApiFactory already set the system property certificateLocation + * + * @param serverInfo + * @param authenticationInfo + * @param configReader + */ + public SSHUtils(ServerInfo serverInfo, GSIAuthenticationInfo authenticationInfo + , ConfigReader configReader) { + this.serverInfo = serverInfo; + this.authenticationInfo = authenticationInfo; + this.configReader = configReader; + } + + /** + * This method will scp the lFile to the rFile location + * + * @param rFile remote file Path to use in scp + * @param lFile local file path to use in scp + * @throws IOException + * @throws JSchException + * @throws org.apache.airavata.gfac.ssh.api.SSHApiException + * + */ + public void scpTo(String rFile, String lFile) throws IOException, JSchException, SSHApiException { + FileInputStream fis = null; + String prefix = null; + if (new File(lFile).isDirectory()) { + prefix = lFile + File.separator; + } + JSch jsch = new JSch(); + + log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " + + serverInfo.getUserName()); + + Session session = null; + + try { + session = jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while creating SSH session." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + java.util.Properties config = this.configReader.getProperties(); + session.setConfig(config); + + // Not a good way, but we dont have any choice + if (session instanceof ExtendedSession) { + ((ExtendedSession) session).setAuthenticationInfo(authenticationInfo); + } + + try { + session.connect(); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while connecting to server." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + boolean ptimestamp = true; + + // exec 'scp -t rfile' remotely + String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + rFile; + Channel channel = session.openChannel("exec"); + + StandardOutReader stdOutReader = new StandardOutReader(); + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + ((ChannelExec) channel).setCommand(command); + + // get I/O streams for remote scp + OutputStream out = channel.getOutputStream(); + InputStream in = channel.getInputStream(); + + channel.connect(); + + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + + File _lfile = new File(lFile); + + if (ptimestamp) { + command = "T" + (_lfile.lastModified() / 1000) + " 0"; + // The access time should be sent here, + // but it is not accessible with JavaAPI ;-< + command += (" " + (_lfile.lastModified() / 1000) + " 0\n"); + out.write(command.getBytes()); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + } + + // send "C0644 filesize filename", where filename should not include '/' + long filesize = _lfile.length(); + command = "C0644 " + filesize + " "; + if (lFile.lastIndexOf('/') > 0) { + command += lFile.substring(lFile.lastIndexOf('/') + 1); + } else { + command += lFile; + } + command += "\n"; + out.write(command.getBytes()); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + + // send a content of lFile + fis = new FileInputStream(lFile); + byte[] buf = new byte[1024]; + while (true) { + int len = fis.read(buf, 0, buf.length); + if (len <= 0) break; + out.write(buf, 0, len); //out.flush(); + } + fis.close(); + fis = null; + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + out.close(); + + stdOutReader.onOutput(channel); + + + if (stdOutReader.getStdErrorString().contains("scp:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + channel.disconnect(); + } + + /** + * This will copy a local file to a remote location + * + * @param remoteFile remote location you want to transfer the file, this cannot be a directory, if user pass + * a dirctory we do copy it to that directory but we simply return the directory name + * todo handle the directory name as input and return the proper final output file name + * @param localFile Local file to transfer, this can be a directory + * @param session + * @return returns the final remote file path, so that users can use the new file location + * @throws IOException + * @throws JSchException + * @throws SSHApiException + */ + public static String scpTo(String remoteFile, String localFile, Session session) throws IOException, JSchException, SSHApiException { + FileInputStream fis = null; + String prefix = null; + if (new File(localFile).isDirectory()) { + prefix = localFile + File.separator; + } + boolean ptimestamp = true; + + // exec 'scp -t rfile' remotely + String command = "scp " + (ptimestamp ? "-p" : "") + " -t " + remoteFile; + Channel channel = session.openChannel("exec"); + + StandardOutReader stdOutReader = new StandardOutReader(); + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + ((ChannelExec) channel).setCommand(command); + + // get I/O streams for remote scp + OutputStream out = channel.getOutputStream(); + InputStream in = channel.getInputStream(); + + channel.connect(); + + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + + File _lfile = new File(localFile); + + if (ptimestamp) { + command = "T" + (_lfile.lastModified() / 1000) + " 0"; + // The access time should be sent here, + // but it is not accessible with JavaAPI ;-< + command += (" " + (_lfile.lastModified() / 1000) + " 0\n"); + out.write(command.getBytes()); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + } + + // send "C0644 filesize filename", where filename should not include '/' + long filesize = _lfile.length(); + command = "C0644 " + filesize + " "; + if (localFile.lastIndexOf('/') > 0) { + command += localFile.substring(localFile.lastIndexOf('/') + 1); + } else { + command += localFile; + } + command += "\n"; + out.write(command.getBytes()); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + + // send a content of lFile + fis = new FileInputStream(localFile); + byte[] buf = new byte[1024]; + while (true) { + int len = fis.read(buf, 0, buf.length); + if (len <= 0) break; + out.write(buf, 0, len); //out.flush(); + } + fis.close(); + fis = null; + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error Reading input Stream"; + log.error(error); + throw new SSHApiException(error); + } + out.close(); + stdOutReader.onOutput(channel); + + + channel.disconnect(); + if (stdOutReader.getStdErrorString().contains("scp:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + //since remote file is always a file we just return the file + return remoteFile; + } + + /** + * This method will copy a remote file to a local directory + * + * @param remoteFile remote file path, this has to be a full qualified path + * @param localFile This is the local file to copy, this can be a directory too + * @param session + * @return returns the final local file path of the new file came from the remote resource + */ + public static void scpFrom(String remoteFile, String localFile, Session session) throws IOException, JSchException, SSHApiException { + FileOutputStream fos = null; + try { + String prefix = null; + if (new File(localFile).isDirectory()) { + prefix = localFile + File.separator; + } + + // exec 'scp -f remotefile' remotely + String command = "scp -f " + remoteFile; + Channel channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command); + + StandardOutReader stdOutReader = new StandardOutReader(); + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + // get I/O streams for remote scp + OutputStream out = channel.getOutputStream(); + InputStream in = channel.getInputStream(); + + channel.connect(); + + byte[] buf = new byte[1024]; + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + + while (true) { + int c = checkAck(in); + if (c != 'C') { + break; + } + + // read '0644 ' + in.read(buf, 0, 5); + + long filesize = 0L; + while (true) { + if (in.read(buf, 0, 1) < 0) { + // error + break; + } + if (buf[0] == ' ') break; + filesize = filesize * 10L + (long) (buf[0] - '0'); + } + + String file = null; + for (int i = 0; ; i++) { + in.read(buf, i, 1); + if (buf[i] == (byte) 0x0a) { + file = new String(buf, 0, i); + break; + } + } + + //System.out.println("filesize="+filesize+", file="+file); + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + + // read a content of lfile + fos = new FileOutputStream(prefix == null ? localFile : prefix + file); + int foo; + while (true) { + if (buf.length < filesize) foo = buf.length; + else foo = (int) filesize; + foo = in.read(buf, 0, foo); + if (foo < 0) { + // error + break; + } + fos.write(buf, 0, foo); + filesize -= foo; + if (filesize == 0L) break; + } + fos.close(); + fos = null; + + if (checkAck(in) != 0) { + String error = "Error transfering the file content"; + log.error(error); + throw new SSHApiException(error); + } + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + } + stdOutReader.onOutput(channel); + if (stdOutReader.getStdErrorString().contains("scp:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if (fos != null) fos.close(); + } catch (Exception ee) { + } + } + } + + /** + * This method will copy a remote file to a local directory + * + * @param remoteFile remote file path, this has to be a full qualified path + * @param localFile This is the local file to copy, this can be a directory too + */ + public void scpFrom(String remoteFile, String localFile) throws SSHApiException { + JSch jsch = new JSch(); + + log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " + + serverInfo.getUserName()); + + Session session = null; + + try { + session = jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while creating SSH session." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + java.util.Properties config = this.configReader.getProperties(); + session.setConfig(config); + + // Not a good way, but we dont have any choice + if (session instanceof ExtendedSession) { + ((ExtendedSession) session).setAuthenticationInfo(authenticationInfo); + } + + try { + session.connect(); + } catch (JSchException e) { + throw new SSHApiException("An exception occurred while connecting to server." + + "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + + " connecting user name - " + + serverInfo.getUserName(), e); + } + + FileOutputStream fos = null; + try { + String prefix = null; + if (new File(localFile).isDirectory()) { + prefix = localFile + File.separator; + } + + // exec 'scp -f remotefile' remotely + StandardOutReader stdOutReader = new StandardOutReader(); + String command = "scp -f " + remoteFile; + Channel channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command); + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + // get I/O streams for remote scp + OutputStream out = channel.getOutputStream(); + InputStream in = channel.getInputStream(); + + channel.connect(); + + byte[] buf = new byte[1024]; + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + + while (true) { + int c = checkAck(in); + if (c != 'C') { + break; + } + + // read '0644 ' + in.read(buf, 0, 5); + + long filesize = 0L; + while (true) { + if (in.read(buf, 0, 1) < 0) { + // error + break; + } + if (buf[0] == ' ') break; + filesize = filesize * 10L + (long) (buf[0] - '0'); + } + + String file = null; + for (int i = 0; ; i++) { + in.read(buf, i, 1); + if (buf[i] == (byte) 0x0a) { + file = new String(buf, 0, i); + break; + } + } + + //System.out.println("filesize="+filesize+", file="+file); + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + + // read a content of lfile + fos = new FileOutputStream(prefix == null ? localFile : prefix + file); + int foo; + while (true) { + if (buf.length < filesize) foo = buf.length; + else foo = (int) filesize; + foo = in.read(buf, 0, foo); + if (foo < 0) { + // error + break; + } + fos.write(buf, 0, foo); + filesize -= foo; + if (filesize == 0L) break; + } + fos.close(); + fos = null; + + if (checkAck(in) != 0) { + String error = "Error transfering the file content"; + log.error(error); + throw new SSHApiException(error); + } + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + } + +// session.disconnect(); + + stdOutReader.onOutput(channel); + if (stdOutReader.getStdErrorString().contains("scp:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if (fos != null) fos.close(); + } catch (Exception ee) { + } + } + } + + /** + * This method will copy a remote file to a local directory + * + * @param remoteFile remote file path, this has to be a full qualified path + * @param localFile This is the local file to copy, this can be a directory too + * @param session + * @return returns the final local file path of the new file came from the remote resource + */ + public static void scpThirdParty(String remoteFileSource, String remoteFileTarget, Session session) throws IOException, JSchException, SSHApiException { + FileOutputStream fos = null; + try { + String prefix = null; + + // exec 'scp -f remotefile' remotely + String command = "scp -3 " + remoteFileSource + " " + remoteFileTarget; + Channel channel = session.openChannel("exec"); + ((ChannelExec) channel).setCommand(command); + + StandardOutReader stdOutReader = new StandardOutReader(); + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + // get I/O streams for remote scp + OutputStream out = channel.getOutputStream(); + InputStream in = channel.getInputStream(); + + channel.connect(); + + byte[] buf = new byte[1024]; + + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + + while (true) { + int c = checkAck(in); + if (c != 'C') { + break; + } + + // read '0644 ' + in.read(buf, 0, 5); + + long filesize = 0L; + while (true) { + if (in.read(buf, 0, 1) < 0) { + // error + break; + } + if (buf[0] == ' ') break; + filesize = filesize * 10L + (long) (buf[0] - '0'); + } + int foo; + while (true) { + if (buf.length < filesize) foo = buf.length; + else foo = (int) filesize; + + int len = in.read(buf, 0, foo); + if (len <= 0) break; + out.write(buf, 0, len); + } + // send '\0' + buf[0] = 0; + out.write(buf, 0, 1); + out.flush(); + if (checkAck(in) != 0) { + String error = "Error transfering the file content"; + log.error(error); + throw new SSHApiException(error); + } + + } + out.close(); + + stdOutReader.onOutput(channel); + if (stdOutReader.getStdErrorString().contains("scp:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + try { + if (fos != null) fos.close(); + } catch (Exception ee) { + } + } + } + + public static void makeDirectory(String path, Session session) throws IOException, JSchException, SSHApiException { + + // exec 'scp -t rfile' remotely + String command = "mkdir -p " + path; + Channel channel = session.openChannel("exec"); + StandardOutReader stdOutReader = new StandardOutReader(); + + ((ChannelExec) channel).setCommand(command); + + + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + try { + channel.connect(); + } catch (JSchException e) { + + channel.disconnect(); +// session.disconnect(); + + throw new SSHApiException("Unable to retrieve command output. Command - " + command + + " on server - " + session.getHost() + ":" + session.getPort() + + " connecting user name - " + + session.getUserName(), e); + } + stdOutReader.onOutput(channel); + if (stdOutReader.getStdErrorString().contains("mkdir:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + + channel.disconnect(); + } + + public static List<String> listDirectory(String path, Session session) throws IOException, JSchException, SSHApiException { + + // exec 'scp -t rfile' remotely + String command = "ls " + path; + Channel channel = session.openChannel("exec"); + StandardOutReader stdOutReader = new StandardOutReader(); + + ((ChannelExec) channel).setCommand(command); + + + ((ChannelExec) channel).setErrStream(stdOutReader.getStandardError()); + try { + channel.connect(); + } catch (JSchException e) { + + channel.disconnect(); +// session.disconnect(); + + throw new SSHApiException("Unable to retrieve command output. Command - " + command + + " on server - " + session.getHost() + ":" + session.getPort() + + " connecting user name - " + + session.getUserName(), e); + } + stdOutReader.onOutput(channel); + stdOutReader.getStdOutputString(); + if (stdOutReader.getStdErrorString().contains("ls:")) { + throw new SSHApiException(stdOutReader.getStdErrorString()); + } + channel.disconnect(); + return Arrays.asList(stdOutReader.getStdOutputString().split("\n")); + } + + static int checkAck(InputStream in) throws IOException { + int b = in.read(); + if (b == 0) return b; + if (b == -1) return b; + + if (b == 1 || b == 2) { + StringBuffer sb = new StringBuffer(); + int c; + do { + c = in.read(); + sb.append((char) c); + } + while (c != '\n'); + if (b == 1) { // error + System.out.print(sb.toString()); + } + if (b == 2) { // fatal error + System.out.print(sb.toString()); + } + } + return b; + } +}
http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java deleted file mode 100644 index 351e1af..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/GSSContextX509.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.airavata.gsi.ssh; - - -import java.io.File; -import java.io.FileInputStream; -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.globus.common.CoGProperties; -import org.globus.gsi.GSIConstants; -import org.globus.gsi.gssapi.GSSConstants; -import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; -import org.globus.gsi.gssapi.auth.HostAuthorization; -import org.gridforum.jgss.ExtendedGSSContext; -import org.gridforum.jgss.ExtendedGSSCredential; -import org.gridforum.jgss.ExtendedGSSManager; -import org.ietf.jgss.GSSContext; -import org.ietf.jgss.GSSCredential; -import org.ietf.jgss.GSSException; -import org.ietf.jgss.GSSName; -import org.ietf.jgss.MessageProp; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.jcraft.jsch.JSchException; - -/** - * This class is based on GSSContextKrb5; it substitutes the globus - * ExtendedGSSManager and uses the SecurityUtils method to get the credential if - * one is not passed in from memory. - * - */ -public class GSSContextX509 implements com.jcraft.jsch.GSSContext { - - private GSSContext context = null; - private GSSCredential credential; - private static final Logger logger = LoggerFactory.getLogger(GSSContextX509.class); - - public void create(String user, String host) throws JSchException { - try { -// ExtendedGSSManager manager = (ExtendedGSSManager) ExtendedGSSManager.getInstance(); - - if (credential == null) { - try { - credential = getCredential(); - } catch (SecurityException t) { - System.out.printf("Could not get proxy: %s: %s\n", t.getClass().getSimpleName(), t.getMessage()); - throw new JSchException(t.toString()); - } - } - - String cname = host; - - try { - cname = InetAddress.getByName(cname).getCanonicalHostName(); - } catch (UnknownHostException e) { - } - - GSSName name = HostAuthorization.getInstance().getExpectedName(credential, cname); - -// context = manager.createContext(name, null, credential, GSSContext.DEFAULT_LIFETIME); -// -// // RFC4462 3.4. GSS-API Session -// // -// // When calling GSS_Init_sec_context(), the client MUST set -// // integ_req_flag to "true" to request that per-message integrity -// // protection be supported for this context. In addition, -// // deleg_req_flag MAY be set to "true" to request access delegation, -// // if -// // requested by the user. -// // -// // Since the user authentication process by its nature authenticates -// // only the client, the setting of mutual_req_flag is not needed for -// // this process. This flag SHOULD be set to "false". -// -// // TODO: OpenSSH's sshd does accept 'false' for mutual_req_flag -// // context.requestMutualAuth(false); -// context.requestMutualAuth(true); -// context.requestConf(true); -// context.requestInteg(true); // for MIC -// context.requestCredDeleg(true); -// context.requestAnonymity(false); - -// context = new BCGSSContextImpl(name, (GlobusGSSCredentialImpl) credential); -// context.requestLifetime(GSSCredential.DEFAULT_LIFETIME); -// context.requestCredDeleg(true); -// context.requestMutualAuth(true); -// context.requestReplayDet(true); -// context.requestSequenceDet(true); -// context.requestConf(false); -// context.requestInteg(true); -// ((ExtendedGSSContext)context).setOption(GSSConstants.DELEGATION_TYPE, GSIConstants.DELEGATION_TYPE_FULL); - - return; - } catch (GSSException ex) { - throw new JSchException(ex.toString()); - } - } - - private static GSSCredential getProxy() { - return getProxy(null, GSSCredential.DEFAULT_LIFETIME); - } - - /** - * @param x509_USER_PROXY - * path to the proxy. - * @param credentialLifetime - * in seconds. - * @return valid credential. - * if proxy task throws exception (or if proxy cannot be found). - */ - private static GSSCredential getProxy(String x509_USER_PROXY, int credentialLifetime) throws SecurityException { - if (x509_USER_PROXY == null) - x509_USER_PROXY = System.getProperty("x509.user.proxy"); - -// if (x509_USER_PROXY == null) { -// SystemUtils.envToProperties(); -// x509_USER_PROXY = System.getProperty("x509.user.proxy"); -// } - - if (x509_USER_PROXY == null || "".equals(x509_USER_PROXY)) - x509_USER_PROXY = CoGProperties.getDefault().getProxyFile(); - - if (x509_USER_PROXY == null) - throw new SecurityException("could not get credential; no location defined"); - - ExtendedGSSManager manager = (ExtendedGSSManager) ExtendedGSSManager.getInstance(); - - // file...load file into a buffer - try { - File f = new File(x509_USER_PROXY); - byte[] data = new byte[(int) f.length()]; - FileInputStream in = new FileInputStream(f); - // read in the credential data - in.read(data); - in.close(); - return manager.createCredential(data, ExtendedGSSCredential.IMPEXP_OPAQUE, credentialLifetime, null, // use - // default - // mechanism - // - - // GSI - GSSCredential.INITIATE_AND_ACCEPT); - } catch (Throwable t) { - throw new SecurityException("could not get credential from " + x509_USER_PROXY, t); - } - } - - public boolean isEstablished() { - // this must check to see if the call returned GSS_S_COMPLETE - if (context != null){ - return context.isEstablished(); - } - return false; - } - - public byte[] init(byte[] token, int s, int l) throws JSchException { - try { - if (context != null){ - return context.initSecContext(token, s, l); - }else { - throw new JSchException("Context is null.."); - } - } catch (GSSException ex) { - throw new JSchException(ex.toString()); - } - } - - public byte[] getMIC(byte[] message, int s, int l) { - try { - MessageProp prop = new MessageProp(0, false); - return context.getMIC(message, s, l, prop); - } catch (GSSException ex) { - logger.error(ex.getMessage(), ex); - return null; - } - } - - public void dispose() { - try { - context.dispose(); - } catch (GSSException ex) { - } - } - - public void setCredential(GSSCredential credential) { - this.credential = credential; - } - - public GSSCredential getCredential() { - return credential; - } -} - http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java deleted file mode 100644 index 34e3b94..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Cluster.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ -package org.apache.airavata.gsi.ssh.api; - -import java.util.List; -import java.util.Map; - -import org.apache.airavata.gsi.ssh.api.job.JobDescriptor; -import org.apache.airavata.gsi.ssh.impl.JobStatus; - -import com.jcraft.jsch.Session; - -/** - * This interface represents a Cluster machine - * End users of the API can implement this and come up with their own - * implementations, but mostly this interface is for internal usage. - */ -public interface Cluster { - - /** - * This will submit a job to the cluster with a given pbs file and some parameters - * - * @param pbsFilePath path of the pbs file - * @param workingDirectory working directory where pbs should has to copy - * @return jobId after successful job submission - * @throws SSHApiException throws exception during error - */ - public String submitBatchJobWithScript(String pbsFilePath, String workingDirectory) throws SSHApiException; - - /** - * This will submit the given job and not performing any monitoring - * - * @param jobDescriptor job descriptor to submit to cluster, this contains all the parameter - * @return jobID after successful job submission. - * @throws SSHApiException throws exception during error - */ - public String submitBatchJob(JobDescriptor jobDescriptor) throws SSHApiException; - - /** - * This will copy the localFile to remoteFile location in configured cluster - * - * @param remoteFile remote file location, this can be a directory too - * @param localFile local file path of the file which needs to copy to remote location - * @throws SSHApiException throws exception during error - */ - public void scpTo(String remoteFile, String localFile) throws SSHApiException; - - /** - * This will copy a remote file in path rFile to local file lFile - * @param remoteFile remote file path, this has to be a full qualified path - * @param localFile This is the local file to copy, this can be a directory too - * @throws SSHApiException - */ - public void scpFrom(String remoteFile, String localFile) throws SSHApiException; - - /** - * This will copy a remote file in path rFile to local file lFile - * @param remoteFile remote file path, this has to be a full qualified path - * @param localFile This is the local file to copy, this can be a directory too - * @throws SSHApiException - */ - public void scpThirdParty(String remoteFileSorce, String remoteFileTarget) throws SSHApiException; - - /** - * This will create directories in computing resources - * @param directoryPath the full qualified path for the directory user wants to create - * @throws SSHApiException throws during error - */ - public void makeDirectory(String directoryPath) throws SSHApiException; - - - /** - * This will get the job description of a job which is there in the cluster - * if jbo is not available with the given ID it returns - * @param jobID jobId has to pass - * @return Returns full job description of the job which submitted successfully - * @throws SSHApiException throws exception during error - */ - public JobDescriptor getJobDescriptorById(String jobID) throws SSHApiException; - - /** - * This will delete the given job from the queue - * - * @param jobID jobId of the job which user wants to delete - * @return return the description of the deleted job - * @throws SSHApiException throws exception during error - */ - public JobDescriptor cancelJob(String jobID) throws SSHApiException; - - /** - * This will get the job status of the the job associated with this jobId - * - * @param jobID jobId of the job user want to get the status - * @return job status of the given jobID - * @throws SSHApiException throws exception during error - */ - public JobStatus getJobStatus(String jobID) throws SSHApiException; - /** - * This will get the job status of the the job associated with this jobId - * - * @param jobName jobName of the job user want to get the status - * @return jobId of the given jobName - * @throws SSHApiException throws exception during error - */ - public String getJobIdByJobName(String jobName, String userName) throws SSHApiException; - - /** - * This method can be used to poll the jobstatuses based on the given - * user but we should pass the jobID list otherwise we will get unwanted - * job statuses which submitted by different middleware outside apache - * airavata with the same uername which we are not considering - * @param userName userName of the jobs which required to get the status - * @param jobIDs precises set of jobIDs - * @return - */ - public void getJobStatuses(String userName,Map<String,JobStatus> jobIDs)throws SSHApiException; - /** - * This will list directories in computing resources - * @param directoryPath the full qualified path for the directory user wants to create - * @throws SSHApiException throws during error - */ - public List<String> listDirectory(String directoryPath) throws SSHApiException; - - /** - * This method can be used to get created ssh session - * to reuse the created session. - * @throws SSHApiException - */ - public Session getSession() throws SSHApiException; - - /** - * This method can be used to close the connections initialized - * to handle graceful shutdown of the system - * @throws SSHApiException - */ - public void disconnect() throws SSHApiException; - - /** - * This gives the server Info - * @return - */ - public ServerInfo getServerInfo(); - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java deleted file mode 100644 index e8f92b0..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandExecutor.java +++ /dev/null @@ -1,278 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ -package org.apache.airavata.gsi.ssh.api; - -import com.jcraft.jsch.*; -import org.apache.airavata.gsi.ssh.api.authentication.*; -import org.apache.airavata.gsi.ssh.config.ConfigReader; -import org.apache.airavata.gsi.ssh.jsch.ExtendedJSch; -import org.apache.airavata.gsi.ssh.util.SSHAPIUIKeyboardInteractive; -import org.apache.airavata.gsi.ssh.util.SSHKeyPasswordHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This is a generic class which take care of command execution - * in a shell, this is used through out the other places of the API. - */ -public class CommandExecutor { - static { - JSch.setConfig("gssapi-with-mic.x509", "org.apache.airavata.gsi.ssh.GSSContextX509"); - JSch.setConfig("userauth.gssapi-with-mic", "com.jcraft.jsch.UserAuthGSSAPIWithMICGSSCredentials"); - JSch jSch = new JSch(); - } - - private static final Logger log = LoggerFactory.getLogger(CommandExecutor.class); - public static final String X509_CERT_DIR = "X509_CERT_DIR"; - - /** - * This will execute the given command with given session and session is not closed at the end. - * - * @param commandInfo - * @param session - * @param commandOutput - * @throws SSHApiException - */ - public static Session executeCommand(CommandInfo commandInfo, Session session, - CommandOutput commandOutput) throws SSHApiException { - - String command = commandInfo.getCommand(); - - Channel channel = null; - try { - if (!session.isConnected()) { - session.connect(); - } - channel = session.openChannel("exec"); - ((ChannelExec) channel).setCommand(command); - } catch (JSchException e) { -// session.disconnect(); - - throw new SSHApiException("Unable to execute command - ", e); - } - - channel.setInputStream(null); - ((ChannelExec) channel).setErrStream(commandOutput.getStandardError()); - try { - channel.connect(); - } catch (JSchException e) { - - channel.disconnect(); -// session.disconnect(); - throw new SSHApiException("Unable to retrieve command output. Command - " + command, e); - } - - - commandOutput.onOutput(channel); - //Only disconnecting the channel, session can be reused - channel.disconnect(); - return session; - } - - /** - * This will not reuse any session, it will create the session and close it at the end - * - * @param commandInfo Encapsulated information about command. E.g :- executable name - * parameters etc ... - * @param serverInfo The SSHing server information. - * @param authenticationInfo Security data needs to be communicated with remote server. - * @param commandOutput The output of the command. - * @param configReader configuration required for ssh/gshissh connection - * @throws SSHApiException throw exception when error occurs - */ - public static void executeCommand(CommandInfo commandInfo, ServerInfo serverInfo, - AuthenticationInfo authenticationInfo, - CommandOutput commandOutput, ConfigReader configReader) throws SSHApiException { - - if (authenticationInfo instanceof GSIAuthenticationInfo) { - System.setProperty(X509_CERT_DIR, (String) ((GSIAuthenticationInfo)authenticationInfo).getProperties(). - get("X509_CERT_DIR")); - } - - - JSch jsch = new ExtendedJSch(); - - log.debug("Connecting to server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + " with user name - " - + serverInfo.getUserName()); - - Session session; - - try { - session = jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort()); - } catch (JSchException e) { - throw new SSHApiException("An exception occurred while creating SSH session." + - "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + - " connecting user name - " - + serverInfo.getUserName(), e); - } - - java.util.Properties config = configReader.getProperties(); - session.setConfig(config); - - //============================================================= - // Handling vanilla SSH pieces - //============================================================= - if (authenticationInfo instanceof SSHPasswordAuthentication) { - String password = ((SSHPasswordAuthentication) authenticationInfo). - getPassword(serverInfo.getUserName(), serverInfo.getHost()); - - session.setUserInfo(new SSHAPIUIKeyboardInteractive(password)); - - // TODO figure out why we need to set password to session - session.setPassword(password); - - } else if (authenticationInfo instanceof SSHPublicKeyFileAuthentication) { - SSHPublicKeyFileAuthentication sshPublicKeyFileAuthentication - = (SSHPublicKeyFileAuthentication)authenticationInfo; - - String privateKeyFile = sshPublicKeyFileAuthentication. - getPrivateKeyFile(serverInfo.getUserName(), serverInfo.getHost()); - - logDebug("The private key file for vanilla SSH " + privateKeyFile); - - String publicKeyFile = sshPublicKeyFileAuthentication. - getPrivateKeyFile(serverInfo.getUserName(), serverInfo.getHost()); - - logDebug("The public key file for vanilla SSH " + publicKeyFile); - - Identity identityFile; - - try { - identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, jsch); - } catch (JSchException e) { - throw new SSHApiException("An exception occurred while initializing keys using files. " + - "(private key and public key)." + - "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + - " connecting user name - " - + serverInfo.getUserName() + " private key file - " + privateKeyFile + ", public key file - " + - publicKeyFile, e); - } - - // Add identity to identity repository - GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch); - identityRepository.add(identityFile); - - // Set repository to session - session.setIdentityRepository(identityRepository); - - // Set the user info - SSHKeyPasswordHandler sshKeyPasswordHandler - = new SSHKeyPasswordHandler((SSHKeyAuthentication)authenticationInfo); - - session.setUserInfo(sshKeyPasswordHandler); - - } else if (authenticationInfo instanceof SSHPublicKeyAuthentication) { - - SSHPublicKeyAuthentication sshPublicKeyAuthentication - = (SSHPublicKeyAuthentication)authenticationInfo; - - Identity identityFile; - - try { - String name = serverInfo.getUserName() + "_" + serverInfo.getHost(); - identityFile = GSISSHIdentityFile.newInstance(name, - sshPublicKeyAuthentication.getPrivateKey(serverInfo.getUserName(), serverInfo.getHost()), - sshPublicKeyAuthentication.getPublicKey(serverInfo.getUserName(), serverInfo.getHost()), jsch); - } catch (JSchException e) { - throw new SSHApiException("An exception occurred while initializing keys using byte arrays. " + - "(private key and public key)." + - "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + - " connecting user name - " - + serverInfo.getUserName(), e); - } - - // Add identity to identity repository - GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch); - identityRepository.add(identityFile); - - // Set repository to session - session.setIdentityRepository(identityRepository); - - // Set the user info - SSHKeyPasswordHandler sshKeyPasswordHandler - = new SSHKeyPasswordHandler((SSHKeyAuthentication)authenticationInfo); - - session.setUserInfo(sshKeyPasswordHandler); - - } - - // Not a good way, but we dont have any choice - if (session instanceof ExtendedSession) { - if (authenticationInfo instanceof GSIAuthenticationInfo) { - ((ExtendedSession) session).setAuthenticationInfo((GSIAuthenticationInfo)authenticationInfo); - } - } - - try { - session.connect(); - } catch (JSchException e) { - throw new SSHApiException("An exception occurred while connecting to server." + - "Connecting server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + - " connecting user name - " - + serverInfo.getUserName(), e); - } - - String command = commandInfo.getCommand(); - - Channel channel; - try { - channel = session.openChannel("exec"); - ((ChannelExec) channel).setCommand(command); - } catch (JSchException e) { -// session.disconnect(); - - throw new SSHApiException("Unable to execute command - " + command + - " on server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + - " connecting user name - " - + serverInfo.getUserName(), e); - } - - - channel.setInputStream(null); - ((ChannelExec) channel).setErrStream(commandOutput.getStandardError()); - - try { - channel.connect(); - } catch (JSchException e) { - - channel.disconnect(); -// session.disconnect(); - - throw new SSHApiException("Unable to retrieve command output. Command - " + command + - " on server - " + serverInfo.getHost() + ":" + serverInfo.getPort() + - " connecting user name - " - + serverInfo.getUserName(), e); - } - - commandOutput.onOutput(channel); - - channel.disconnect(); -// session.disconnect(); - } - - private static void logDebug(String message) { - if (log.isDebugEnabled()) { - log.debug(message); - } - } - - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandInfo.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandInfo.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandInfo.java deleted file mode 100644 index 988bc31..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandInfo.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apache.airavata.gsi.ssh.api;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/** - * Encapsulates information about - */ -public interface CommandInfo { - - /** - * Gets the executable command as a string. - * @return String encoded command. Should be able to execute - * directly on remote shell. Should includes appropriate parameters. - */ - String getCommand(); - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandOutput.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandOutput.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandOutput.java deleted file mode 100644 index a7866ee..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/CommandOutput.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apache.airavata.gsi.ssh.api;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -import com.jcraft.jsch.Channel; - -import java.io.OutputStream; - -/** - * Output of a certain command. TODO rethink - */ -public interface CommandOutput { - - /** - * Gets the output of the command as a stream. - * @param channel Command output as a stream. - */ - void onOutput(Channel channel); - - /** - * Gets standard error as a output stream. - * @return Command error as a stream. - */ - OutputStream getStandardError(); - - /** - * The command exit code. - * @param code The program exit code - */ - void exitCode(int code); -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java deleted file mode 100644 index 16353bb..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Core.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ -package org.apache.airavata.gsi.ssh.api; - -import org.apache.airavata.gsi.ssh.api.job.JobDescriptor; - -/** - * This represents a CPU core of a machine in the cluster - */ -public class Core { - private JobDescriptor job; - private String id; - - public Core(String id) { - this.id = id; - this.job = null; - } - - /** - * @return core's id - */ - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - /** - * @return job running on the core - */ - public JobDescriptor getJob() { - return job; - } - - public void setJob(JobDescriptor job) { - this.job = job; - } - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Node.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Node.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Node.java deleted file mode 100644 index 4650867..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/Node.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ -package org.apache.airavata.gsi.ssh.api; - -import java.util.HashMap; - -public class Node { - private String Name; - private Core[] Cores; - private String state; - private HashMap<String, String> status; - private String np; - private String ntype; - - /** - * @return the machine's name - */ - public String getName() { - return Name; - } - - public void setName(String Name) { - this.Name = Name; - } - - /** - * @return machine cores as an array - */ - public Core[] getCores() { - return Cores; - } - - public void setCores(Core[] Cores) { - this.Cores = Cores; - } - - - /** - * @return the machine state - */ - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - /** - * @return the status - */ - public HashMap<String, String> getStatus() { - return status; - } - - public void setStatus(HashMap<String, String> status) { - this.setStatus(status); - } - - - /** - * @return the number of cores in the machine - */ - public String getNp() { - return np; - } - - - public void setNp(String np) { - this.np = np; - } - - /** - * @return the ntype of the machine - */ - public String getNtype() { - return ntype; - } - - - public void setNtype(String ntype) { - this.ntype = ntype; - } - - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/SSHApiException.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/SSHApiException.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/SSHApiException.java deleted file mode 100644 index f6f41d3..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/SSHApiException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.airavata.gsi.ssh.api; - -/** - * An exception class to wrap SSH command execution related errors. - */ -public class SSHApiException extends Exception { - - public SSHApiException(String message) { - super(message); - } - - public SSHApiException(String message, Exception e) { - super(message, e); - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/ServerInfo.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/ServerInfo.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/ServerInfo.java deleted file mode 100644 index 7385f70..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/ServerInfo.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.apache.airavata.gsi.ssh.api;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/** - * Encapsulate server information. - */ -public class ServerInfo { - - private String host; - private String userName; - private int port = 22; - - public ServerInfo(String userName, String host) { - this.userName = userName; - this.host = host; - } - - public ServerInfo(String userName,String host, int port) { - this.host = host; - this.userName = userName; - this.port = port; - } - - public String getHost() { - return host; - } - - public void setHost(String host) { - this.host = host; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/AuthenticationInfo.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/AuthenticationInfo.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/AuthenticationInfo.java deleted file mode 100644 index 84cbae1..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/AuthenticationInfo.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.airavata.gsi.ssh.api.authentication;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/** - * User: AmilaJ ([email protected]) - * Date: 10/4/13 - * Time: 11:25 AM - */ - -/** - * An empty interface that represents authentication data to the API. - */ -public interface AuthenticationInfo { -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/GSIAuthenticationInfo.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/GSIAuthenticationInfo.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/GSIAuthenticationInfo.java deleted file mode 100644 index 3ed81c0..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/GSIAuthenticationInfo.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.airavata.gsi.ssh.api.authentication;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -import org.ietf.jgss.GSSCredential; - -import java.util.Properties; - -/** - * Authentication data. Could be MyProxy user name, password, could be GSSCredentials - * or could be SSH keys. - */ -public abstract class GSIAuthenticationInfo implements AuthenticationInfo { - - public Properties properties = new Properties(); - - public abstract GSSCredential getCredentials() throws SecurityException; - - public Properties getProperties() { - return properties; - } - - public void setProperties(Properties properties) { - this.properties = properties; - } -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHKeyAuthentication.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHKeyAuthentication.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHKeyAuthentication.java deleted file mode 100644 index f56cdbf..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHKeyAuthentication.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apache.airavata.gsi.ssh.api.authentication;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -/** - * User: AmilaJ ([email protected]) - * Date: 10/4/13 - * Time: 2:39 PM - */ - -/** - * Abstracts out common methods for SSH key authentication. - */ -public interface SSHKeyAuthentication extends AuthenticationInfo { - - /** - * This is needed only if private key and public keys are encrypted. - * If they are not encrypted we can just return null. - * @return User should return pass phrase if keys are encrypted. If not null. - */ - String getPassPhrase(); - - /** - * Callback with the banner message. API user can get hold of banner message - * by implementing this method. - * @param message The banner message. - */ - void bannerMessage(String message); -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPasswordAuthentication.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPasswordAuthentication.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPasswordAuthentication.java deleted file mode 100644 index f9adcdb..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPasswordAuthentication.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.airavata.gsi.ssh.api.authentication; - -/** - * User: AmilaJ ([email protected]) - * Date: 10/4/13 - * Time: 11:22 AM - */ - -/** - * Password authentication for vanilla SSH. - */ -public interface SSHPasswordAuthentication extends AuthenticationInfo { - - /** - * Gets the password for given host name and given user name. - * @param userName The connecting user name name. - * @param hostName The connecting host. - * @return Password for the given user. - */ - String getPassword(String userName, String hostName); - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyAuthentication.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyAuthentication.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyAuthentication.java deleted file mode 100644 index 7c3f5e7..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyAuthentication.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - -package org.apache.airavata.gsi.ssh.api.authentication; - -/** - * User: AmilaJ ([email protected]) - * Date: 10/4/13 - * Time: 9:48 AM - */ - - -/** - * Public key authentication for vanilla SSH. - * The public key and private key are returned as byte arrays. Useful when we store private key/public key - * in a secure storage such as credential store. API user should implement this. - */ -public interface SSHPublicKeyAuthentication extends SSHKeyAuthentication { - - /** - * Gets the public key as byte array. - * @param userName The user who is trying to SSH - * @param hostName The host which user wants to connect to. - * @return The public key as a byte array. - */ - byte[] getPrivateKey(String userName, String hostName); - - /** - * Gets the private key as byte array. - * @param userName The user who is trying to SSH - * @param hostName The host which user wants to connect to. - * @return The private key as a byte array. - */ - byte[] getPublicKey(String userName, String hostName); - -} http://git-wip-us.apache.org/repos/asf/airavata/blob/7b809747/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyFileAuthentication.java ---------------------------------------------------------------------- diff --git a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyFileAuthentication.java b/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyFileAuthentication.java deleted file mode 100644 index e074acd..0000000 --- a/tools/gsissh/src/main/java/org/apache/airavata/gsi/ssh/api/authentication/SSHPublicKeyFileAuthentication.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apache.airavata.gsi.ssh.api.authentication;/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -/** - * User: AmilaJ ([email protected]) - * Date: 10/4/13 - * Time: 9:52 AM - */ - -/** - * Public key authentication for vanilla SSH. - * The public key and private key stored files are returned. API user should implement this. - */ -public interface SSHPublicKeyFileAuthentication extends SSHKeyAuthentication { - - /** - * The file which contains the public key. - * @param userName The user who is trying to SSH - * @param hostName The host which user wants to connect to. - * @return The name of the file which contains the public key. - */ - String getPublicKeyFile(String userName, String hostName); - - /** - * The file which contains the public key. - * @param userName The user who is trying to SSH - * @param hostName The host which user wants to connect to. - * @return The name of the file which contains the private key. - */ - String getPrivateKeyFile(String userName, String hostName); - - -}
