Author: dblevins
Date: Sat Oct 10 08:16:34 2009
New Revision: 823815

URL: http://svn.apache.org/viewvc?rev=823815&view=rev
Log:
Tweaked the tool so it defaults to Static3DES and lists the available ciphers.  
Also doesn't "pretty" up the output and just prints the encrypted value.  Makes 
it easier on command-line junkies like myself who like to pipe and script stuff 
(saves me from having to strip off the junk i don't care about).

Modified:
    
openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
    
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Cipher.java
    
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
    
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
    
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/Messages.properties

Modified: 
openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml?rev=823815&r1=823814&r2=823815&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
 (original)
+++ 
openejb/trunk/openejb3/assembly/openejb-tomcat/openejb-tomcat-webapp/src/main/resources/META-INF/org.apache.openejb.tomcat/service-jar.xml
 Sat Oct 10 08:16:34 2009
@@ -324,6 +324,8 @@
 
     Password
 
+    PasswordCipher  PlainText
+
     # The connection properties that will be sent to the JDBC
     # driver when establishing new connections
     #
@@ -512,6 +514,8 @@
     #Password pass
     Password
 
+    PasswordCipher  PlainText
+
     # The connection properties that will be sent to the JDBC
     # driver when establishing new connections
     #

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Cipher.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Cipher.java?rev=823815&r1=823814&r2=823815&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Cipher.java
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/Cipher.java
 Sat Oct 10 08:16:34 2009
@@ -17,6 +17,8 @@
 package org.apache.openejb.config;
 
 import java.sql.SQLException;
+import java.util.Map;
+import java.io.IOException;
 
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
@@ -30,6 +32,8 @@
 import org.apache.openejb.resource.jdbc.BasicDataSourceUtil;
 import org.apache.openejb.resource.jdbc.PasswordCipher;
 import org.apache.openejb.util.Messages;
+import org.apache.openejb.util.Join;
+import org.apache.xbean.finder.ResourceFinder;
 
 /**
  * Command line tool on top of the {...@link 
org.apache.openejb.resource.jdbc.PasswordCipher} interface. Basically,
@@ -65,42 +69,54 @@
             return;
         }
 
-        if (!line.hasOption("cipher")) {
-            System.out.println("Must specify the PasswordCipher implementation 
to use.");
-            help(options);
-            return;
+        String cipherName = "Static3DES";
+        if (line.hasOption("cipher")) {
+            cipherName = line.getOptionValue("cipher");
         }
 
         if (line.getArgList().size() != 1) {
-            System.out.println("Must specify either a plain text to encrypt, 
either a ciphered value to decrypt.");
+            System.out.println("Must specify either a plain text to encrypt or 
a ciphered value to decrypt.");
             help(options);
             return;
         }
 
         try {
-            PasswordCipher cipher = 
BasicDataSourceUtil.getPasswordCipher(line.getOptionValue("cipher"));
+            PasswordCipher cipher = 
BasicDataSourceUtil.getPasswordCipher(cipherName);
 
             if (line.hasOption("decrypt")) {
                 String pwdArg = (String) line.getArgList().get(0);
                 char[] encryptdPassword = pwdArg.toCharArray();
-                System.out.println("The plain text value for " + pwdArg + " is 
" + cipher.decrypt(encryptdPassword));
+                System.out.println(cipher.decrypt(encryptdPassword));
 
             } else { // if option neither encrypt/decrypt is specified, we 
assume
                      // it is encrypt.
                 String plainPassword = (String) line.getArgList().get(0);
-                System.out.println("The encrypt value for " + plainPassword + 
" is " + new String(cipher.encrypt(plainPassword)));
+                System.out.println(new String(cipher.encrypt(plainPassword)));
             }
 
         } catch (SQLException e) {
             System.out.println("Could not load password cipher implementation 
class. Check your classpath.");
+
+            availableCiphers();
+
             throw new SystemExitException(-1);
         }
 
     }
 
+    private static void availableCiphers() {
+        try {
+            ResourceFinder finder = new ResourceFinder("META-INF/");
+            Map<String, Class> impls = 
finder.mapAllImplementations(PasswordCipher.class);
+            System.out.println("Available ciphers are: "+ Join.join(",", 
impls.keySet()));
+        } catch (Exception dontCare) {
+        }
+    }
+
     private static void help(Options options) {
         HelpFormatter formatter = new HelpFormatter();
         formatter.printHelp("cipher [options] <value>", "\n" + 
i18n("cmd.cipher.description"), options, "\n");
+        availableCiphers();
     }
 
     private static Option option(String shortOpt, String longOpt, String 
description) {

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml?rev=823815&r1=823814&r2=823815&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb.embedded/service-jar.xml
 Sat Oct 10 08:16:34 2009
@@ -310,6 +310,8 @@
 
     Password
 
+    PasswordCipher  PlainText
+
     # The connection properties that will be sent to the JDBC
     # driver when establishing new connections
     #
@@ -498,6 +500,8 @@
     #Password pass
     Password
 
+    PasswordCipher  PlainText
+
     # The connection properties that will be sent to the JDBC
     # driver when establishing new connections
     #

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml?rev=823815&r1=823814&r2=823815&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/META-INF/org.apache.openejb/service-jar.xml
 Sat Oct 10 08:16:34 2009
@@ -313,6 +313,9 @@
 
     Password
 
+    PasswordCipher  PlainText
+
+
     # The connection properties that will be sent to the JDBC
     # driver when establishing new connections
     #
@@ -497,6 +500,8 @@
 
     Password
 
+    PasswordCipher  PlainText
+
     # The connection properties that will be sent to the JDBC
     # driver when establishing new connections
     #

Modified: 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/Messages.properties
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/Messages.properties?rev=823815&r1=823814&r2=823815&view=diff
==============================================================================
--- 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/Messages.properties
 (original)
+++ 
openejb/trunk/openejb3/container/openejb-core/src/main/resources/org/apache/openejb/config/Messages.properties
 Sat Oct 10 08:16:34 2009
@@ -25,7 +25,7 @@
 cmd.cipher.opt.help = Lists these options and exits.
 
 #options.addOption(option("i", "cipher", "cmd.cipher.opt.impl"));
-cmd.cipher.opt.impl = Specifies the password cipher implementation to use.
+cmd.cipher.opt.impl = Specifies the password cipher implementation to use 
(default is Static3DES).
 
 #options.addOption(option("d", "decrypt", "cmd.cipher.opt.decrypt"));
 cmd.cipher.opt.decrypt = Switches command line tool to decrypt.


Reply via email to