geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r917413 - in /geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool: ./ src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
Date Mon, 01 Mar 2010 08:04:42 GMT
Author: genspring
Date: Mon Mar  1 08:04:42 2010
New Revision: 917413

URL: http://svn.apache.org/viewvc?rev=917413&view=rev
Log:
GERONIMO-4896 Commands to a Secure JMX Connector require the SSL keyStorePassword to be specified
on command line, modified based on additional improvement patch from Ashish.

Modified:
    geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/   (props changed)
    geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
    geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java

Propchange: geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Mar  1 08:04:42 2010
@@ -0,0 +1 @@
+/geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool:917412

Modified: geronimo/server/branches/2.2/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.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java?rev=917413&r1=917412&r2=917413&view=diff
==============================================================================
--- geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
(original)
+++ geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
Mon Mar  1 08:04:42 2010
@@ -17,16 +17,13 @@
 
 package org.apache.geronimo.deployment.cli;
 
-import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Serializable;
+import java.util.Properties;
 import java.util.jar.JarFile;
 
 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
@@ -45,9 +42,9 @@
 import org.apache.geronimo.kernel.Kernel;
 
 /**
- * Supports online connections to the server, via JSR-88, valid only
- * when the server is online.
- *
+ * Supports online connections to the server, via JSR-88, valid only when the
+ * server is online.
+ * 
  * @version $Rev$ $Date$
  */
 public class ServerConnection {
@@ -59,15 +56,19 @@
     private SavedAuthentication auth;
     private boolean logToSysErr;
     private boolean verboseMessages;
-    String KEYSTORE_TRUSTSTORE_PASSWORD_FILE="org.apache.geronimo.keyStoreTrustStorePasswordFile";
-    String DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION="/var/security/keystores/geronimo-default";
-    String GERONIMO_HOME="org.apache.geronimo.home.dir";
+    String KEYSTORE_TRUSTSTORE_PASSWORD_FILE = "org.apache.geronimo.keyStoreTrustStorePasswordFile";
+    String DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION = "/var/security/keystores/geronimo-default";
+    String GERONIMO_HOME = "org.apache.geronimo.home.dir";
+    String DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE = System.getProperty(GERONIMO_HOME)
+            + "/var/config/config-substitutions.properties";
 
-    public ServerConnection(ConnectionParams params, PrintWriter out, InputStream in, Kernel
kernel, DeploymentFactory geronimoDeploymentFactory) throws DeploymentException {
+    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 {
+
+    public ServerConnection(ConnectionParams params, UsernamePasswordHandler handler, Kernel
kernel,
+            DeploymentFactory geronimoDeploymentFactory) throws DeploymentException {
         if (null == kernel) {
             throw new IllegalArgumentException("kernel is required");
         }
@@ -84,7 +85,7 @@
         logToSysErr = params.isSyserr();
         boolean offline = params.isOffline();
         boolean secure = params.isSecure();
-        
+
         if ((driver != null) && uri == null) {
             throw new DeploymentSyntaxException("A custom driver requires a custom URI");
         }
@@ -106,7 +107,7 @@
         OfflineDeployerStarter offlineDeployerStarter = new OfflineDeployerStarter(kernel);
         offlineDeployerStarter.start();
     }
-    
+
     public void close() throws DeploymentException {
         if (manager != null) {
             manager.release();
@@ -121,7 +122,8 @@
         return (auth == null) ? null : auth.getURI();
     }
 
-    private void tryToConnect(String argURI, String driver, String user, String password,
boolean secure) throws DeploymentException {
+    private void tryToConnect(String argURI, String driver, String user, String password,
boolean secure)
+            throws DeploymentException {
         DeploymentFactoryManager mgr = DeploymentFactoryManager.getInstance();
         if (driver != null) {
             loadDriver(driver, mgr);
@@ -136,46 +138,38 @@
                 if (savedAuthentication != null) {
                     user = savedAuthentication.getUser();
                     password = new String(savedAuthentication.getPassword());
-                }  
+                }
             } catch (IOException e) {
                 System.out.println("Warning: " + e.getMessage());
-            }          
+            }
         }
 
-        if(secure)
-        {
+        if (secure) {
             try {
-            FileInputStream fstream= new FileInputStream(System.getProperty(KEYSTORE_TRUSTSTORE_PASSWORD_FILE));
-            DataInputStream in = new DataInputStream(fstream);
-            BufferedReader br = new BufferedReader(new InputStreamReader(in));
-            String strLine;
-            String keyStorePassword=null;
-            String trustStorePassword=null;
-            while ((strLine = br.readLine()) != null)   {
-                if(strLine.startsWith("keyStorePassword"))
-                {
-                    keyStorePassword=(String)EncryptionManager.decrypt(strLine.substring(17));
                   
-                }
-                if(strLine.startsWith("trustStorePassword"))
-                {
-                    trustStorePassword=(String)EncryptionManager.decrypt(strLine.substring(19));;
-                }
-            }
-             
-            String value=System.getProperty("javax.net.ssl.keyStore",System.getProperty(GERONIMO_HOME)+DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
-            String value1=System.getProperty("javax.net.ssl.trustStore",System.getProperty(GERONIMO_HOME)+DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
-            System.setProperty("javax.net.ssl.keyStore", value);
-            System.setProperty("javax.net.ssl.trustStore", value1);
-            System.setProperty("javax.net.ssl.keyStorePassword",keyStorePassword);
-            System.setProperty("javax.net.ssl.trustStorePassword",trustStorePassword);
-            }
-            catch(NullPointerException e)
-            {
-                throw new NullPointerException("Null value specified for trustStore keyStore
location property org.apache.geronimo.keyStoreTrustStorePasswordFile");
-            }
-            catch(IOException e)
-            {
-                throw new DeploymentException("Unable to set KeyStorePassword and TrustStorePassword",
e);
+                Properties props = new Properties();
+
+                String keyStorePassword = null;
+                String trustStorePassword = null;
+
+                FileInputStream fstream = new FileInputStream(System.getProperty(KEYSTORE_TRUSTSTORE_PASSWORD_FILE,
+                        DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE));
+                props.load(fstream);
+
+                keyStorePassword = (String) EncryptionManager.decrypt(props.getProperty("keyStorePassword"));
+                trustStorePassword = (String) EncryptionManager.decrypt(props.getProperty("trustStorePassword"));
+
+                fstream.close();
+
+                String value = System.getProperty("javax.net.ssl.keyStore", System.getProperty(GERONIMO_HOME)
+                        + DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
+                String value1 = System.getProperty("javax.net.ssl.trustStore", System.getProperty(GERONIMO_HOME)
+                        + DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
+                System.setProperty("javax.net.ssl.keyStore", value);
+                System.setProperty("javax.net.ssl.trustStore", value1);
+                System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
+                System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+            } catch (IOException e) {
+                throw new DeploymentException("Unable to set KeyStorePassword and TrustStorePassword.",
e);
             }
         }
         if (user == null || password == null) {
@@ -220,7 +214,8 @@
             JarFile jar = new JarFile(file);
             className = jar.getManifest().getMainAttributes().getValue("J2EE-DeploymentFactory-Implementation-Class");
             if (className == null) {
-                throw new DeploymentException("The driver JAR " + file.getAbsolutePath()
+ " does not specify a J2EE-DeploymentFactory-Implementation-Class; cannot load driver.");
+                throw new DeploymentException("The driver JAR " + file.getAbsolutePath()
+                        + " does not specify a J2EE-DeploymentFactory-Implementation-Class;
cannot load driver.");
             }
             jar.close();
             DeploymentFactory factory = (DeploymentFactory) Class.forName(className).newInstance();
@@ -228,7 +223,8 @@
         } catch (DeploymentException e) {
             throw e;
         } catch (Exception e) {
-            throw new DeploymentSyntaxException("Unable to load driver class " + className
+ " from JAR " + file.getAbsolutePath(), e);
+            throw new DeploymentSyntaxException("Unable to load driver class " + className
+ " from JAR "
+                    + file.getAbsolutePath(), e);
         }
     }
 
@@ -242,9 +238,10 @@
 
     public static interface UsernamePasswordHandler {
         String getUsername() throws IOException;
+
         String getPassword() throws IOException;
     }
-    
+
     private static class DefaultUserPasswordHandler implements UsernamePasswordHandler {
 
         private PrintWriter out;
@@ -255,12 +252,12 @@
             this.out = out;
             this.in = in;
         }
-        
+
         private void initPrompt() throws IOException {
             this.prompt = new InputPrompt(this.in, this.out);
         }
-        
-        public String getPassword() throws IOException {   
+
+        public String getPassword() throws IOException {
             initPrompt();
             return this.prompt.getPassword("Password: ");
         }
@@ -269,6 +266,6 @@
             initPrompt();
             return this.prompt.getInput("Username: ");
         }
-        
+
     }
 }

Modified: geronimo/server/branches/2.2/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.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java?rev=917413&r1=917412&r2=917413&view=diff
==============================================================================
--- geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
(original)
+++ geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
Mon Mar  1 08:04:42 2010
@@ -17,14 +17,12 @@
 
 package org.apache.geronimo.deployment.cli;
 
-import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.FileInputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.net.MalformedURLException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.management.MBeanServerConnection;
 import javax.management.remote.JMXConnector;
@@ -33,7 +31,6 @@
 import javax.management.remote.rmi.RMIConnectorServer;
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 
-import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.crypto.EncryptionManager;
 import org.apache.geronimo.deployment.cli.DeployUtils.SavedAuthentication;
 import org.apache.geronimo.gbean.GBeanInfo;
@@ -49,31 +46,35 @@
 
     public static final String RMI_NAMING_CONFG_ID = "org/apache/geronimo/RMINaming";
 
-    public static final String DEFAULT_PORT = "1099"; // 1099 is used by java.rmi.registry.Registry
+    public static final String DEFAULT_PORT = "1099"; // 1099 is used by
+                                                      // java.rmi.registry.Registry
 
     String host;
-    
+
     String port;
 
     String user;
 
     String password;
-    
+
     boolean secure = false;
 
     private String[] args;
-    String KEYSTORE_TRUSTSTORE_PASSWORD_FILE="org.apache.geronimo.keyStoreTrustStorePasswordFile";
-    String DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION="/var/security/keystores/geronimo-default";
-    String GERONIMO_HOME="org.apache.geronimo.home.dir";
+    String KEYSTORE_TRUSTSTORE_PASSWORD_FILE = "org.apache.geronimo.keyStoreTrustStorePasswordFile";
+    String DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION = "/var/security/keystores/geronimo-default";
+    String GERONIMO_HOME = "org.apache.geronimo.home.dir";
+    String DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE = System.getProperty(GERONIMO_HOME)
+            + "/var/config/config-substitutions.properties";
 
     public static void main(String[] args) throws Exception {
         StopServer cmd = new StopServer();
         cmd.execute(args);
     }
-    
+
     public int execute(Object opaque) {
-        if (! (opaque instanceof String[])) {
-            throw new IllegalArgumentException("Argument type is [" + opaque.getClass() +
"]; expected [" + String[].class + "]");
+        if (!(opaque instanceof String[])) {
+            throw new IllegalArgumentException("Argument type is [" + opaque.getClass() +
"]; expected ["
+                    + String[].class + "]");
         }
         this.args = (String[]) opaque;
 
@@ -89,7 +90,7 @@
             printUsage();
         }
 
-        Integer portI = null;        
+        Integer portI = null;
         if (port != null) {
             try {
                 portI = new Integer(port);
@@ -140,7 +141,9 @@
                 kernel = getRunningKernel();
             } catch (IOException e) {
                 System.out.println();
-                System.out.println("Could not communicate with the server.  The server may
not be running or the port number may be incorrect (" + e.getMessage() + ")");
+                System.out
+                        .println("Could not communicate with the server.  The server may
not be running or the port number may be incorrect ("
+                                + e.getMessage() + ")");
             }
             if (kernel != null) {
                 System.out.println("Server found.");
@@ -176,41 +179,34 @@
         } else if (args[i].equals("--secure")) {
             secure = true;
             try {
-                FileInputStream fstream= new FileInputStream(System.getProperty(KEYSTORE_TRUSTSTORE_PASSWORD_FILE));
-                DataInputStream in = new DataInputStream(fstream);
-                BufferedReader br = new BufferedReader(new InputStreamReader(in));
-                String strLine;
-                String keyStorePassword=null;
-                String trustStorePassword=null;
-                while ((strLine = br.readLine()) != null)   {
-                    if(strLine.startsWith("keyStorePassword"))
-                    {
-                        keyStorePassword=(String)EncryptionManager.decrypt(strLine.substring(17));
                   
-                    }
-                    if(strLine.startsWith("trustStorePassword"))
-                    {
-                        trustStorePassword=(String)EncryptionManager.decrypt(strLine.substring(19));;
-                    }
-                }
-                 
-                String value=System.getProperty("javax.net.ssl.keyStore",System.getProperty(GERONIMO_HOME)+DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
-                String value1=System.getProperty("javax.net.ssl.trustStore",System.getProperty(GERONIMO_HOME)+DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
+                Properties props = new Properties();
+
+                String keyStorePassword = null;
+                String trustStorePassword = null;
+
+                FileInputStream fstream = new FileInputStream(System.getProperty(KEYSTORE_TRUSTSTORE_PASSWORD_FILE,
+                        DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE));
+                props.load(fstream);
+
+                keyStorePassword = (String) EncryptionManager.decrypt(props.getProperty("keyStorePassword"));
+                trustStorePassword = (String) EncryptionManager.decrypt(props.getProperty("trustStorePassword"));
+
+                fstream.close();
+
+                String value = System.getProperty("javax.net.ssl.keyStore", System.getProperty(GERONIMO_HOME)
+                        + DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
+                String value1 = System.getProperty("javax.net.ssl.trustStore", System.getProperty(GERONIMO_HOME)
+                        + DEFAULT_TRUSTSTORE_KEYSTORE_LOCATION);
                 System.setProperty("javax.net.ssl.keyStore", value);
                 System.setProperty("javax.net.ssl.trustStore", value1);
-                System.setProperty("javax.net.ssl.keyStorePassword",keyStorePassword);
-                System.setProperty("javax.net.ssl.trustStorePassword",trustStorePassword);
-                }
-                
-                catch(NullPointerException e)
-                {
-                throw new NullPointerException("Null value specified for trustStore keyStore
location property org.apache.geronimo.keyStoreTrustStorePasswordFile");
-                }
-                
-                catch(IOException e)
-                {
-                    System.out.println("Unable to set KeyStorePassword and TrustStorePassword");
-                    e.printStackTrace();                    
-                }
+                System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword);
+                System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
+            }
+
+            catch (IOException e) {
+                System.out.println("Unable to set KeyStorePassword and TrustStorePassword");
+                e.printStackTrace();
+            }
         } else {
             printUsage();
         }
@@ -228,8 +224,8 @@
         }
         Kernel kernel = null;
         try {
-            JMXServiceURL address = new JMXServiceURL(
-                    "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + connectorName);
+            JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" +
host + ":" + port
+                    + connectorName);
             JMXConnector jmxConnector = JMXConnectorFactory.connect(address, map);
             MBeanServerConnection mbServerConnection = jmxConnector.getMBeanServerConnection();
             kernel = new KernelDelegate(mbServerConnection);



Mime
View raw message