Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Commit

Permalink
SONARSCSVN-9 Support SVN+SSH authentication using private key
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Feb 17, 2016
1 parent e8ef3ea commit b6bb7f4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/sonar/plugins/scm/svn/SvnBlameCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public void blame(final BlameInput input, final BlameOutput output) {
private void blame(SVNClientManager clientManager, FileSystem fs, InputFile inputFile, BlameOutput output) {
String filename = inputFile.relativePath();

LOG.debug("Annotate file {}", filename);

AnnotationHandler handler = new AnnotationHandler();
try {
SVNStatusClient statusClient = clientManager.getStatusClient();
Expand Down Expand Up @@ -112,10 +114,14 @@ public SVNClientManager getClientManager() {
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
String password = configuration.password();
final char[] passwordValue = password != null ? password.toCharArray() : null;
String passPhrase = configuration.passPhrase();
final char[] passPhraseValue = passPhrase != null ? passPhrase.toCharArray() : null;
ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(
null,
configuration.username(),
passwordValue,
configuration.privateKey(),
passPhraseValue,
false);
return SVNClientManager.newInstance(options, authManager);
}
Expand Down
37 changes: 33 additions & 4 deletions src/main/java/org/sonar/plugins/scm/svn/SvnConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
package org.sonar.plugins.scm.svn;

import com.google.common.collect.ImmutableList;
import java.io.File;
import java.util.List;
import javax.annotation.CheckForNull;
import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
import org.sonar.api.PropertyType;
Expand All @@ -28,16 +31,14 @@
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;

import javax.annotation.CheckForNull;

import java.util.List;

@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
public class SvnConfiguration implements BatchComponent {

private static final String CATEGORY_SVN = "SVN";
public static final String USER_PROP_KEY = "sonar.svn.username";
public static final String PRIVATE_KEY_PATH_PROP_KEY = "sonar.svn.privateKeyPath";
public static final String PASSWORD_PROP_KEY = "sonar.svn.password.secured";
public static final String PASSPHRASE_PROP_KEY = "sonar.svn.passphrase.secured";
private final Settings settings;

public SvnConfiguration(Settings settings) {
Expand All @@ -63,6 +64,24 @@ public static List<PropertyDefinition> getProperties() {
.category(CoreProperties.CATEGORY_SCM)
.subCategory(CATEGORY_SVN)
.index(1)
.build(),
PropertyDefinition.builder(PRIVATE_KEY_PATH_PROP_KEY)
.name("Path to private key file")
.description("Used only for SVN+SSH authentication")
.type(PropertyType.STRING)
.onQualifiers(Qualifiers.PROJECT)
.category(CoreProperties.CATEGORY_SCM)
.subCategory(CATEGORY_SVN)
.index(2)
.build(),
PropertyDefinition.builder(PASSPHRASE_PROP_KEY)
.name("Passphrase")
.description("Optional passphrase to be used for SVN+SSH authentication")
.type(PropertyType.PASSWORD)
.onQualifiers(Qualifiers.PROJECT)
.category(CoreProperties.CATEGORY_SCM)
.subCategory(CATEGORY_SVN)
.index(3)
.build());
}

Expand All @@ -76,4 +95,14 @@ public String password() {
return settings.getString(PASSWORD_PROP_KEY);
}

@CheckForNull
public File privateKey() {
return settings.hasKey(PRIVATE_KEY_PATH_PROP_KEY) ? new File(settings.getString(PRIVATE_KEY_PATH_PROP_KEY)) : null;
}

@CheckForNull
public String passPhrase() {
return settings.getString(PASSPHRASE_PROP_KEY);
}

}

0 comments on commit b6bb7f4

Please sign in to comment.