diff --git a/spring-integration-smb/README.md b/spring-integration-smb/README.md index a72568c..f28e586 100644 --- a/spring-integration-smb/README.md +++ b/spring-integration-smb/README.md @@ -3,7 +3,7 @@ Spring Integration SMB Support ## Introduction -This module add Spring Integration support for [Server Message Block][] (SMB). +This module adds Spring Integration support for [Server Message Block][] (SMB). [Server Message Block]: https://en.wikipedia.org/wiki/Server_Message_Block @@ -23,9 +23,13 @@ Put the following block into pom.xml if using Maven: ## Changes +##### Version 1.1 * Updated to use the latest version of the [JCIFS](https://github.com/codelibs/jcifs) library * SMB2 (2.02 protocol level) support, some SMB3 support +##### Version 1.2 + * Ability to set the SMB min/max versions in the `SmbSessionFactory` via configuration in the JCIFS library + ## Overview The Java CIFS Client Library has been chosen as a Java implementation for the CIFS/SMB networking protocol. @@ -46,15 +50,37 @@ For XML configuration the `` component is provi There is no (yet) some SMB specific requirements for files transferring to SMB, so for XML `` component we simply reuse an existing `FileTransferringMessageHandler`. In case of Java configuration that `FileTransferringMessageHandler` should be supplied with the `SmbSessionFactory` (or `SmbRemoteFileTemplate`). - @ServiceActivator(inputChannel = "storeToSmb") - @Bean - public MessageHandler smbMessageHandler(SmbSessionFactory smbSessionFactory) { - FileTransferringMessageHandler handler = - new FileTransferringMessageHandler<>(smbSessionFactory); - handler.setRemoteDirectoryExpression( - new LiteralExpression("remote-target-dir")); - handler.setFileNameGenerator(m -> - m.getHeaders().get(FileHeaders.FILENAME, String.class) + ".test"); - handler.setAutoCreateDirectory(true); - return handler; - } +````java +@ServiceActivator(inputChannel = "storeToSmb") +@Bean +public MessageHandler smbMessageHandler(SmbSessionFactory smbSessionFactory) { + FileTransferringMessageHandler handler = + new FileTransferringMessageHandler<>(smbSessionFactory); + handler.setRemoteDirectoryExpression( + new LiteralExpression("remote-target-dir")); + handler.setFileNameGenerator(m -> + m.getHeaders().get(FileHeaders.FILENAME, String.class) + ".test"); + handler.setAutoCreateDirectory(true); + return handler; +} +```` + +### Setting SMB Protocol Min/Max Versions + +Example: To set a minimum version of SMB 2.1 and a maximum version of SMB 3.1.1 + +````java +@Bean +public SmbSessionFactory smbSessionFactory() { + SmbSessionFactory smbSession = new SmbSessionFactory(); + smbSession.setHost("myHost"); + smbSession.setPort(445); + smbSession.setDomain("myDomain"); + smbSession.setUsername("myUser"); + smbSession.setPassword("myPassword"); + smbSession.setShareAndDir("myShareAndDir"); + smbSession.setSmbMinVersion(DialectVersion.SMB210); + smbSession.setSmbMaxVersion(DialectVersion.SMB311); + return smbSession; +} +```` diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java index e807b81..772790b 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ import java.net.URISyntaxException; import org.springframework.util.Assert; import org.springframework.util.StringUtils; +import jcifs.DialectVersion; + /** * Data holder class for a SMB share configuration. * @@ -31,8 +33,7 @@ import org.springframework.util.StringUtils; * @author Markus Spann * @author Prafull Kumar Soni * @author Artem Bilan - * - * @since 1.0 + * @author Gregory Bragg */ public class SmbConfig { @@ -52,6 +53,18 @@ public class SmbConfig { private boolean useTempFile = false; + /** + * Defaults to and follows the jCIFS library default of 'SMB1' + * @since 1.2 + */ + private DialectVersion smbMinVersion = DialectVersion.SMB1; + + /** + * Defaults to and follows the jCIFS library default of 'SMB210' + * @since 1.2 + */ + private DialectVersion smbMaxVersion = DialectVersion.SMB210; + public SmbConfig() { } @@ -134,6 +147,46 @@ public class SmbConfig { return this.useTempFile; } + /** + * Gets the desired minimum SMB version value for what the Windows server will allow + * during protocol transport negotiation. + * @return one of SMB1, SMB202, SMB210, SMB300, SMB302 or SMB311 + * @since 1.2 + */ + public DialectVersion getSmbMinVersion() { + return this.smbMinVersion; + } + + /** + * Sets the desired minimum SMB version value for what the Windows server will allow + * during protocol transport negotiation. + * @param _smbMinVersion one of SMB1, SMB202, SMB210, SMB300, SMB302 or SMB311 + * @since 1.2 + */ + public void setSmbMinVersion(DialectVersion _smbMinVersion) { + this.smbMinVersion = _smbMinVersion; + } + + /** + * Gets the desired maximum SMB version value for what the Windows server will allow + * during protocol transport negotiation. + * @return one of SMB1, SMB202, SMB210, SMB300, SMB302 or SMB311 + * @since 1.2 + */ + public DialectVersion getSmbMaxVersion() { + return this.smbMaxVersion; + } + + /** + * Sets the desired maximum SMB version value for what the Windows server will allow + * during protocol transport negotiation. + * @param _smbMaxVersion one of SMB1, SMB202, SMB210, SMB300, SMB302 or SMB311 + * @since 1.2 + */ + public void setSmbMaxVersion(DialectVersion _smbMaxVersion) { + this.smbMaxVersion = _smbMaxVersion; + } + String getDomainUserPass(boolean _includePassword) { String domainUserPass; if (StringUtils.hasText(this.domain)) { diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java index 69202b2..066a74e 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.integration.smb.session; import java.io.IOException; +import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -29,7 +30,7 @@ import jcifs.smb.SmbFile; * The SMB session factory. * * @author Markus Spann - * @since 1.0 + * @author Gregory Bragg */ public class SmbSessionFactory extends SmbConfig implements SessionFactory { @@ -39,6 +40,7 @@ public class SmbSessionFactory extends SmbConfig implements SessionFactory