Skip to content

Commit 907a0d1

Browse files
authored
Merge pull request #141 from modelix/fix/auth-provider-instead-of-jwt-token
Use authProvider instead of static jwt string in the SyncServiceImpl
2 parents ea5d6ad + 8f41d14 commit 907a0d1

File tree

6 files changed

+12
-11
lines changed

6 files changed

+12
-11
lines changed

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/IRebindModulesSyncService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ interface IRebindModulesSyncService {
2121
* Creates a connection to the model server. Do not forget to close the created client after use.
2222
*
2323
* @param serverURL the model server URL
24-
* @param jwt the JWT auth token
24+
* @param authProvider a function that generates a JWT token that can be used for auth
2525
*
2626
* @return the model client that is connected to the model server
2727
*/
2828
@Throws(IOException::class)
29-
fun connectModelServer(serverURL: String, jwt: String? = null): ModelClientV2?
29+
fun connectModelServer(serverURL: String, authProvider: () -> String? = { null }): ModelClientV2?
3030

3131
/**
3232
* Connects to the model server's specific branch's specific version, and creates [IBinding]s for the modules and

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/ISyncService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import java.util.concurrent.CompletableFuture
1414
@UnstableModelixFeature(reason = "The new modelix MPS plugin is under construction", intendedFinalization = "This feature is finalized when the new sync plugin is ready for release.")
1515
interface ISyncService : IRebindModulesSyncService {
1616

17-
override fun connectModelServer(serverURL: String, jwt: String?) = connectModelServer(URL(serverURL), jwt)
17+
override fun connectModelServer(serverURL: String, authProvider: () -> String?) = connectModelServer(URL(serverURL), authProvider)
1818

1919
@Throws(IOException::class)
20-
fun connectModelServer(serverURL: URL, jwt: String? = null): ModelClientV2
20+
fun connectModelServer(serverURL: URL, authProvider: () -> String?): ModelClientV2
2121

2222
fun disconnectModelServer(client: ModelClientV2)
2323

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/SyncServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class SyncServiceImpl : ISyncService, InjectableService {
6767
}
6868

6969
@Throws(IOException::class)
70-
override fun connectModelServer(serverURL: URL, jwt: String?): ModelClientV2 {
70+
override fun connectModelServer(serverURL: URL, authProvider: () -> String?): ModelClientV2 {
7171
logger.info { "Connecting to $serverURL" }
72-
val modelClientV2 = ModelClientV2.builder().url(serverURL.toString()).authToken { jwt }.build()
72+
val modelClientV2 = ModelClientV2.builder().url(serverURL.toString()).authToken(authProvider).build()
7373
runBlocking(networkDispatcher) {
7474
modelClientV2.init()
7575
}

mps-sync-plugin-lib/src/main/kotlin/org/modelix/mps/sync/persistence/PersistableState.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ data class PersistableState(
105105
*
106106
* @return some context statistics about the restored state
107107
*/
108-
fun restoreState(syncService: IRebindModulesSyncService, project: Project): RestoredStateContext? {
108+
fun restoreState(syncService: IRebindModulesSyncService, project: Project, authProvider: () -> String? = { null }): RestoredStateContext? {
109109
var client: ModelClientV2? = null
110110

111111
try {
@@ -120,7 +120,8 @@ data class PersistableState(
120120
}
121121

122122
logger.debug { "Restoring connection to model server." }
123-
client = syncService.connectModelServer(clientUrl, "")
123+
// TODO FIXME auth token is missing
124+
client = syncService.connectModelServer(clientUrl, authProvider)
124125
if (client == null) {
125126
throw IllegalStateException("Connection to $clientUrl failed, thus PersistableState is not restored.")
126127
}

mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/ModelSyncService.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class ModelSyncService(project: Project) : IRebindModulesSyncService {
8282
logger.debug { "ModelixSyncPlugin: InjectableNotifierWrapper is initialized" }
8383
}
8484

85-
override fun connectModelServer(serverURL: String, jwt: String?): ModelClientV2? {
85+
override fun connectModelServer(serverURL: String, authProvider: () -> String?): ModelClientV2? {
8686
var client: ModelClientV2? = null
8787
try {
88-
client = syncService.connectModelServer(URL(serverURL), jwt)
88+
client = syncService.connectModelServer(URL(serverURL), authProvider)
8989
notifier.notifyAndLogInfo("Connected to server: $serverURL", logger)
9090
} catch (t: Throwable) {
9191
val message = "Unable to connect to $serverURL. Cause: ${t.message}"

mps-sync-plugin/src/main/kotlin/org/modelix/mps/sync/plugin/gui/ModelSyncGuiFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class ModelSyncGuiFactory : ToolWindowFactory {
179179
return@addActionListener
180180
}
181181

182-
val client = modelSyncService.connectModelServer(serverURL.text, jwt.text)
182+
val client = modelSyncService.connectModelServer(serverURL.text) { jwt.text }
183183
triggerRefresh(client)
184184
}
185185
jwtPanel.add(connectButton)

0 commit comments

Comments
 (0)