Remove deprecated key file interface

Change-Id: If66006b4ffbe194be2a06eb14e3409219192edcc
This commit is contained in:
Ray Milkey 2018-02-08 11:36:43 -08:00 committed by Thomas Vachuska
parent 640fedd7e6
commit d4b51c2651
2 changed files with 4 additions and 33 deletions

View File

@ -23,16 +23,15 @@ import org.onosproject.netconf.config.NetconfSshClientLib;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.io.File;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.OptionalInt; import java.util.OptionalInt;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/** /**
* Represents a Netconf device information. * Represents a Netconf device information.
*/ */
@ -46,9 +45,6 @@ public class NetconfDeviceInfo {
private IpAddress ipAddress; private IpAddress ipAddress;
private int port; private int port;
private char[] key; private char[] key;
//File keyFile @deprecated 1.9.0
@Deprecated
private File keyFile;
private Optional<NetconfSshClientLib> sshClientLib; private Optional<NetconfSshClientLib> sshClientLib;
private OptionalInt connectTimeoutSec; private OptionalInt connectTimeoutSec;
private OptionalInt replyTimeoutSec; private OptionalInt replyTimeoutSec;
@ -88,10 +84,6 @@ public class NetconfDeviceInfo {
* @param port the tcp port * @param port the tcp port
* @param keyString the string containing a DSA or RSA private key * @param keyString the string containing a DSA or RSA private key
* of the user in OpenSSH key format * of the user in OpenSSH key format
* <br>
* (Pre 1.9.0 behaviour: {@code keyString} can be file path
* to a file containing DSA or RSA private key of the user
* in OpenSSH key format)
*/ */
public NetconfDeviceInfo(String name, String password, IpAddress ipAddress, public NetconfDeviceInfo(String name, String password, IpAddress ipAddress,
int port, String keyString) { int port, String keyString) {
@ -103,7 +95,6 @@ public class NetconfDeviceInfo {
this.ipAddress = ipAddress; this.ipAddress = ipAddress;
this.port = port; this.port = port;
this.key = keyString.toCharArray(); this.key = keyString.toCharArray();
this.keyFile = new File(keyString);
this.sshClientLib = Optional.empty(); this.sshClientLib = Optional.empty();
this.connectTimeoutSec = OptionalInt.empty(); this.connectTimeoutSec = OptionalInt.empty();
this.replyTimeoutSec = OptionalInt.empty(); this.replyTimeoutSec = OptionalInt.empty();
@ -126,7 +117,6 @@ public class NetconfDeviceInfo {
if (netconfConfig.sshKey() != null && !netconfConfig.sshKey().isEmpty()) { if (netconfConfig.sshKey() != null && !netconfConfig.sshKey().isEmpty()) {
this.key = netconfConfig.sshKey().toCharArray(); this.key = netconfConfig.sshKey().toCharArray();
} }
this.keyFile = new File(netconfConfig.sshKey());
if (netconfConfig.sshClient().isPresent()) { if (netconfConfig.sshClient().isPresent()) {
this.sshClientLib = Optional.of(NetconfSshClientLib.getEnum(netconfConfig.sshClient().get())); this.sshClientLib = Optional.of(NetconfSshClientLib.getEnum(netconfConfig.sshClient().get()));
} else { } else {
@ -220,19 +210,6 @@ public class NetconfDeviceInfo {
return key; return key;
} }
/**
* Exposes the keyFile of the controller.
*
* @return File object pointing to a file containing a DSA or RSA
* private key of the user in OpenSSH key format,
* or null if device is not configured to use public key authentication
* @deprecated 1.9.0
*/
@Deprecated
public File getKeyFile() {
return keyFile;
}
/** /**
* Exposes the Client library implementation. * Exposes the Client library implementation.
* *

View File

@ -184,13 +184,7 @@ public class NetconfSessionImpl implements NetconfSession {
} }
boolean isAuthenticated; boolean isAuthenticated;
try { try {
if (deviceInfo.getKeyFile() != null && deviceInfo.getKeyFile().canRead()) { if (deviceInfo.getKey() != null) {
log.debug("Authenticating with key file to device {} with username {}",
deviceInfo.getDeviceId(), deviceInfo.name());
isAuthenticated = netconfConnection.authenticateWithPublicKey(
deviceInfo.name(), deviceInfo.getKeyFile(),
deviceInfo.password().equals("") ? null : deviceInfo.password());
} else if (deviceInfo.getKey() != null) {
log.debug("Authenticating with key to device {} with username {}", log.debug("Authenticating with key to device {} with username {}",
deviceInfo.getDeviceId(), deviceInfo.name()); deviceInfo.getDeviceId(), deviceInfo.name());
isAuthenticated = netconfConnection.authenticateWithPublicKey( isAuthenticated = netconfConnection.authenticateWithPublicKey(