geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r917415 - in /geronimo/server/trunk/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:19:21 GMT
Author: genspring
Date: Mon Mar  1 08:19:20 2010
New Revision: 917415

URL: http://svn.apache.org/viewvc?rev=917415&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/trunk/framework/modules/geronimo-deploy-tool/   (props changed)
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/ServerConnection.java
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java

Propchange: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Mon Mar  1 08:19:20 2010
@@ -0,0 +1,2 @@
+/geronimo/server/branches/2.2/framework/modules/geronimo-deploy-tool:826768,832538,885058,917413
+/geronimo/server/trunk/framework/modules/geronimo-deploy-tool:749113,749116-807432,809079-825588

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=917415&r1=917414&r2=917415&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
Mon Mar  1 08:19:20 2010
@@ -17,15 +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.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 +43,9 @@
 import org.apache.geronimo.kernel.util.JarUtils;
 
 /**
- * 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 +57,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");
         }
@@ -136,7 +138,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);
@@ -157,40 +160,32 @@
             }
         }
 
-        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) {
@@ -235,7 +230,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();
@@ -243,7 +239,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);
         }
     }
 
@@ -257,6 +254,7 @@
 
     public static interface UsernamePasswordHandler {
         String getUsername() throws IOException;
+
         String getPassword() throws IOException;
     }
 

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java?rev=917415&r1=917414&r2=917415&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/StopServer.java
Mon Mar  1 08:19:20 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.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import javax.management.MBeanServerConnection;
@@ -34,6 +32,7 @@
 import javax.management.remote.JMXServiceURL;
 import javax.management.remote.rmi.RMIConnectorServer;
 import javax.rmi.ssl.SslRMIClientSocketFactory;
+
 import org.apache.geronimo.crypto.EncryptionManager;
 import org.apache.geronimo.cli.shutdown.ShutdownCLParser;
 import org.apache.geronimo.deployment.cli.DeployUtils.SavedAuthentication;
@@ -57,14 +56,17 @@
 	private boolean secure;
 
     private final Bundle bundle;
-    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";
+    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 DEFAULT_KEYSTORE_TRUSTSTORE_PASSWORD_FILE = System.getProperty(GERONIMO_HOME)
+            + "/var/config/config-substitutions.properties";
 
     public StopServer(Bundle bundle) {
         this.bundle = bundle;
     }
-    
+
     public int execute(Object opaque) {
         if (! (opaque instanceof ShutdownCLParser)) {
             throw new IllegalArgumentException("Argument type is [" + opaque.getClass() +
"]; expected [" + ShutdownCLParser.class + "]");
@@ -86,41 +88,34 @@
         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);
+                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();
+            }
         
         }
         



Mime
View raw message