spring-projects / spring-integration-extensions

The Spring Integration Extensions project provides extension components for Spring Integration
http://www.springintegration.org/
279 stars 265 forks source link

smb MessageHandler not correctly serializing user/password #193

Closed gorille closed 6 years ago

gorille commented 6 years ago

Hi Folks,

I've just tried to use the spring integration smb extension to push files according to this post.

@Bean
public MessageHandler smbMessageHandler(SmbSessionFactory smbSessionFactory) {
    FileTransferringMessageHandler<SmbFile> 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;
}

I do fill in the user/password/doamin and when I launch the code, I get an error

Caused by: org.springframework.core.NestedIOException: Unable to initialize share: smb://user%3Apassword@hostname:445/test-seb; nested exception is jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad password.

Please do note the user%3Apassword , this comes from here

URLEncoder.encode(domainUserPass, "UTF8"); is basically encoding the : which is wrong. correct URL scheme should be smb://user:password@host:445 instead of smb://user%3Apassword@host:445

artembilan commented 6 years ago

Please, share with us how do you configure those user/password/doamin.

However It looks like would be better to use UriComponentsBuilder from Spring Web for encoding: https://docs.spring.io/spring/docs/5.0.6.RELEASE/spring-framework-reference/web.html#mvc-uri-building

gorille commented 6 years ago

I use the provided SmbSessionFactory as explained in the post.

SmbSessionFactory factory = new SmbSessionFactory()
factory.setUsername("user");
factory.setPassword("password");
...
... // and later in the code
FileTransferringMessageHandler<SmbFile> handler = new FileTransferringMessageHandler<> (factory );