From 3a53a3caf24fc041c27982120ea4b769d5923653 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sat, 30 Oct 2010 21:42:14 +0000 Subject: [PATCH] [MNG-4877] Regression: Deploy to SCP with privateKey fails - privateKey and passphrase gets lost git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1029208 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/repository/Authentication.java | 49 ++++++++++++++++++- .../legacy/LegacyRepositorySystem.java | 7 ++- .../org/apache/maven/RepositoryUtils.java | 3 +- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java index 307946fad9..ff28907b39 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/Authentication.java @@ -20,7 +20,12 @@ package org.apache.maven.artifact.repository; */ public class Authentication -{ +{ + + private String privateKey; + + private String passphrase; + public Authentication( String userName, String password ) { this.username = userName; @@ -76,4 +81,46 @@ public class Authentication { this.username = userName; } + + /** + * Get the passphrase of the private key file. The passphrase is used only when host/protocol supports + * authentication via exchange of private/public keys and private key was used for authentication. + * + * @return passphrase of the private key file + */ + public String getPassphrase() + { + return passphrase; + } + + /** + * Set the passphrase of the private key file. + * + * @param passphrase passphrase of the private key file + */ + public void setPassphrase( final String passphrase ) + { + this.passphrase = passphrase; + } + + /** + * Get the absolute path to the private key file. + * + * @return absolute path to private key + */ + public String getPrivateKey() + { + return privateKey; + } + + /** + * Set the absolute path to private key file. + * + * @param privateKey path to private key in local file system + */ + public void setPrivateKey( final String privateKey ) + { + this.privateKey = privateKey; + } + } diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java index 91dc3b6c76..ef2707a79f 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/LegacyRepositorySystem.java @@ -550,6 +550,8 @@ public class LegacyRepositorySystem } Authentication authentication = new Authentication( server.getUsername(), server.getPassword() ); + authentication.setPrivateKey( server.getPrivateKey() ); + authentication.setPassphrase( server.getPassphrase() ); repository.setAuthentication( authentication ); } @@ -572,7 +574,10 @@ public class LegacyRepositorySystem selector.getAuthentication( RepositoryUtils.toRepo( repository ) ); if ( auth != null ) { - return new Authentication( auth.getUsername(), auth.getPassword() ); + Authentication result = new Authentication( auth.getUsername(), auth.getPassword() ); + result.setPrivateKey( auth.getPrivateKeyFile() ); + result.setPassphrase( auth.getPassphrase() ); + return result; } } } diff --git a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java index 7c7671d216..ee3f0efa42 100644 --- a/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java +++ b/maven-core/src/main/java/org/apache/maven/RepositoryUtils.java @@ -221,7 +221,8 @@ public class RepositoryUtils Authentication result = null; if ( auth != null ) { - result = new Authentication( auth.getUsername(), auth.getPassword() ); + result = + new Authentication( auth.getUsername(), auth.getPassword(), auth.getPrivateKey(), auth.getPassphrase() ); } return result; }