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 27de4cef6c..22fe581ae4 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-2022 the original author or authors. + * Copyright 2012-2024 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. @@ -25,7 +25,7 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * Data holder class for a SMB share configuration. + * Data holder class for an SMB share configuration. *
* SmbFile URLs syntax:
* smb://[[[domain;]username[:password]@]server[:port]/[[share/[dir/]file]]][?[param=value[param2=value2[...]]]
@@ -197,22 +197,50 @@ public class SmbConfig {
}
public final String getUrl(boolean _includePassword) {
- String domainUserPass = getDomainUserPass(_includePassword);
+ return createUri(_includePassword).toASCIIString();
+ }
+ /**
+ * Return the url string for the share connection without encoding.
+ * Used in the {@link SmbShare} constructor delegation.
+ * @return the url string for the share connection without encoding.
+ * @since 6.3.8
+ */
+ public final String rawUrl() {
+ return rawUrl(true);
+ }
+
+ /**
+ * Return the url string for the share connection without encoding.
+ * Used in the {@link SmbShare} constructor delegation.
+ * @param _includePassword whether password has to be masked in credentials of URL.
+ * @return the url string for the share connection without encoding.
+ * @since 6.3.8
+ */
+ public final String rawUrl(boolean _includePassword) {
+ String domainUserPass = getDomainUserPass(_includePassword);
+ String path = cleanPath();
+ return "smb://%s@%s%s".formatted(domainUserPass, getHostPort(), path);
+ }
+
+ private URI createUri(boolean _includePassword) {
+ String domainUserPass = getDomainUserPass(_includePassword);
+ String path = cleanPath();
+ try {
+ return new URI("smb", domainUserPass, this.host, this.port, path, null, null);
+ }
+ catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ private String cleanPath() {
String path = StringUtils.cleanPath(this.shareAndDir);
if (!path.startsWith("/")) {
path = "/" + path;
}
-
- try {
- return new URI("smb", domainUserPass, this.host, this.port, path, null, null)
- .toASCIIString();
- }
- catch (URISyntaxException e) {
- throw new IllegalArgumentException(e);
- }
-
+ return path;
}
@Override
diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbShare.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbShare.java
index d287a481e1..f96102937e 100644
--- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbShare.java
+++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbShare.java
@@ -63,7 +63,7 @@ public class SmbShare extends SmbFile {
* @throws IOException if an invalid SMB URL was constructed by jCIFS
*/
public SmbShare(SmbConfig _smbConfig) throws IOException {
- super(StringUtils.cleanPath(_smbConfig.validate().getUrl()),
+ super(StringUtils.cleanPath(_smbConfig.validate().rawUrl()),
SingletonContext.getInstance().withCredentials(
new NtlmPasswordAuthenticator(
_smbConfig.getDomain(), _smbConfig.getUsername(), _smbConfig.getPassword())));
@@ -76,7 +76,7 @@ public class SmbShare extends SmbFile {
* @throws IOException if an invalid SMB URL was constructed by jCIFS
*/
public SmbShare(SmbConfig _smbConfig, CIFSContext _context) throws IOException {
- super(StringUtils.cleanPath(_smbConfig.validate().getUrl()), _context);
+ super(StringUtils.cleanPath(_smbConfig.validate().rawUrl()), _context);
}
/**
@@ -88,7 +88,7 @@ public class SmbShare extends SmbFile {
* @throws IOException if an invalid property was set or an invalid SMB URL was constructed by jCIFS
*/
public SmbShare(SmbConfig _smbConfig, Properties _props) throws IOException {
- super(StringUtils.cleanPath(_smbConfig.validate().getUrl()),
+ super(StringUtils.cleanPath(_smbConfig.validate().rawUrl()),
new BaseContext(
new PropertyConfiguration(_props)).withCredentials(
new NtlmPasswordAuthenticator(
diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests-context.xml b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests-context.xml
index 9c9bf00a91..ecda2bf347 100644
--- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests-context.xml
+++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests-context.xml
@@ -1,30 +1,31 @@