diff --git a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/IRebindModulesSyncService.kt b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/IRebindModulesSyncService.kt index 77d69c81..d19708c1 100644 --- a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/IRebindModulesSyncService.kt +++ b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/IRebindModulesSyncService.kt @@ -21,12 +21,12 @@ interface IRebindModulesSyncService { * Creates a connection to the model server. Do not forget to close the created client after use. * * @param serverURL the model server URL - * @param jwt the JWT auth token + * @param authProvider a function that generates a JWT token that can be used for auth * * @return the model client that is connected to the model server */ @Throws(IOException::class) - fun connectModelServer(serverURL: String, jwt: String? = null): ModelClientV2? + fun connectModelServer(serverURL: String, authProvider: () -> String? = { null }): ModelClientV2? /** * Connects to the model server's specific branch's specific version, and creates [IBinding]s for the modules and diff --git a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/ISyncService.kt b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/ISyncService.kt index c2ffc875..19287a65 100644 --- a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/ISyncService.kt +++ b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/ISyncService.kt @@ -14,10 +14,10 @@ import java.util.concurrent.CompletableFuture @UnstableModelixFeature(reason = "The new modelix MPS plugin is under construction", intendedFinalization = "This feature is finalized when the new sync plugin is ready for release.") interface ISyncService : IRebindModulesSyncService { - override fun connectModelServer(serverURL: String, jwt: String?) = connectModelServer(URL(serverURL), jwt) + override fun connectModelServer(serverURL: String, authProvider: () -> String?) = connectModelServer(URL(serverURL), authProvider) @Throws(IOException::class) - fun connectModelServer(serverURL: URL, jwt: String? = null): ModelClientV2 + fun connectModelServer(serverURL: URL, authProvider: () -> String?): ModelClientV2 fun disconnectModelServer(client: ModelClientV2) diff --git a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/SyncServiceImpl.kt b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/SyncServiceImpl.kt index c0607343..cd7ad3e4 100644 --- a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/SyncServiceImpl.kt +++ b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/SyncServiceImpl.kt @@ -67,9 +67,9 @@ class SyncServiceImpl : ISyncService, InjectableService { } @Throws(IOException::class) - override fun connectModelServer(serverURL: URL, jwt: String?): ModelClientV2 { + override fun connectModelServer(serverURL: URL, authProvider: () -> String?): ModelClientV2 { logger.info { "Connecting to $serverURL" } - val modelClientV2 = ModelClientV2.builder().url(serverURL.toString()).authToken { jwt }.build() + val modelClientV2 = ModelClientV2.builder().url(serverURL.toString()).authToken(authProvider).build() runBlocking(networkDispatcher) { modelClientV2.init() } diff --git a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/persistence/PersistableState.kt b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/persistence/PersistableState.kt index 908b181c..2f40c457 100644 --- a/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/persistence/PersistableState.kt +++ b/mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/persistence/PersistableState.kt @@ -105,7 +105,7 @@ data class PersistableState( * * @return some context statistics about the restored state */ - fun restoreState(syncService: IRebindModulesSyncService, project: Project): RestoredStateContext? { + fun restoreState(syncService: IRebindModulesSyncService, project: Project, authProvider: () -> String? = { null }): RestoredStateContext? { var client: ModelClientV2? = null try { @@ -120,7 +120,8 @@ data class PersistableState( } logger.debug { "Restoring connection to model server." } - client = syncService.connectModelServer(clientUrl, "") + // TODO FIXME auth token is missing + client = syncService.connectModelServer(clientUrl, authProvider) if (client == null) { throw IllegalStateException("Connection to $clientUrl failed, thus PersistableState is not restored.") } diff --git a/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/ModelSyncService.kt b/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/ModelSyncService.kt index e8917ab6..973a5961 100644 --- a/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/ModelSyncService.kt +++ b/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/ModelSyncService.kt @@ -82,10 +82,10 @@ class ModelSyncService(project: Project) : IRebindModulesSyncService { logger.debug { "ModelixSyncPlugin: InjectableNotifierWrapper is initialized" } } - override fun connectModelServer(serverURL: String, jwt: String?): ModelClientV2? { + override fun connectModelServer(serverURL: String, authProvider: () -> String?): ModelClientV2? { var client: ModelClientV2? = null try { - client = syncService.connectModelServer(URL(serverURL), jwt) + client = syncService.connectModelServer(URL(serverURL), authProvider) notifier.notifyAndLogInfo("Connected to server: $serverURL", logger) } catch (t: Throwable) { val message = "Unable to connect to $serverURL. Cause: ${t.message}" diff --git a/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/gui/ModelSyncGuiFactory.kt b/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/gui/ModelSyncGuiFactory.kt index 66c8ce04..40d2da1d 100644 --- a/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/gui/ModelSyncGuiFactory.kt +++ b/mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/gui/ModelSyncGuiFactory.kt @@ -181,7 +181,7 @@ class ModelSyncGuiFactory : ToolWindowFactory { return@addActionListener } - val client = modelSyncService.connectModelServer(serverURL.text, jwt.text) + val client = modelSyncService.connectModelServer(serverURL.text) { jwt.text } triggerRefresh(client) } jwtPanel.add(connectButton)