Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/upgrade to sftp6 #218

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jrcc-access-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-document-api</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
6 changes: 3 additions & 3 deletions jrcc-access-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-access-spring-boot-autoconfigure</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<name>jrcc-access-spring-boot-autoconfigure</name>
<description>Demo project for Spring Boot</description>

Expand Down Expand Up @@ -100,12 +100,12 @@
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-document-access-libs</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-document-api</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,28 @@ public class AutoConfiguration {

public AutoConfiguration(SftpInputProperties sftpInputProperties) {
this.properties = sftpInputProperties;
logger.info("SFTP Configuration: Host => [{}]", this.properties.getHost());
logger.info("SFTP Configuration: Port => [{}]", this.properties.getPort());
logger.info("SFTP Configuration: Username => [{}]", this.properties.getUsername());
logger.info("SFTP Configuration: Remote Directory => [{}]", this.properties.getRemoteDirectory());
logger.info("SFTP Configuration: Filter Pattern => [{}]", this.properties.getFilterPattern());
logger.info("SFTP Configuration: Cron => [{}]", this.properties.getCron());
logger.info("SFTP Configuration: Max Message Per Poll => [{}]", this.properties.getMaxMessagePerPoll());
logger.info("SFTP Configuration: Known Host File => [{}]", this.properties.getKnownHostFile());
logger.debug("SFTP Configuration: Host => [{}]", this.properties.getHost());
logger.debug("SFTP Configuration: Port => [{}]", this.properties.getPort());
logger.debug("SFTP Configuration: Username => [{}]", this.properties.getUsername());
logger.debug("SFTP Configuration: Remote Directory => [{}]", this.properties.getRemoteDirectory());
logger.debug("SFTP Configuration: Filter Pattern => [{}]", this.properties.getFilterPattern());
logger.debug("SFTP Configuration: Cron => [{}]", this.properties.getCron());
logger.debug("SFTP Configuration: Max Message Per Poll => [{}]", this.properties.getMaxMessagePerPoll());
logger.debug("SFTP Configuration: Known Host File => [{}]", this.properties.getKnownHostFile());
}

@Bean
public SessionFactory<SftpClient.DirEntry> sftpSessionFactory() throws InvalidConfigException, IOException {


SshClient sshClient = SshClient.setUpDefaultClient();
sshClient.setKeyExchangeFactories(NamedFactory.setUpTransformedFactories(
false,
BuiltinDHFactories.VALUES,
ClientBuilder.DH2KEX
));

boolean isAllowUnknownKeys = properties.isAllowUnknownKeys();

sshClient.setSignatureFactories(new ArrayList<>(BuiltinSignatures.VALUES));

boolean isAllowUnknownKeys = properties.isAllowUnknownKeys();
ServerKeyVerifier serverKeyVerifier =
isAllowUnknownKeys ? AcceptAllServerKeyVerifier.INSTANCE : RejectAllServerKeyVerifier.INSTANCE;

Expand All @@ -108,11 +105,7 @@ public SessionFactory<SftpClient.DirEntry> sftpSessionFactory() throws InvalidCo
if (!knownHostFile.exists())
throw new KnownHostFileNotFoundException("Cannot find known_hosts file when allow-unknown-keys is false.");

logger.info("SFTP Known Hosts");
Resource resource = resourceLoader.getResource("file:"+properties.getKnownHostFile());
logger.info("SFTP Known Hosts: length = {}", resource.contentLength());
logger.info("SFTP Known Hosts: content = {}", resource.getContentAsString(Charset.defaultCharset()));

serverKeyVerifier = new ResourceKnownHostsServerKeyVerifier(resource);
}

Expand All @@ -123,10 +116,7 @@ public SessionFactory<SftpClient.DirEntry> sftpSessionFactory() throws InvalidCo
if(!(new File(properties.getSshPrivateKey()).exists()))
throw new KnownHostFileNotDefinedException("Cannot find known_hosts file private key file. ");

logger.info("SFTP Configuration: setPrivateKey");
Resource resource = resourceLoader.getResource("file:"+properties.getSshPrivateKey());;
logger.info("SFTP Configuration: privateKey - length {}", resource.contentLength());
logger.info("SFTP Configuration: privateKey - content {}", resource.getContentAsString(Charset.defaultCharset()));

IoResource<Resource> privateKeyResource =
new AbstractIoResource<>(Resource.class, resource) {
Expand Down Expand Up @@ -155,9 +145,7 @@ public InputStream openInputStream() throws IOException {
factory.setPort(properties.getPort());
factory.setUser(properties.getUsername());

CachingSessionFactory<SftpClient.DirEntry> cachingSessionFactory = new CachingSessionFactory<>(factory);
this.properties.getServerAliveInterval().ifPresent(timeout -> cachingSessionFactory.setSessionWaitTimeout(timeout));
return cachingSessionFactory;
return factory;
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ public void setMaxMessagePerPoll(String maxMessagePerPoll) {
}

public String getSshPrivateKey() {
logger.info("getSshPrivateKey sshPrivateKey = {}", this.sshPrivateKey);
logger.info("getSshPrivateKey from System.getenv(SSH_PRIVATE_KEY): {}", System.getenv("SSH_PRIVATE_KEY"));
logger.info("getSshPrivateKey from System.getenv(SFTP_HOST): {}", System.getenv("SFTP_HOST"));
logger.info("getSshPrivateKey from System.getenv(SFTP_KNOWN_HOST_FILE): {}", System.getenv("SFTP_KNOWN_HOST_FILE"));
if (StringUtils.isBlank(this.sshPrivateKey)) { logger.info("getSshPrivateKey return null"); return null;}
logger.info("getSshPrivateKey return not null {}", this.sshPrivateKey);
return this.sshPrivateKey;
}

Expand Down
4 changes: 2 additions & 2 deletions jrcc-access-spring-boot-sample-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-access-spring-boot-sample-app</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<name>jrcc-access-spring-boot-sample-app</name>
<description>Demo project for Spring Boot</description>

Expand All @@ -37,7 +37,7 @@
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-access-spring-boot-starter</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>

</dependencies>
Expand Down
6 changes: 3 additions & 3 deletions jrcc-access-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-access-spring-boot-starter</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<name>jrcc-access-spring-boot-starter</name>
<description>Demo project for Spring Boot</description>

Expand All @@ -38,7 +38,7 @@
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-access-spring-boot-autoconfigure</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
Expand All @@ -47,7 +47,7 @@
<dependency>
<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-document-access-libs</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions jrcc-document-access-libs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<parent>
<groupId>ca.bc.gov.open</groupId>
<artifactId>document-access</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
</parent>


<groupId>ca.bc.gov.open</groupId>
<artifactId>jrcc-document-access-libs</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>
<packaging>jar</packaging>

<name>jrcc-document-access-libs</name>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ca.bc.gov.open</groupId>
<artifactId>document-access</artifactId>
<version>1.3.2</version>
<version>1.3.3</version>

<name>document-access</name>
<packaging>pom</packaging>
Expand Down
Loading