davsclaus opened a new pull request, #30582: URL: https://github.com/apache/camel/pull/30582
## What was wrong [CAMEL-27367](https://issues.apache.org/jira/browse/CAMEL-27367): `SmbOperations.connectIfNecessary` called `configuration.getPassword().toCharArray()`, so an smb endpoint without a `password` failed with a `NullPointerException`. Without a `username`, smbj's `AuthenticationContext` failed with a `NullPointerException` too. ## The fix The credentials are built in `SmbOperations.createAuthenticationContext`: - **A username without a password** logs in with an empty password. The ftp component does the same (it passes the null password on), and so does sftp. So `username=Guest` without a password is a guest login, when the server allows guest access. - **No username** fails before connecting, with `Cannot connect to: host:port as no username is set. Set the username and password of the share, or username=Guest for guest access.` Why anonymous login is not offered, although the ftp component logs in as `anonymous` without a username: I tried smbj's `AuthenticationContext.anonymous()` against the Samba test container. smbj 0.15.0 fails in `SMBSessionBuilder.deriveKey` with `NullPointerException: Cannot invoke "javax.crypto.SecretKey.getEncoded()" because "derivationKey" is null` (SMB 3.1.1, the server accepts the anonymous session but smbj derives the signing key from a session key it does not have). That is not clean enough to offer, so a missing username is a clear error. If smbj fixes this, anonymous login can be added later. The smb component doc has a new "Login" section that says this (catalog doc copy updated). No option metadata changed. ## Tests - `SmbAuthenticationContextTest` (new, unit): username and password, username without password, `Guest` without password is a guest context, no or empty username fails with the message. 5 tests, pass. - `SmbNoPasswordIT` (new, Samba container): username without password, `Guest` without password, and no username all fail with a `GenericFileOperationFailedException` "Cannot connect to: ...". Before the fix, all three failed with a `NullPointerException`; after, 3 tests pass. - Full camel-smb suite with Docker: `mvn verify` in `components/camel-smb`: 31 unit tests and 89 ITs, all pass. Not tested: a real guest login (the test Samba server has no guest share, and changing the test-infra image was out of scope). _Claude Code on behalf of davsclaus_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
