Here's a follow up to my last email with a demo class / test case that
illustrates the failure.
Add this code to the apache-sshd/sshd-core project under
src/test/java/com/example
When you run the test the first case passes. It spins up a new Sshd/SFTP
server and connects to it with the JSch client, and authenticates just fine
with the user/pass obtained via the ConcurrentHashMap.
The second test case fails. It tries to connect multiple sessions with
different user/pass combos. You'll see the following printed on
system.err.println =>
First, we create a new session for foo=bar:
CREATE-SESSION: SftpServer identity:1190000432, authMap identity:822056113,
authMap:{foo=bar}, user:foo, pass:bar
Then we authenticate -- works ok, you'll see foo=bar is in the map
AUTHENTICATE: SftpServer identity:1526115339, authMap identity:2023306452,
authMap:{foo=bar}, user:foo, pass:bar
Now, we create a new session for foo2=bar2, note that it prints the contents of
the map after this call and it contains foo2=bar2
CREATE-SESSION: SftpServer identity:1190000432, authMap identity:822056113,
authMap:{foo2=bar2, foo=bar}, user:foo2, pass:bar2
Then we try to authenticate, but it fails. foo2=bar2 is not in the map, and
the identity hashcode is different.
AUTHENTICATE: SftpServer identity:1526115339, authMap identity:2023306452,
authMap:{foo=bar}, user:foo2, pass:bar2
Note that the identity hashcodes change between calls to createSession( ) in
the test, and authenticate( ) coming in from apache-sshd. If you look at the
code, you'll see that I don't manipulate the ConcurrentMap anywhere in the code
or the test case other than adding an entry to it, and it is a private final
instance variable.
So, why doesn't this work? Something in the mina code is using a stale
instance of the SftpServer.java class it seems?
Any ideas?
Regards,
Davis