geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r728391 - in /geronimo/server/trunk: assemblies/geronimo-boilerplate/src/main/underlay/contents/etc/ framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ framework/modules/geronimo-deploy-tool/src/main/java/org/...
Date Sun, 21 Dec 2008 05:41:54 GMT
Author: gawor
Date: Sat Dec 20 21:41:53 2008
New Revision: 728391

URL: http://svn.apache.org/viewvc?rev=728391&view=rev
Log:
login command for gshell and support for saved credentails in gshell commands (GERONIMO-4464)

Added:
    geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/LoginCommand.groovy
Modified:
    geronimo/server/trunk/assemblies/geronimo-boilerplate/src/main/underlay/contents/etc/layout.xml
    geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java

Modified: geronimo/server/trunk/assemblies/geronimo-boilerplate/src/main/underlay/contents/etc/layout.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate/src/main/underlay/contents/etc/layout.xml?rev=728391&r1=728390&r2=728391&view=diff
==============================================================================
--- geronimo/server/trunk/assemblies/geronimo-boilerplate/src/main/underlay/contents/etc/layout.xml
(original)
+++ geronimo/server/trunk/assemblies/geronimo-boilerplate/src/main/underlay/contents/etc/layout.xml
Sat Dec 20 21:41:53 2008
@@ -127,6 +127,11 @@
 
             <nodes>
                 <command>
+                    <name>login</name>
+                    <id>geronimo-commands:login</id>
+                </command>
+
+                <command>
                     <name>connect</name>
                     <id>geronimo-commands:connect</id>
                 </command>

Modified: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy?rev=728391&r1=728390&r2=728391&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
Sat Dec 20 21:41:53 2008
@@ -23,6 +23,7 @@
 import org.apache.geronimo.gshell.command.annotation.CommandComponent
 import org.apache.geronimo.gshell.command.CommandSupport
 import org.apache.geronimo.deployment.cli.ServerConnection
+import org.apache.geronimo.deployment.cli.ServerConnection.UsernamePasswordHandler
 import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryWithKernel
 import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager
 import org.apache.geronimo.cli.deployer.ConnectionParamsImpl
@@ -68,27 +69,12 @@
         if (!quiet) {
         	io.out.println("Connecting to Geronimo server: ${hostname}:${port}")
         }
-        
-        // If the username/password was not configured via cli, then prompt the user for
the values
-        if (username == null || password == null) {
-            if (username == null) {
-                username = prompter.readLine('Username: ')
-            }
-
-            if (password == null) {
-                password = prompter.readPassword('Password: ')
-            }
-
-            //
-            // TODO: Handle null inputs...
-            //
-        }
-        
+                
         def kernel = new BasicKernel('gshell deployer')
         def deploymentManager = new RemoteDeploymentManager(Collections.emptySet())
         def deploymentFactory = new DeploymentFactoryWithKernel(kernel, deploymentManager)
         def connectionParams = new ConnectionParamsImpl(host: hostname, port: port, user:
username, password: password, offline: false, secure: secure)
-        def connection = new ServerConnection(connectionParams, io.out, io.inputStream, kernel,
deploymentFactory)
+        def connection = new ServerConnection(connectionParams, new GShellUserPasswordHandler(prompter),
kernel, deploymentFactory)
 
         // Disconnect previous connection if any
         disconnect()
@@ -131,3 +117,20 @@
         variables.parent.unset(SERVER_CONNECTION)
     }
 }
