From 2f4877ac38789d0a0bfd7264c5dff09ae662253f Mon Sep 17 00:00:00 2001 From: Richard Li <742829+rli@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:28:23 -0800 Subject: [PATCH] Fix JSR310 serialization error when preparing login panel (#5216) If a user is somehow in the situtation where they have an `sso-session` defined, with a token in their SSO cache (either valid/invalid), then prepareBrowser fails since it tries to serialize the state of `connectionSettings` without the jackson-jsr310 module. When using the IDE normally, this should not be possible because logout destroys the existing token and there is a prior check to see if user should be shown the chat panel / re-auth flow instead of the login browser This is not intended behavior, so fix by configuring this to be an ignored field. --- ...ix-213273c1-12a5-47d1-b973-499d25e1d68e.json | 4 ++++ .../core/credentials/ToolkitConnectionImpls.kt | 3 +++ .../DefaultToolkitAuthManagerTest.kt | 17 +++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 .changes/next-release/bugfix-213273c1-12a5-47d1-b973-499d25e1d68e.json diff --git a/.changes/next-release/bugfix-213273c1-12a5-47d1-b973-499d25e1d68e.json b/.changes/next-release/bugfix-213273c1-12a5-47d1-b973-499d25e1d68e.json new file mode 100644 index 0000000000..a35b78228d --- /dev/null +++ b/.changes/next-release/bugfix-213273c1-12a5-47d1-b973-499d25e1d68e.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Fix issue where users are unable to login to Amazon Q if they have previously authenticated (#5214)" +} \ No newline at end of file diff --git a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitConnectionImpls.kt b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitConnectionImpls.kt index fb89054b5f..f7c85b05e6 100644 --- a/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitConnectionImpls.kt +++ b/plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/core/credentials/ToolkitConnectionImpls.kt @@ -3,6 +3,7 @@ package software.aws.toolkits.jetbrains.core.credentials +import com.fasterxml.jackson.annotation.JsonIgnore import com.intellij.openapi.Disposable import com.intellij.openapi.util.Disposer import software.aws.toolkits.core.TokenConnectionSettings @@ -73,6 +74,7 @@ sealed class ManagedBearerSsoConnection( region ) + @JsonIgnore override fun getConnectionSettings(): TokenConnectionSettings = provider override fun dispose() { @@ -99,6 +101,7 @@ class DetectedDiskSsoSessionConnection( region ) + @JsonIgnore override fun getConnectionSettings(): TokenConnectionSettings = provider override fun dispose() { diff --git a/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/DefaultToolkitAuthManagerTest.kt b/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/DefaultToolkitAuthManagerTest.kt index 3f5d496243..f63be201d7 100644 --- a/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/DefaultToolkitAuthManagerTest.kt +++ b/plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/DefaultToolkitAuthManagerTest.kt @@ -3,6 +3,7 @@ package software.aws.toolkits.jetbrains.core.credentials +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.testFramework.ProjectExtension @@ -453,6 +454,22 @@ class DefaultToolkitAuthManagerTest { } } + @Test + fun `serializing LegacyManagedBearerSsoConnection does not include connectionSettings`() { + val profile = ManagedSsoProfile("us-east-1", "startUrl000", listOf("scopes")) + val connection = sut.createConnection(profile) as LegacyManagedBearerSsoConnection + + assertThat(jacksonObjectMapper().writeValueAsString(connection)).doesNotContain("connectionSettings") + } + + @Test + fun `serializing ProfileSsoManagedBearerSsoConnection does not include connectionSettings`() { + val profile = UserConfigSsoSessionProfile("sessionName", "us-east-1", "startUrl000", listOf("scopes")) + val connection = sut.createConnection(profile) as ProfileSsoManagedBearerSsoConnection + + assertThat(jacksonObjectMapper().writeValueAsString(connection)).doesNotContain("connectionSettings") + } + private companion object { @ExtendWith(ProjectExtension::class) val projectRule = ProjectRule()