geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r720410 - in /geronimo/gshell/trunk/gshell-commands/gshell-ssh: ./ src/main/java/org/apache/geronimo/gshell/commands/ssh/ src/main/resources/META-INF/gshell/ src/main/resources/org/apache/geronimo/gshell/commands/ssh/
Date Tue, 25 Nov 2008 04:20:58 GMT
Author: jdillon
Date: Mon Nov 24 20:20:57 2008
New Revision: 720410

URL: http://svn.apache.org/viewvc?rev=720410&view=rev
Log:
Adding ssh command, still not quite functional

Added:
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
  (with props)
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
  (with props)
Modified:
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/pom.xml
    geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml

Modified: geronimo/gshell/trunk/gshell-commands/gshell-ssh/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/pom.xml?rev=720410&r1=720409&r2=720410&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/pom.xml (original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/pom.xml Mon Nov 24 20:20:57 2008
@@ -37,6 +37,23 @@
         SSH support.
     </description>
 
+    <repositories>
+        <repository>
+            <id>sshd.snapshots</id>
+            <name>SSHD Repository</name>
+            <url>http://sshd.googlecode.com/svn/m2-snapshot-repo/</url>
+            <layout>default</layout>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>ignore</checksumPolicy>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+        </repository>
+    </repositories>
+
     <dependencies>
         <dependency>
             <groupId>org.apache.geronimo.gshell</groupId>
@@ -52,7 +69,12 @@
             <groupId>org.apache.geronimo.gshell.support</groupId>
             <artifactId>gshell-console</artifactId>
         </dependency>
-        
+
+        <dependency>
+            <groupId>org.apache.geronimo.gshell.support</groupId>
+            <artifactId>gshell-security</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>com.google.code.sshd</groupId>
             <artifactId>sshd</artifactId>

Added: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java?rev=720410&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
(added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
Mon Nov 24 20:20:57 2008
@@ -0,0 +1,145 @@
+/*
+ * 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.geronimo.gshell.commands.ssh;
+
+import com.google.code.sshd.ClientChannel;
+import com.google.code.sshd.ClientSession;
+import com.google.code.sshd.SshClient;
+import org.apache.geronimo.gshell.clp.Argument;
+import org.apache.geronimo.gshell.clp.Option;
+import org.apache.geronimo.gshell.command.CommandAction;
+import org.apache.geronimo.gshell.command.CommandContext;
+import org.apache.geronimo.gshell.i18n.MessageSource;
+import org.apache.geronimo.gshell.io.IO;
+import org.apache.geronimo.gshell.io.PromptReader;
+import org.apache.geronimo.gshell.spring.BeanContainer;
+import org.apache.geronimo.gshell.spring.BeanContainerAware;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.URI;
+
+/**
+ * Connect to a SSH server.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SshAction
+    implements CommandAction, BeanContainerAware
+{
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Option(name="-u", aliases={"--username"})
+    private String username;
+
+    @Option(name="-p", aliases={"--password"})
+    private String password;
+
+    @Argument(required=true, index=0)
+    private URI remote;
+
+    private BeanContainer container;
+
+    public void setBeanContainer(final BeanContainer container) {
+        assert container != null;
+        this.container = container;
+    }
+
+    /**
+     * Helper to validate that prompted username or password is not null or empty.
+     */
+    private class UsernamePasswordValidator
+        implements PromptReader.Validator
+    {
+        private String type;
+
+        private int count = 0;
+
+        private int max = 3;
+
+        public UsernamePasswordValidator(final String type) {
+            assert type != null;
+
+            this.type = type;
+        }
+
+        public boolean isValid(final String value) {
+            count++;
+
+            if (value != null && value.trim().length() > 0) {
+                return true;
+            }
+
+            if (count >= max) {
+                throw new RuntimeException("Too many attempts; failed to prompt user for
" + type + " after " + max + " tries");
+            }
+
+            return false;
+        }
+    }
+
+    public Object execute(final CommandContext context) throws Exception {
+        assert context != null;
+        IO io = context.getIo();
+        MessageSource messages = context.getCommand().getMessages();
+
+        io.info(messages.format("info.connecting", remote.getHost(), remote.getPort()));
+
+        // If the username/password was not configured via cli, then prompt the user for
the values
+        if (username == null || password == null) {
+            PromptReader prompter = new PromptReader(io);
+            String text;
+
+            log.debug("Prompting user for credentials");
+
+            if (username == null) {
+                text = messages.getMessage("prompt.username");
+                username = prompter.readLine(text + ": ", new UsernamePasswordValidator(text));
+            }
+
+            if (password == null) {
+                text = messages.getMessage("prompt.password");
+                password = prompter.readPassword(text + ": ", new UsernamePasswordValidator(text));
+            }
+        }
+
+        // Create the client from prototype
+        SshClient client = container.getBean(SshClient.class);
+        log.debug("Created client: {}", client);
+
+        ClientSession session = client.connect(remote.getHost(), remote.getPort());
+        io.info(messages.getMessage("info.connected"));
+
+        session.authPassword(username, password);
+
+        ClientChannel channel = session.createChannel("shell");
+        channel.setIn(io.inputStream);
+        channel.setOut(io.outputStream);
+        channel.setErr(io.errorStream);
+        channel.open();
+        channel.waitFor(ClientChannel.CLOSED, 0);
+
+        io.verbose(messages.getMessage("verbose.disconnected"));
+
+        return Result.SUCCESS;
+    }
+
+
+}
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/java/org/apache/geronimo/gshell/commands/ssh/SshAction.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml?rev=720410&r1=720409&r2=720410&view=diff
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
(original)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/META-INF/gshell/components.xml
Mon Nov 24 20:20:57 2008
@@ -33,6 +33,10 @@
 
     <gshell:plugin name="gshell-ssh">
         <gshell:command-bundle name="default">
+            <gshell:command name="ssh">
+                <gshell:action class="org.apache.geronimo.gshell.commands.ssh.SshAction"/>
+            </gshell:command>
+
             <gshell:command name="ssh-server">
                 <gshell:action class="org.apache.geronimo.gshell.commands.ssh.SshServerAction"/>
             </gshell:command>
@@ -41,6 +45,9 @@
         </gshell:command-bundle>
     </gshell:plugin>
 
+    <bean name="sshClient" class="com.google.code.sshd.SshClient" factory-method="setUpDefaultClient"
init-method="start" destroy-method="stop">
+    </bean>
+
     <bean name="sshServer" class="com.google.code.sshd.SshServer" factory-method="setUpDefaultServer"
scope="prototype">
         <property name="shellFactory">
             <bean class="org.apache.geronimo.gshell.commands.ssh.ShellFactoryImpl">

Added: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
URL: http://svn.apache.org/viewvc/geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties?rev=720410&view=auto
==============================================================================
--- geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
(added)
+++ geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
Mon Nov 24 20:20:57 2008
@@ -0,0 +1,46 @@
+##
+## 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.
+##
+
+##
+## $Rev$ $Date$
+##
+command.description=Connect to a SSH server.
+
+command.option.local=Bind local address to URI
+command.option.local.token=URI
+
+command.option.username=Remote user name
+command.option.username.token=USERNAME
+
+command.option.password=Remote user password
+command.option.password.token=PASSWORD
+
+command.argument.remote=Connect to remote server at URI
+command.argument.remote.token=URI
+
+command.manual=\
+  TODO: ssh manual
+
+info.connecting=Connecting to: {0}:{1}
+info.connected=Connected
+
+prompt.username=Username
+prompt.password=Password
+
+verbose.disconnected=Disconnected
\ No newline at end of file

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/gshell/trunk/gshell-commands/gshell-ssh/src/main/resources/org/apache/geronimo/gshell/commands/ssh/SshAction.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message