From fa59869f2c8a9fa6e8540dd2846af0db3c9a2b7c Mon Sep 17 00:00:00 2001 From: hstyi Date: Mon, 9 Jun 2025 09:47:00 +0800 Subject: [PATCH] fix: authentication username not being saved (#622) --- src/main/kotlin/app/termora/SshClients.kt | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/app/termora/SshClients.kt b/src/main/kotlin/app/termora/SshClients.kt index b4d99ba..8b128f6 100644 --- a/src/main/kotlin/app/termora/SshClients.kt +++ b/src/main/kotlin/app/termora/SshClients.kt @@ -265,9 +265,14 @@ object SshClients { } catch (e: Exception) { if (e !is SshException || e.disconnectCode != SshConstants.SSH2_DISCONNECT_NO_MORE_AUTH_METHODS_AVAILABLE) throw e val owner = client.properties["owner"] as Window? ?: throw e - val authentication = ask(host, entry, owner) ?: throw e - if (authentication.type == AuthenticationType.No) throw e - return doOpenSession(host.copy(authentication = authentication), client) + val askUserInfo = ask(host, entry, owner) ?: throw e + if (askUserInfo.authentication.type == AuthenticationType.No) throw e + return doOpenSession( + host.copy( + authentication = askUserInfo.authentication, + username = askUserInfo.username + ), client + ) } session.setAttribute(HOST_KEY, host) @@ -414,12 +419,18 @@ object SshClients { return sshClient } - private fun ask(host: Host, entry: HostConfigEntry, owner: Window): Authentication? { - val ref = AtomicReference(null) + + private data class AskUserInfo(val username: String, val authentication: Authentication) + + private fun ask(host: Host, entry: HostConfigEntry, owner: Window): AskUserInfo? { + val ref = AtomicReference(null) + SwingUtilities.invokeAndWait { val dialog = RequestAuthenticationDialog(owner, host) dialog.setLocationRelativeTo(owner) - val authentication = dialog.getAuthentication().apply { ref.set(this) } + val authentication = dialog.getAuthentication() + ref.set(AskUserInfo(dialog.getUsername(), authentication)) + // save if (dialog.isRemembered()) { // fix https://github.com/TermoraDev/termora/issues/609