[settings-sync] IJPL-199443: extract performLogout to JBAccountInfoService

(cherry picked from commit b56188fafbab3f0141fd3dbcf252f5f6571c2511)

IJ-CR-176391

GitOrigin-RevId: fe605f32a3fe103321c28c6407bbe0ff77f2152d
This commit is contained in:
Aleksandra Olemskaia
2025-09-16 14:45:56 +02:00
committed by intellij-monorepo-bot
parent 0c4bd76b9e
commit d9d1ba79fb
5 changed files with 30 additions and 14 deletions

View File

@@ -124,6 +124,11 @@ public interface JBAccountInfoService {
@Nullable String authProviderId,
@NotNull Map<@NotNull String, @NotNull String> clientMetadata);
/**
* Performs the logout action by clearing stored authentication data.
*/
@NotNull CompletableFuture<LogoutResult> performLogout();
/**
* Returns the list of licenses available in the current user's account matching the specified productCode.
* <p>
@@ -231,6 +236,11 @@ public interface JBAccountInfoService {
record LoginFailed(@NlsSafe @NotNull String errorMessage) implements LoginResult { }
}
sealed interface LogoutResult permits LogoutResult.LogoutSuccessful, LogoutResult.LogoutFailed {
record LogoutSuccessful() implements LogoutResult { }
record LogoutFailed(@NlsSafe @NotNull String errorMessage) implements LogoutResult { }
}
record JbaLicense(
@NlsSafe @NotNull String licenseId,
@NotNull String jbaUserId,

View File

@@ -59,7 +59,6 @@ jvm_library(
"@lib//:mockito",
"//platform/util/progress",
"@lib//:kotlinx-coroutines-test",
"//licenseCommon:commercial-license",
],
runtime_deps = [":settingsSync_resources"]
)

View File

@@ -26,6 +26,5 @@
<orderEntry type="library" scope="TEST" name="mockito" level="project" />
<orderEntry type="module" module-name="intellij.platform.util.progress" />
<orderEntry type="library" scope="TEST" name="kotlinx-coroutines-test" level="project" />
<orderEntry type="module" module-name="intellij.platform.commercial.license" />
</component>
</module>

View File

@@ -33,6 +33,10 @@ object DummyJBAccountInfoService : JBAccountInfoService {
}
}
override fun performLogout(): CompletableFuture<JBAccountInfoService.LogoutResult?> {
TODO("Not yet implemented")
}
override fun getAvailableLicenses(productCode: String): CompletableFuture<JBAccountInfoService.LicenseListResult> {
TODO("Not yet implemented")
}

View File

@@ -2,11 +2,6 @@ package com.intellij.settingsSync.jba.auth
import com.intellij.CommonBundle
import com.intellij.icons.AllIcons
import com.intellij.ide.license.LicenseManager
import com.intellij.ide.license.impl.AuthClientContext
import com.intellij.ide.license.impl.AuthManagerHolder.getJBAManager
import com.intellij.ide.license.login.LicenseModelLoginManagerImpl
import com.intellij.ide.license.login.LoginManager
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.idea.AppMode
import com.intellij.openapi.actionSystem.*
@@ -228,7 +223,7 @@ internal class JBAAuthService(private val cs: CoroutineScope) : SettingsSyncAuth
if (ApplicationManagerEx.isInIntegrationTest() || System.getProperty("settings.sync.test.auth") == "true") {
return DummyJBAccountInfoService
}
var instance = JBAccountInfoService.getInstance()
val instance = JBAccountInfoService.getInstance()
if (instance == null && !AppMode.isRemoteDevHost()) {
LOG.info("Attempting to load info service from plugin...")
val descriptorImpl = PluginManagerCore.findPlugin(PluginId.getId("com.intellij.marketplace")) ?: return null
@@ -240,8 +235,7 @@ internal class JBAAuthService(private val cs: CoroutineScope) : SettingsSyncAuth
}
private fun getAllProductCodes(): Set<String> {
val ideProductCode = LicenseManager.getInstance().platformLicenseInfo.productDescriptor.productCode
return PluginManagerCore.loadedPlugins.mapNotNullTo(mutableSetOf(ideProductCode)) { it.getProductCode() }
return PluginManagerCore.loadedPlugins.mapNotNullTo(mutableSetOf()) { it.getProductCode() }
}
private suspend fun shouldShowCheckLicenses(): Boolean = coroutineScope {
@@ -295,14 +289,24 @@ internal class JBAAuthService(private val cs: CoroutineScope) : SettingsSyncAuth
val dialog = ConfirmLogoutDialog(component, shouldShowCheckLicenses)
if (dialog.showAndGet()) {
performLogout()
performLogout(component)
}
}
}
private fun performLogout() {
val loginManager: LoginManager = LicenseModelLoginManagerImpl(getJBAManager(), AuthClientContext.OTHER)
loginManager.initiateLogout()
private fun performLogout(component: Component) {
if (RemoteCommunicatorHolder.getExternalProviders().isEmpty())
return
val accountInfoService = getAccountInfoService()
if (accountInfoService != null) {
if (AppMode.isRemoteDevHost()) {
showManageLicensesDialog(component)
}
accountInfoService.performLogout()
}
else {
LOG.error("JBA auth service is not available!")
}
}
internal var authRequiredAction: SettingsSyncAuthService.PendingUserAction? = null