change ftp password to string type
This commit is contained in:
parent
f189ccc4cf
commit
17feb07e94
5 changed files with 36 additions and 13 deletions
|
@ -734,8 +734,7 @@ public class FTPEnvironment implements Map<String, Object>, Cloneable {
|
||||||
}
|
}
|
||||||
|
|
||||||
String username = getUsername();
|
String username = getUsername();
|
||||||
char[] passwordChars = FileSystemProviderSupport.getValue(this, PASSWORD, char[].class, null);
|
String password = FileSystemProviderSupport.getValue(this, PASSWORD, String.class, null);
|
||||||
String password = passwordChars != null ? new String(passwordChars) : null;
|
|
||||||
String account = FileSystemProviderSupport.getValue(this, ACCOUNT, String.class, null);
|
String account = FileSystemProviderSupport.getValue(this, ACCOUNT, String.class, null);
|
||||||
if (account != null) {
|
if (account != null) {
|
||||||
if (!client.login(username, password, account)) {
|
if (!client.login(username, password, account)) {
|
||||||
|
|
|
@ -76,8 +76,11 @@ public class SftpFileSystem
|
||||||
private int writeBufferSize;
|
private int writeBufferSize;
|
||||||
private final List<FileStore> stores;
|
private final List<FileStore> stores;
|
||||||
|
|
||||||
public SftpFileSystem(SftpFileSystemProvider provider, String id, ClientSession session,
|
public SftpFileSystem(SftpFileSystemProvider provider,
|
||||||
SftpClientFactory factory, SftpVersionSelector selector) throws IOException {
|
String id,
|
||||||
|
ClientSession session,
|
||||||
|
SftpClientFactory factory,
|
||||||
|
SftpVersionSelector selector) throws IOException {
|
||||||
super(provider);
|
super(provider);
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.clientSession = Objects.requireNonNull(session, "No client session");
|
this.clientSession = Objects.requireNonNull(session, "No client session");
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.apache.sshd.fs;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.sshd.client.config.hosts.HostConfigEntry;
|
||||||
import org.apache.sshd.client.session.ClientSession;
|
import org.apache.sshd.client.session.ClientSession;
|
||||||
import org.apache.sshd.client.session.ClientSessionCreator;
|
import org.apache.sshd.client.session.ClientSessionCreator;
|
||||||
import org.apache.sshd.common.auth.PasswordHolder;
|
import org.apache.sshd.common.auth.PasswordHolder;
|
||||||
|
@ -50,13 +51,28 @@ public interface SftpFileSystemClientSessionInitializer {
|
||||||
* @return The created {@link ClientSession}
|
* @return The created {@link ClientSession}
|
||||||
* @throws IOException If failed to connect
|
* @throws IOException If failed to connect
|
||||||
*/
|
*/
|
||||||
default ClientSession createClientSession(
|
default ClientSession createClientSession(SftpFileSystemProvider provider,
|
||||||
SftpFileSystemProvider provider, SftpFileSystemInitializationContext context)
|
SftpFileSystemInitializationContext context)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
UsernameHolder user = context.getCredentials();
|
UsernameHolder user = context.getCredentials();
|
||||||
ClientSessionCreator client = provider.getClientInstance();
|
ClientSessionCreator client = provider.getClientInstance();
|
||||||
return client.connect(user.getUsername(), context.getHost(), context.getPort())
|
// proxy?
|
||||||
.verifyDuration(context.getMaxConnectTime()).getSession();
|
String proxy = (String) context.getEnvironment().get("proxy");
|
||||||
|
if (proxy != null) {
|
||||||
|
HostConfigEntry entry = new HostConfigEntry();
|
||||||
|
entry.setProxyJump(proxy);
|
||||||
|
entry.setUsername(user.getUsername());
|
||||||
|
entry.setHostName(context.getHost());
|
||||||
|
entry.setHost(context.getHost());
|
||||||
|
entry.setPort(context.getPort());
|
||||||
|
return client.connect(entry)
|
||||||
|
.verifyDuration(context.getMaxConnectTime())
|
||||||
|
.getSession();
|
||||||
|
} else {
|
||||||
|
return client.connect(user.getUsername(), context.getHost(), context.getPort())
|
||||||
|
.verifyDuration(context.getMaxConnectTime())
|
||||||
|
.getSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,9 +106,10 @@ public interface SftpFileSystemClientSessionInitializer {
|
||||||
* @return The created {@link SftpFileSystem}
|
* @return The created {@link SftpFileSystem}
|
||||||
* @throws IOException If failed to create the file-system
|
* @throws IOException If failed to create the file-system
|
||||||
*/
|
*/
|
||||||
default SftpFileSystem createSftpFileSystem(
|
default SftpFileSystem createSftpFileSystem(SftpFileSystemProvider provider,
|
||||||
SftpFileSystemProvider provider, SftpFileSystemInitializationContext context, ClientSession session,
|
SftpFileSystemInitializationContext context,
|
||||||
SftpVersionSelector selector)
|
ClientSession session,
|
||||||
|
SftpVersionSelector selector)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return new SftpFileSystem(provider, context.getId(), session, provider.getSftpClientFactory(), selector);
|
return new SftpFileSystem(provider, context.getId(), session, provider.getSftpClientFactory(), selector);
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,9 @@ public class SftpFileSystemProvider extends FileSystemProvider {
|
||||||
this(client, null, selector);
|
this(client, null, selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SftpFileSystemProvider(SshClient client, SftpClientFactory factory, SftpVersionSelector selector) {
|
public SftpFileSystemProvider(SshClient client,
|
||||||
|
SftpClientFactory factory,
|
||||||
|
SftpVersionSelector selector) {
|
||||||
this.factory = factory;
|
this.factory = factory;
|
||||||
this.versionSelector = selector;
|
this.versionSelector = selector;
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
|
|
|
@ -3,6 +3,8 @@ package org.apache.sshd.fs.test;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import org.apache.sshd.client.ClientBuilder;
|
import org.apache.sshd.client.ClientBuilder;
|
||||||
import org.apache.sshd.client.SshClient;
|
import org.apache.sshd.client.SshClient;
|
||||||
|
import org.apache.sshd.client.config.hosts.HostConfigEntry;
|
||||||
|
import org.apache.sshd.client.session.ClientSession;
|
||||||
import org.apache.sshd.fs.SftpFileSystem;
|
import org.apache.sshd.fs.SftpFileSystem;
|
||||||
import org.apache.sshd.fs.SftpFileSystemProvider;
|
import org.apache.sshd.fs.SftpFileSystemProvider;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -20,7 +22,7 @@ public class SFTPFileSystemTest {
|
||||||
private static final Logger logger = Logger.getLogger(SFTPFileSystemTest.class.getName());
|
private static final Logger logger = Logger.getLogger(SFTPFileSystemTest.class.getName());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void init() throws Exception {
|
public void testXbib() throws Exception {
|
||||||
Map<String, String> env = new HashMap<>();
|
Map<String, String> env = new HashMap<>();
|
||||||
env.put("username", "joerg");
|
env.put("username", "joerg");
|
||||||
URI uri = URI.create("sftp://xbib.org");
|
URI uri = URI.create("sftp://xbib.org");
|
||||||
|
|
Loading…
Reference in a new issue