Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 50828 invoked from network); 18 Dec 2008 05:08:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Dec 2008 05:08:19 -0000 Received: (qmail 55701 invoked by uid 500); 18 Dec 2008 05:08:31 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 55680 invoked by uid 500); 18 Dec 2008 05:08:31 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 55671 invoked by uid 99); 18 Dec 2008 05:08:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 17 Dec 2008 21:08:31 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Dec 2008 05:08:10 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8A4322388988; Wed, 17 Dec 2008 21:07:50 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r727644 - in /geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli: DeployUtils.java ServerConnection.java StopServer.java Date: Thu, 18 Dec 2008 05:07:50 -0000 To: scm@geronimo.apache.org From: gawor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081218050750.8A4322388988@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gawor Date: Wed Dec 17 21:07:50 2008 New Revision: 727644 URL: http://svn.apache.org/viewvc?rev=727644&view=rev Log: enable shutdown command to use deployer saved credentials (GERONIMO-1367) Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.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/DeployUtils.java?rev=727644&r1=727643&r2=727644&view=diff ============================================================================== --- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java (original) +++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployUtils.java Wed Dec 17 21:07:50 2008 @@ -17,11 +17,20 @@ package org.apache.geronimo.deployment.cli; +import java.io.BufferedInputStream; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.Serializable; import java.io.StringReader; +import java.util.Properties; import jline.ConsoleReader; + +import org.apache.geronimo.crypto.EncryptionManager; import org.apache.geronimo.deployment.plugin.ConfigIDExtractor; /** @@ -30,6 +39,10 @@ * @version $Rev$ $Date$ */ public class DeployUtils extends ConfigIDExtractor { + + private final static String DEFAULT_URI = "deployer:geronimo:jmx"; + private final static String DEFAULT_SECURE_URI = "deployer:geronimo:jmxs"; + /** * Split up an output line so it indents at beginning and end (to fit in a * typical terminal) and doesn't break in the middle of a word. @@ -133,6 +146,92 @@ } return buf.toString(); } + + 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); + } + return uri; + } + + public static SavedAuthentication readSavedCredentials(String uri) throws IOException { + SavedAuthentication auth = null; + InputStream in; + + // First check for .geronimo-deployer on class path (e.g. packaged in deployer.jar) + in = DeployUtils.class.getResourceAsStream("/.geronimo-deployer"); + // If not there, check in home directory + if (in == null) { + File authFile = new File(System.getProperty("user.home"), ".geronimo-deployer"); + if (authFile.exists() && authFile.canRead()) { + try { + in = new BufferedInputStream(new FileInputStream(authFile)); + } catch (FileNotFoundException e) { + // ignore + } + } + } + + if (in != null) { + try { + Properties props = new Properties(); + props.load(in); + String encrypted = props.getProperty("login." + uri); + if (encrypted != null) { + if (encrypted.startsWith("{Plain}")) { + int pos = encrypted.indexOf("/"); + String user = encrypted.substring(7, pos); + String password = encrypted.substring(pos + 1); + auth = new SavedAuthentication(uri, user, password.toCharArray()); + } else { + Object o = EncryptionManager.decrypt(encrypted); + if (o == encrypted) { + throw new IOException("Unknown encryption used in saved login file"); + } else { + auth = (SavedAuthentication) o; + } + } + } + } catch (IOException e) { + throw new IOException("Unable to read authentication from saved login file: " + e.getMessage()); + } finally { + try { + in.close(); + } catch (IOException e) { + // ingore + } + } + } + + return auth; + } + + public final static class SavedAuthentication implements Serializable { + private static final long serialVersionUID = -3127576258038677899L; + + private String uri; + private String user; + private char[] password; + + public SavedAuthentication(String uri, String user, char[] password) { + this.uri = uri; + this.user = user; + this.password = password; + } + + public String getURI() { + return this.uri; + } + + public String getUser() { + return this.user; + } + + public char[] getPassword() { + return this.password; + } + } } 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=727644&r1=727643&r2=727644&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 Wed Dec 17 21:07:50 2008 @@ -17,16 +17,12 @@ package org.apache.geronimo.deployment.cli; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.Serializable; import java.io.Writer; -import java.util.Properties; import java.util.jar.JarFile; import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager; @@ -36,11 +32,11 @@ import org.apache.geronimo.cli.deployer.ConnectionParams; import org.apache.geronimo.common.DeploymentException; +import org.apache.geronimo.deployment.cli.DeployUtils.SavedAuthentication; import org.apache.geronimo.deployment.plugin.factories.AuthenticationFailedException; import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager; import org.apache.geronimo.deployment.plugin.jmx.LocalDeploymentManager; import org.apache.geronimo.kernel.Kernel; -import org.apache.geronimo.crypto.EncryptionManager; /** * Supports online connections to the server, via JSR-88, valid only @@ -50,9 +46,6 @@ */ public class ServerConnection { - private final static String DEFAULT_URI = "deployer:geronimo:jmx"; - private final static String DEFAULT_SECURE_URI = "deployer:geronimo:jmxs"; - private final DeploymentFactory geronimoDeploymentFactory; private DeploymentManager manager; @@ -86,7 +79,7 @@ throw new DeploymentSyntaxException("A custom driver requires a custom URI"); } if (host != null || port != null) { - uri = getDefaultURI(secure) + "://" + (host == null ? "" : host) + (port == null ? "" : ":" + port); + uri = DeployUtils.getConnectionURI(host, port, secure); } if (offline) { startOfflineDeployer(kernel); @@ -103,10 +96,6 @@ OfflineDeployerStarter offlineDeployerStarter = new OfflineDeployerStarter(kernel); offlineDeployerStarter.start(); } - - private static String getDefaultURI(boolean secure) { - return (secure) ? DEFAULT_SECURE_URI : DEFAULT_URI; - } public void close() throws DeploymentException { if (manager != null) { @@ -119,7 +108,7 @@ } String getServerURI() { - return auth.uri; + return (auth == null) ? null : auth.getURI(); } private void tryToConnect(String argURI, String driver, String user, String password, boolean secure) throws DeploymentException { @@ -129,57 +118,18 @@ } else { mgr.registerDeploymentFactory(geronimoDeploymentFactory); } - String useURI = argURI == null ? getDefaultURI(secure) : argURI; + String useURI = argURI == null ? DeployUtils.getConnectionURI(null, null, secure) : argURI; 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"); - // If not there, check in home directory - if (in == null) { - File authFile = new File(System.getProperty("user.home"), ".geronimo-deployer"); - if (authFile.exists() && authFile.canRead()) { - try { - in = new BufferedInputStream(new FileInputStream(authFile)); - } catch (FileNotFoundException e) { - // ignore - } - } - } - if (in != null) { - try { - Properties props = new Properties(); - props.load(in); - String encrypted = props.getProperty("login." + useURI); - if (encrypted != null) { - - if (encrypted.startsWith("{Plain}")) { - int pos = encrypted.indexOf("/"); - user = encrypted.substring(7, pos); - password = encrypted.substring(pos + 1); - } else { - Object o = EncryptionManager.decrypt(encrypted); - if (o == encrypted) { - System.out.print(DeployUtils.reformat("Unknown encryption used in saved login file", 4, 72)); - } else { - SavedAuthentication auth = (SavedAuthentication) o; - if (auth.uri.equals(useURI)) { - user = auth.user; - password = new String(auth.password); - } - } - } - } - } catch (IOException e) { - System.out.print(DeployUtils.reformat("Unable to read authentication from saved login file: " + e.getMessage(), 4, 72)); - } finally { - try { - in.close(); - } catch (IOException e) { - // ingore - } - } - } + try { + SavedAuthentication savedAuthentication = DeployUtils.readSavedCredentials(useURI); + if (savedAuthentication != null) { + user = savedAuthentication.getUser(); + password = new String(savedAuthentication.getPassword()); + } + } catch (IOException e) { + System.out.println("Warning: " + e.getMessage()); + } } if (user == null || password == null) { @@ -241,15 +191,4 @@ return manager.getClass().getName().startsWith("org.apache.geronimo."); } - private final static class SavedAuthentication implements Serializable { - private String uri; - private String user; - private char[] password; - - public SavedAuthentication(String uri, String user, char[] password) { - this.uri = uri; - this.user = user; - this.password = password; - } - } } Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.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/StopServer.java?rev=727644&r1=727643&r2=727644&view=diff ============================================================================== --- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java (original) +++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java Wed Dec 17 21:07:50 2008 @@ -29,6 +29,7 @@ import javax.management.remote.rmi.RMIConnectorServer; import javax.rmi.ssl.SslRMIClientSocketFactory; +import org.apache.geronimo.deployment.cli.DeployUtils.SavedAuthentication; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoBuilder; import org.apache.geronimo.kernel.Kernel; @@ -44,7 +45,7 @@ public static final String DEFAULT_PORT = "1099"; // 1099 is used by java.rmi.registry.Registry - String host = "localhost"; + String host; String port; @@ -79,33 +80,52 @@ printUsage(); } - try { - if (port != null) { - Integer.parseInt(port); + Integer portI = null; + if (port != null) { + try { + portI = new Integer(port); + } catch (NumberFormatException e) { + System.out.println("Invalid port number specified."); + return 1; } - } catch (NumberFormatException e) { - System.out.println("Invalid port number specified."); - return 1; } - try { - InputPrompt prompt = new InputPrompt(System.in, System.out); - if (user == null) { - user = prompt.getInput("Username: "); + if (user == null && password == null) { + String uri = DeployUtils.getConnectionURI(host, portI, secure); + try { + SavedAuthentication savedAuthentication = DeployUtils.readSavedCredentials(uri); + if (savedAuthentication != null) { + user = savedAuthentication.getUser(); + password = new String(savedAuthentication.getPassword()); + } + } catch (IOException e) { + System.out.println("Warning: " + e.getMessage()); } - if (password == null) { - password = prompt.getPassword("Password: "); + } + + if (user == null || password == null) { + try { + InputPrompt prompt = new InputPrompt(System.in, System.out); + if (user == null) { + user = prompt.getInput("Username: "); + } + if (password == null) { + password = prompt.getPassword("Password: "); + } + } catch (IOException e) { + System.out.println("Unable to prompt for login."); + return 1; } - } catch (IOException e) { - System.out.println("Unable to prompt for login."); - return 1; } try { if (port == null) { port = DEFAULT_PORT; } - System.out.print("Locating server on port " + port + "... "); + if (host == null) { + host = "localhost"; + } + System.out.print("Locating server on " + host + ":" + port + "... "); Kernel kernel = null; try { kernel = getRunningKernel();