You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2009/02/20 12:10:30 UTC

svn commit: r746205 - in /maven/components/branches/maven-2.1.x/maven-core/src/main: java/org/apache/maven/cli/CLIManager.java java/org/apache/maven/cli/MavenCli.java resources/META-INF/plexus/components.xml

Author: brett
Date: Fri Feb 20 11:10:29 2009
New Revision: 746205

URL: http://svn.apache.org/viewvc?rev=746205&view=rev
Log:
[MNG-553] add command line options for (master) password encryption

Modified:
    maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java
    maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
    maven/components/branches/maven-2.1.x/maven-core/src/main/resources/META-INF/plexus/components.xml

Modified: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java?rev=746205&r1=746204&r2=746205&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java (original)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/CLIManager.java Fri Feb 20 11:10:29 2009
@@ -74,6 +74,10 @@
     
     public static final String ALSO_MAKE_DEPENDENTS = "amd";
 
+    public static final String ENCRYPT_MASTER_PASSWORD = "emp";
+
+    public static final String ENCRYPT_PASSWORD = "ep";
+
     public CLIManager()
     {
         options = new Options();
@@ -98,6 +102,15 @@
                                         .withDescription( "Display version information" )
                                         .create( VERSION ) );
 
+        options.addOption( OptionBuilder.withLongOpt( "enc-master-passwd" )
+                           .hasArg()
+                           .withDescription( "Encrypt master security password" )
+                           .create( ENCRYPT_MASTER_PASSWORD ) );
+        options.addOption( OptionBuilder.withLongOpt( "enc-passwd" )
+                           .hasArg()
+                           .withDescription( "Encrypt server password" )
+                           .create( ENCRYPT_PASSWORD ) );
+
         options.addOption( OptionBuilder.withLongOpt( "quiet" )
                                         .withDescription( "Quiet output - only show errors" )
                                         .create( QUIET ) );

Modified: maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java?rev=746205&r1=746204&r2=746205&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java Fri Feb 20 11:10:29 2009
@@ -19,6 +19,18 @@
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Properties;
+import java.util.StringTokenizer;
+import java.util.Map.Entry;
+
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.ParseException;
 import org.apache.maven.Maven;
@@ -54,18 +66,11 @@
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Properties;
-import java.util.StringTokenizer;
-import java.util.Map.Entry;
+import org.sonatype.plexus.components.cipher.DefaultPlexusCipher;
+import org.sonatype.plexus.components.sec.dispatcher.DefaultSecDispatcher;
+import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher;
+import org.sonatype.plexus.components.sec.dispatcher.SecUtil;
+import org.sonatype.plexus.components.sec.dispatcher.model.SettingsSecurity;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -135,7 +140,7 @@
             cliManager.displayHelp();
             return 0;
         }
-
+        
         if ( commandLine.hasOption( CLIManager.VERSION ) )
         {
             showVersion();
@@ -203,6 +208,60 @@
             return 1;
         }
 
+        DefaultSecDispatcher dispatcher;
+        try
+        {
+            if ( commandLine.hasOption( CLIManager.ENCRYPT_MASTER_PASSWORD ) )
+            {
+                String passwd = commandLine.getOptionValue( CLIManager.ENCRYPT_MASTER_PASSWORD );
+
+                DefaultPlexusCipher cipher = new DefaultPlexusCipher();
+
+                System.out.println( cipher.encryptAndDecorate( passwd,
+                                                               DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION ) );
+                
+                return 0;
+            }
+            else if ( commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
+            {
+                String passwd = commandLine.getOptionValue( CLIManager.ENCRYPT_PASSWORD );
+                
+                dispatcher = (DefaultSecDispatcher) embedder.lookup( SecDispatcher.ROLE );
+                String file =
+                    System.getProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION,
+                                        dispatcher.getConfigurationFile() );
+                embedder.release( dispatcher );
+                
+                String master = null;
+                
+                SettingsSecurity sec = SecUtil.read( file, true );
+                if ( sec != null )
+                {
+                    master = sec.getMaster();
+                }
+
+                if ( master == null )
+                {
+                    System.err.println( "Master password is not set in the setting security file" );
+                    
+                    return 1;
+                }
+                
+                DefaultPlexusCipher cipher = new DefaultPlexusCipher();
+                String masterPasswd =
+                    cipher.decryptDecorated( master, DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION );
+                System.out.println( cipher.encryptAndDecorate( passwd, masterPasswd ) );
+                
+                return 0;
+            }
+        }
+        catch ( Exception e )
+        {
+            showFatalError( "Error encrypting password: " + e.getMessage(), e, showErrors );
+            
+            return 1;
+        }
+            
         Maven maven = null;
 
         MavenExecutionRequest request = null;

Modified: maven/components/branches/maven-2.1.x/maven-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.1.x/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=746205&r1=746204&r2=746205&view=diff
==============================================================================
--- maven/components/branches/maven-2.1.x/maven-core/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/components/branches/maven-2.1.x/maven-core/src/main/resources/META-INF/plexus/components.xml Fri Feb 20 11:10:29 2009
@@ -616,7 +616,7 @@
         </requirement>
       </requirements>
       <configuration>
-        <_configuration-file>~/.m2/settings-security.xml</_configuration-file>
+        <_configuration-file>${user.home}/.m2/settings-security.xml</_configuration-file>
       </configuration>
     </component>    
   </components>