You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2014/01/10 22:29:29 UTC
git commit: [MNG-4099] Password encryption CLI switches should prompt
for password if missing
Updated Branches:
refs/heads/master 60437a28a -> 626884e9e
[MNG-4099] Password encryption CLI switches should prompt for password if missing
Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/626884e9
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/626884e9
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/626884e9
Branch: refs/heads/master
Commit: 626884e9eeaafe895a0118d3d9d57dd6206c353e
Parents: 60437a2
Author: Robert Scholte <rf...@codehaus.org>
Authored: Fri Jan 10 22:27:25 2014 +0100
Committer: Robert Scholte <rf...@codehaus.org>
Committed: Fri Jan 10 22:29:00 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/maven/cli/CLIManager.java | 4 +--
.../java/org/apache/maven/cli/MavenCli.java | 31 ++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven/blob/626884e9/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
index 1018e29..c6bdd4a 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIManager.java
@@ -132,8 +132,8 @@ public class CLIManager
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 ) );
+ options.addOption( OptionBuilder.withLongOpt( "encrypt-master-password" ).hasOptionalArg().withDescription( "Encrypt master security password" ).create( ENCRYPT_MASTER_PASSWORD ) );
+ options.addOption( OptionBuilder.withLongOpt( "encrypt-password" ).hasOptionalArg().withDescription( "Encrypt server password" ).create( ENCRYPT_PASSWORD ) );
options.addOption( OptionBuilder.withLongOpt( "threads" ).hasArg().withDescription( "Thread count, for instance 2.0C where C is core multiplied" ).create( THREADS ) );
options.addOption( OptionBuilder.withLongOpt( "legacy-local-repository" ).withDescription( "Use Maven 2 Legacy Local Repository behaviour, ie no use of _remote.repositories. Can also be activated by using -Dmaven.legacyLocalRepo=true" ).create( LEGACY_LOCAL_REPOSITORY ) );
http://git-wip-us.apache.org/repos/asf/maven/blob/626884e9/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
----------------------------------------------------------------------
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
index c6d705c..4dcb0b7 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
@@ -19,6 +19,7 @@ package org.apache.maven.cli;
* under the License.
*/
+import java.io.Console;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -497,6 +498,21 @@ public class MavenCli
if ( cliRequest.commandLine.hasOption( CLIManager.ENCRYPT_MASTER_PASSWORD ) )
{
String passwd = cliRequest.commandLine.getOptionValue( CLIManager.ENCRYPT_MASTER_PASSWORD );
+
+ if ( passwd == null )
+ {
+ Console cons;
+ char[] password;
+ if ( ( cons = System.console() ) != null
+ && ( password = cons.readPassword( "Master password:") ) != null )
+ {
+ // Cipher uses Strings
+ passwd = String.copyValueOf( password );
+
+ // Sun/Oracle advises to empty the char array
+ java.util.Arrays.fill( password, ' ' );
+ }
+ }
DefaultPlexusCipher cipher = new DefaultPlexusCipher();
@@ -507,6 +523,21 @@ public class MavenCli
else if ( cliRequest.commandLine.hasOption( CLIManager.ENCRYPT_PASSWORD ) )
{
String passwd = cliRequest.commandLine.getOptionValue( CLIManager.ENCRYPT_PASSWORD );
+
+ if ( passwd == null )
+ {
+ Console cons;
+ char[] password;
+ if ( ( cons = System.console() ) != null
+ && ( password = cons.readPassword( "Password:" ) ) != null )
+ {
+ // Cipher uses Strings
+ passwd = String.copyValueOf( password );
+
+ // Sun/Oracle advises to empty the char array
+ java.util.Arrays.fill( password, ' ' );
+ }
+ }
String configurationFile = dispatcher.getConfigurationFile();