[WAGON-491] Add ability to set certificate via byte[] and not only via file
diff --git a/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java b/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java
index 6e92717..60d5708 100644
--- a/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java
+++ b/wagon-provider-api/src/main/java/org/apache/maven/wagon/authentication/AuthenticationInfo.java
@@ -43,7 +43,7 @@
private String password;
/**
- * Passphrase of the user's private key file
+ * Passphrase of the user's private key
*/
private String passphrase;
@@ -53,11 +53,16 @@
private String privateKey;
/**
- * Get the passphrase of the private key file. The passphrase is used only
+ * The private key file content (if key is in a package like JAR, WAR, ...)
+ */
+ private byte[] privateKeyContent;
+
+ /**
+ * Get the passphrase of the private key. 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
+ * @return passphrase of the private key
*/
public String getPassphrase()
{
@@ -65,9 +70,9 @@
}
/**
- * Set the passphrase of the private key file.
+ * Set the passphrase of the private key.
*
- * @param passphrase passphrase of the private key file
+ * @param passphrase passphrase of the private key
*/
public void setPassphrase( final String passphrase )
{
@@ -95,6 +100,26 @@
}
/**
+ * Get the private key content.
+ *
+ * @return private key content
+ */
+ public byte[] getPrivateKeyContent()
+ {
+ return privateKeyContent;
+ }
+
+ /**
+ * Set private key content.
+ *
+ * @param privateKeyContent private key content
+ */
+ public void setPrivateKeyContent( final byte[] privateKeyContent )
+ {
+ this.privateKeyContent = privateKeyContent;
+ }
+
+ /**
* Get the user's password which is used when connecting to the repository.
*
* @return password of user
diff --git a/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java b/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
index 7e87d2d..cc00ba7 100644
--- a/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
+++ b/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
@@ -27,6 +27,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Properties;
@@ -148,6 +149,19 @@
throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
}
}
+ else if ( authenticationInfo.getPrivateKeyContent() != null )
+ {
+ fireSessionDebug( "Using private key content" );
+ try
+ {
+ sch.addIdentity( null, authenticationInfo.getPrivateKeyContent(), null,
+ authenticationInfo.getPassphrase().getBytes( StandardCharsets.UTF_8 ) );
+ }
+ catch ( JSchException e )
+ {
+ throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage(), e );
+ }
+ }
else
{
try