+
+class GShellUserPasswordHandler implements UsernamePasswordHandler {
+
+    PromptReader prompter
+    
+    public GShellUserPasswordHandler(PromptReader prompter) {
+        this.prompter = prompter
+    }
+    
+    public String getPassword() throws IOException {  
+        return prompter.readPassword('Password: ') 
+    }
+
+    public String getUsername() throws IOException {
+        return prompter.readLine('Username: ')        
+    }
+}

Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/LoginCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/LoginCommand.groovy?rev=728391&view=auto
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/LoginCommand.groovy
(added)
+++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/LoginCommand.groovy
Sat Dec 20 21:41:53 2008
@@ -0,0 +1,49 @@
+/*
+ * 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.commands
+
+import jline.ConsoleReader
+
+import org.apache.geronimo.gshell.clp.Argument
+import org.apache.geronimo.gshell.command.annotation.CommandComponent
+import org.apache.geronimo.cli.deployer.BaseCommandArgs
+import org.apache.geronimo.deployment.cli.CommandLogin
+
+/**
+ * Login command.
+ *
+ * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $
+ */
+@CommandComponent(id='geronimo-commands:login', description='Saves the username and password
for this connection')
+class LoginCommand extends ConnectCommand {
+
+    protected Object doExecute() throws Exception {
+        def connection = connect()
+        
+        def command = new CommandLogin()
+        
+        def consoleReader = new ConsoleReader(io.inputStream, io.out)
+        
+        def args = new BaseCommandArgs((String[])[])
+        
+        command.execute(consoleReader, connection, args)
+    }
+    
+}

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java?rev=728391&r1=728390&r2=728391&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java
Sat Dec 20 21:41:53 2008
@@ -148,10 +148,14 @@
     }
     
     public static String getConnectionURI(String host, Integer port, boolean secure) {
-        String uri = (secure) ? DEFAULT_SECURE_URI : DEFAULT_URI;
-        if (host != null || port != null) {
-            uri += "://" + (host == null ? "" : host) + (port == null ? "" : ":" + port);
+        if (host == null) {
+            host = "localhost";
+        }
+        if (port == null) {
+            port = new Integer(1099);
         }
+        String uri = (secure) ? DEFAULT_SECURE_URI : DEFAULT_URI;
+        uri += "://" + host + ":" + port;
         return uri;
     }
     

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java?rev=728391&r1=728390&r2=728391&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
Sat Dec 20 21:41:53 2008
@@ -22,7 +22,6 @@
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.Serializable;
-import java.io.Writer;
 import java.util.jar.JarFile;
 
 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
@@ -49,20 +48,21 @@
     private final DeploymentFactory geronimoDeploymentFactory;
 
     private DeploymentManager manager;
-    private Writer out;
-    private InputStream in;
+    private UsernamePasswordHandler handler;
     private SavedAuthentication auth;
     private boolean logToSysErr;
     private boolean verboseMessages;
 
     public ServerConnection(ConnectionParams params, PrintWriter out, InputStream in, Kernel
kernel, DeploymentFactory geronimoDeploymentFactory) throws DeploymentException {
+        this(params, new DefaultUserPasswordHandler(in, out), kernel, geronimoDeploymentFactory);
+    }
+    
+    public ServerConnection(ConnectionParams params, UsernamePasswordHandler handler, Kernel
kernel, DeploymentFactory geronimoDeploymentFactory) throws DeploymentException {
         if (null == kernel) {
             throw new IllegalArgumentException("kernel is required");
         }
         this.geronimoDeploymentFactory = geronimoDeploymentFactory;
-
-        this.out = out;
-        this.in = in;        
+        this.handler = handler;
 
         String uri = params.getURI();
         String driver = params.getDriver();
@@ -134,12 +134,11 @@
 
         if (user == null || password == null) {
             try {
-                InputPrompt prompt = new InputPrompt(in, out);
                 if (user == null) {
-                    user = prompt.getInput("Username: ");
+                    user = handler.getUsername();
                 }
                 if (password == null) {
-                    password = prompt.getPassword("Password: ");
+                    password = handler.getPassword();
                 }
             } catch (IOException e) {
                 throw new DeploymentException("Unable to prompt for login", e);
@@ -191,4 +190,35 @@
         return manager.getClass().getName().startsWith("org.apache.geronimo.");
     }
 
+    public static interface UsernamePasswordHandler {
+        String getUsername() throws IOException;
+        String getPassword() throws IOException;
+    }
+    
+    private static class DefaultUserPasswordHandler implements UsernamePasswordHandler {
+
+        private PrintWriter out;
+        private InputStream in;
+        private InputPrompt prompt;
+
+        public DefaultUserPasswordHandler(InputStream in, PrintWriter out) {
+            this.out = out;
+            this.in = in;
+        }
+        
+        private void initPrompt() throws IOException {
+            this.prompt = new InputPrompt(this.in, this.out);
+        }
+        
+        public String getPassword() throws IOException {   
+            initPrompt();
+            return this.prompt.getPassword("Password: ");
+        }
+
+        public String getUsername() throws IOException {
+            initPrompt();
+            return this.prompt.getInput("Username: ");
+        }
+        
+    }
 }



Mime
View raw message