You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/08/12 17:17:43 UTC

svn commit: r803553 - in /maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli: CLIManager.java MavenCli.java

Author: bentmann
Date: Wed Aug 12 15:17:42 2009
New Revision: 803553

URL: http://svn.apache.org/viewvc?rev=803553&view=rev
Log:
[MNG-553] Secure Storage of Server Passwords

o Restored CLI commands to create encrypted passwords

Modified:
    maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
    maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java?rev=803553&r1=803552&r2=803553&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java (original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java Wed Aug 12 15:17:42 2009
@@ -92,6 +92,10 @@
 
     public static final String LOG_FILE = "l";
 
+    public static final String ENCRYPT_MASTER_PASSWORD = "emp";
+
+    public static final String ENCRYPT_PASSWORD = "ep";
+
     private Options options;
 
     @SuppressWarnings("static-access")
@@ -128,6 +132,8 @@
         options.addOption( OptionBuilder.withLongOpt( "also-make-dependents" ).withDescription( "If project list is specified, also build projects that depend on projects on the list" ).create( ALSO_MAKE_DEPENDENTS ) );
         options.addOption( OptionBuilder.withLongOpt( "log-file" ).hasArg().withDescription( "Log file to where all build output will go." ).create( LOG_FILE ) );
         options.addOption( OptionBuilder.withLongOpt( "show-version" ).withDescription( "Display version information WITHOUT stopping build" ).create( SHOW_VERSION ) );
+        options.addOption( OptionBuilder.withLongOpt( "encrypt-master-password" ).hasArg().withDescription( "Encrypt master security password" ).create( ENCRYPT_MASTER_PASSWORD ) );
+        options.addOption( OptionBuilder.withLongOpt( "encrypt-password" ).hasArg().withDescription( "Encrypt server password" ).create( ENCRYPT_PASSWORD ) );
         
         // Adding this back in for compatibility with the verifier that hard codes this option.
         

Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java?rev=803553&r1=803552&r2=803553&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java Wed Aug 12 15:17:42 2009
@@ -30,6 +30,11 @@
 import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.execution.MavenExecutionResult;
 import org.codehaus.plexus.classworlds.ClassWorld;
+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 jason van zyl
@@ -160,6 +165,63 @@
             return 1;
         }
 
+        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 );
+
+                DefaultSecDispatcher dispatcher;
+                dispatcher = (DefaultSecDispatcher) mavenEmbedder.getPlexusContainer().lookup( SecDispatcher.class );
+                String configurationFile = dispatcher.getConfigurationFile();
+                if ( configurationFile.startsWith( "~" ) )
+                {
+                    configurationFile = System.getProperty( "user.home" ) + configurationFile.substring( 1 );
+                }
+                String file = System.getProperty( DefaultSecDispatcher.SYSTEM_PROPERTY_SEC_LOCATION, configurationFile );
+                mavenEmbedder.getPlexusContainer().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 )
+        {
+            CLIReportingUtils.showError( "FATAL ERROR: " + "Error encrypting password: " + e.getMessage(), e, showErrors );
+
+            return 1;
+        }
+
         MavenExecutionResult result = mavenEmbedder.execute( request );
 
         try