-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce mandatory session verification only for new logins (#2811)
* Enforce mandatory session verification only for new logins - Creates `AppMigration` base interface as a way to isolate migration logic, app migrations must implement this interface. - Creates `AppMigration01` with the existing logs removal migration and `AppMigration02` with the logic to allow existing sessions to skip verification. - Add `DefaultSessionPreferencesStoreFactory.remove(sessionId)` to allow a ephemeral session store access to exist outside the `SessionScope` for this new migration. * Fix tests * Add more tests. This also includes creating several abstractions. * Review changes. - Make `orderedMigrations` a class property, `migrations` just a constructor parameter to avoid incorrect usages. - Create `lastMigration` property too, use it instead of `MIGRATION_VERSION`.
- Loading branch information
1 parent
2007752
commit 5c59f6c
Showing
30 changed files
with
370 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Enforce mandatory session verification only for new logins. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...mpl/src/main/kotlin/io/element/android/features/migration/impl/migrations/AppMigration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.migration.impl.migrations | ||
|
||
interface AppMigration { | ||
val order: Int | ||
suspend fun migrate() | ||
} |
33 changes: 33 additions & 0 deletions
33
...l/src/main/kotlin/io/element/android/features/migration/impl/migrations/AppMigration01.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.migration.impl.migrations | ||
|
||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import io.element.android.features.rageshake.api.logs.LogFilesRemover | ||
import io.element.android.libraries.di.AppScope | ||
import javax.inject.Inject | ||
|
||
@ContributesMultibinding(AppScope::class) | ||
class AppMigration01 @Inject constructor( | ||
private val logFilesRemover: LogFilesRemover, | ||
) : AppMigration { | ||
override val order: Int = 1 | ||
|
||
override suspend fun migrate() { | ||
logFilesRemover.perform() | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...l/src/main/kotlin/io/element/android/features/migration/impl/migrations/AppMigration02.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2024 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.features.migration.impl.migrations | ||
|
||
import com.squareup.anvil.annotations.ContributesMultibinding | ||
import io.element.android.features.preferences.api.store.SessionPreferencesStoreFactory | ||
import io.element.android.libraries.di.AppScope | ||
import io.element.android.libraries.matrix.api.core.SessionId | ||
import io.element.android.libraries.sessionstorage.api.SessionStore | ||
import kotlinx.coroutines.coroutineScope | ||
import javax.inject.Inject | ||
|
||
@ContributesMultibinding(AppScope::class) | ||
class AppMigration02 @Inject constructor( | ||
private val sessionStore: SessionStore, | ||
private val sessionPreferenceStoreFactory: SessionPreferencesStoreFactory, | ||
) : AppMigration { | ||
override val order: Int = 2 | ||
|
||
override suspend fun migrate() { | ||
coroutineScope { | ||
for (session in sessionStore.getAllSessions()) { | ||
val sessionId = SessionId(session.userId) | ||
val preferences = sessionPreferenceStoreFactory.get(sessionId, this) | ||
preferences.setSkipSessionVerification(true) | ||
// This session preference store must be ephemeral since it's not created with the right coroutine scope | ||
sessionPreferenceStoreFactory.remove(sessionId) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.