You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dw...@apache.org on 2008/06/07 16:30:48 UTC

svn commit: r664344 - /geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java

Author: dwoods
Date: Sat Jun  7 07:30:48 2008
New Revision: 664344

URL: http://svn.apache.org/viewvc?rev=664344&view=rev
Log:
GERONIMO-3408 Clean up deployer login code in ServerConnection.  Thanks for the patch Ted.

Modified:
    geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java

Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java?rev=664344&r1=664343&r2=664344&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java Sat Jun  7 07:30:48 2008
@@ -91,7 +91,7 @@
             startOfflineDeployer(kernel);
             manager = new LocalDeploymentManager(kernel);
         } else {
-            tryToConnect(uri, driver, user, password, true);
+            tryToConnect(uri, driver, user, password);
         }
         if (manager == null) {
             throw new DeploymentException("Unexpected error; connection failed.");
@@ -117,7 +117,7 @@
         return auth.uri;
     }
 
-    private void tryToConnect(String argURI, String driver, String user, String password, boolean authPrompt) throws DeploymentException {
+    private void tryToConnect(String argURI, String driver, String user, String password) throws DeploymentException {
         DeploymentFactoryManager mgr = DeploymentFactoryManager.getInstance();
         if (driver != null) {
             loadDriver(driver, mgr);
@@ -126,7 +126,7 @@
         }
         String useURI = argURI == null ? DEFAULT_URI : argURI;
 
-        if (authPrompt && user == null && password == null) {
+        if (user == null && password == null) {
             InputStream in;
             // First check for .geronimo-deployer on class path (e.g. packaged in deployer.jar)
             in = ServerConnection.class.getResourceAsStream("/.geronimo-deployer");
@@ -177,25 +177,28 @@
             }
         }
 
-        if (authPrompt && !useURI.equals(DEFAULT_URI) && user == null && password == null) {
-            // Non-standard URI, but no authentication information
-            doAuthPromptAndRetry(useURI, user, password);
-            return;
-        } else { // Standard URI with no auth, Non-standard URI with auth, or else this is the 2nd try already
+        if (user == null || password == null) {
             try {
-                manager = mgr.getDeploymentManager(useURI, user, password);
-                auth = new SavedAuthentication(useURI, user, password == null ? null : password.toCharArray());
-            } catch (AuthenticationFailedException e) { // server's there, you just can't talk to it
-                if (authPrompt) {
-                    doAuthPromptAndRetry(useURI, user, password);
-                    return;
-                } else {
-                    throw new DeploymentException("Login Failed");
+                InputPrompt prompt = new InputPrompt(in, out);
+                if (user == null) {
+                    user = prompt.getInput("Username: ");
                 }
-            } catch (DeploymentManagerCreationException e) {
-                throw new DeploymentException("Unable to connect to server at " + useURI + " -- " + e.getMessage(), e);
+                if (password == null) {
+                    password = prompt.getPassword("Password: ");
+                }
+            } catch (IOException e) {
+                throw new DeploymentException("Unable to prompt for login", e);
             }
         }
+        try {
+            manager = mgr.getDeploymentManager(useURI, user, password);
+            auth = new SavedAuthentication(useURI, user, password == null ? null : password.toCharArray());
+        } catch (AuthenticationFailedException e) {
+            // server's there, you just can't talk to it
+            throw new DeploymentException("Login Failed");
+        } catch (DeploymentManagerCreationException e) {
+            throw new DeploymentException("Unable to connect to server at " + useURI + " -- " + e.getMessage(), e);
+        }
 
         if (manager instanceof JMXDeploymentManager) {
             JMXDeploymentManager deploymentManager = (JMXDeploymentManager) manager;
@@ -225,21 +228,6 @@
         }
     }
 
-    private void doAuthPromptAndRetry(String uri, String user, String password) throws DeploymentException {
-        try {
-            InputPrompt prompt = new InputPrompt(in, out);
-            if (user == null) {
-                user = prompt.getInput("Username: ");
-            }
-            if (password == null) {
-                password = prompt.getPassword("Password: ");
-            }
-        } catch (IOException e) {
-            throw new DeploymentException("Unable to prompt for login", e);
-        }
-        tryToConnect(uri, null, user, password, false);
-    }
-
     public DeploymentManager getDeploymentManager() {
         return manager;
     }