Repository: maven-scm Updated Branches: refs/heads/master 860a2eeae -> 1fd6136ed
#resolves SCM-811 by masking command output in ScmResult class used by all SCM operations Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/8785b85e Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/8785b85e Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/8785b85e Branch: refs/heads/master Commit: 8785b85e0d6273f88e7bd173c5d59d0e2c1148c2 Parents: 5c303e4 Author: EDWARD WEBB <edward.w...@libertymutual.com> Authored: Sat Feb 6 09:58:36 2016 -0500 Committer: EDWARD WEBB <edward.w...@libertymutual.com> Committed: Sat Feb 6 09:58:36 2016 -0500 ---------------------------------------------------------------------- .../java/org/apache/maven/scm/ScmResult.java | 30 ++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-scm/blob/8785b85e/maven-scm-api/src/main/java/org/apache/maven/scm/ScmResult.java ---------------------------------------------------------------------- diff --git a/maven-scm-api/src/main/java/org/apache/maven/scm/ScmResult.java b/maven-scm-api/src/main/java/org/apache/maven/scm/ScmResult.java index 61c77d4..ace98d9 100644 --- a/maven-scm-api/src/main/java/org/apache/maven/scm/ScmResult.java +++ b/maven-scm-api/src/main/java/org/apache/maven/scm/ScmResult.java @@ -20,6 +20,8 @@ package org.apache.maven.scm; */ import java.io.Serializable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author <a href="mailto:tryg...@inamo.no">Trygve Laugstøl</a> @@ -38,6 +40,12 @@ public class ScmResult private final String commandLine; + + public static final String PASSWORD_PLACE_HOLDER = "********"; + + //works for SVN and git + private Pattern patternForUserColonPasswordAtHost = Pattern.compile( "^.*:(.*)@.*$" ); + /** * Copy constructor. * <p/> @@ -52,11 +60,12 @@ public class ScmResult this.providerMessage = scmResult.providerMessage; - this.commandOutput = scmResult.commandOutput; + this.commandOutput = masked( scmResult.commandOutput ); this.success = scmResult.success; } + /** * ScmResult contructor. * @@ -71,7 +80,7 @@ public class ScmResult this.providerMessage = providerMessage; - this.commandOutput = commandOutput; + this.commandOutput = masked( commandOutput ); this.success = success; } @@ -109,4 +118,21 @@ public class ScmResult { return commandLine; } + + + private String masked( String commandOutput ) + { + if ( null != commandOutput ) + { + final Matcher passwordMatcher = patternForUserColonPasswordAtHost.matcher( commandOutput ); + if ( passwordMatcher.find() ) + { + // clear password + final String clearPassword = passwordMatcher.group( 1 ); + // to be replaced in output by stars + commandOutput = commandOutput.replace( clearPassword, PASSWORD_PLACE_HOLDER ); + } + } + return commandOutput; + } }