Add facilities and Javadoc on SessionParams data class
This commit is contained in:
parent
c646fd2b36
commit
4c31e52892
|
@ -246,7 +246,7 @@ class CryptoTestHelper(private val mTestHelper: CommonTestHelper) {
|
|||
assertNotNull(eventWireContent.get("session_id"))
|
||||
assertNotNull(eventWireContent.get("sender_key"))
|
||||
|
||||
assertEquals(senderSession.sessionParams.credentials.deviceId, eventWireContent.get("device_id"))
|
||||
assertEquals(senderSession.sessionParams.deviceId, eventWireContent.get("device_id"))
|
||||
|
||||
assertNotNull(event.eventId)
|
||||
assertEquals(roomId, event.roomId)
|
||||
|
|
|
@ -122,7 +122,7 @@ class XSigningTest : InstrumentedTest {
|
|||
// We will want to test that in alice POV, this new device would be trusted by cross signing
|
||||
|
||||
val bobSession2 = mTestHelper.logIntoAccount(bobUserId, SessionTestParams(true))
|
||||
val bobSecondDeviceId = bobSession2.sessionParams.credentials.deviceId!!
|
||||
val bobSecondDeviceId = bobSession2.sessionParams.deviceId!!
|
||||
|
||||
// Check that bob first session sees the new login
|
||||
val data = mTestHelper.doSync<MXUsersDevicesMap<CryptoDeviceInfo>> {
|
||||
|
|
|
@ -148,7 +148,7 @@ class KeyShareTests : InstrumentedTest {
|
|||
|
||||
// Mark the device as trusted
|
||||
aliceSession.cryptoService().setDeviceVerification(DeviceTrustLevel(crossSigningVerified = false, locallyVerified = true), aliceSession.myUserId,
|
||||
aliceSession2.sessionParams.credentials.deviceId ?: "")
|
||||
aliceSession2.sessionParams.deviceId ?: "")
|
||||
|
||||
// Re request
|
||||
aliceSession2.cryptoService().reRequestRoomKeyForEvent(receivedEvent.root)
|
||||
|
@ -253,12 +253,12 @@ class KeyShareTests : InstrumentedTest {
|
|||
})
|
||||
|
||||
val txId: String = "m.testVerif12"
|
||||
aliceVerificationService2.beginKeyVerification(VerificationMethod.SAS, aliceSession1.myUserId, aliceSession1.sessionParams.credentials.deviceId
|
||||
aliceVerificationService2.beginKeyVerification(VerificationMethod.SAS, aliceSession1.myUserId, aliceSession1.sessionParams.deviceId
|
||||
?: "", txId)
|
||||
|
||||
mTestHelper.waitWithLatch { latch ->
|
||||
mTestHelper.retryPeriodicallyWithLatch(latch) {
|
||||
aliceSession1.cryptoService().getDeviceInfo(aliceSession1.myUserId, aliceSession2.sessionParams.credentials.deviceId ?: "")?.isVerified == true
|
||||
aliceSession1.cryptoService().getDeviceInfo(aliceSession1.myUserId, aliceSession2.sessionParams.deviceId ?: "")?.isVerified == true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -835,7 +835,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
assertTrue(signature.valid)
|
||||
assertNotNull(signature.device)
|
||||
assertEquals(cryptoTestData.firstSession.cryptoService().getMyDevice().deviceId, signature.deviceId)
|
||||
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.credentials.deviceId)
|
||||
assertEquals(signature.device!!.deviceId, cryptoTestData.firstSession.sessionParams.deviceId)
|
||||
|
||||
stateObserver.stopAndCheckStates(null)
|
||||
cryptoTestData.cleanUp(mTestHelper)
|
||||
|
@ -997,7 +997,7 @@ class KeysBackupTest : InstrumentedTest {
|
|||
keysBackup.backupAllGroupSessions(null, it)
|
||||
}
|
||||
|
||||
val oldDeviceId = cryptoTestData.firstSession.sessionParams.credentials.deviceId!!
|
||||
val oldDeviceId = cryptoTestData.firstSession.sessionParams.deviceId!!
|
||||
val oldKeyBackupVersion = keysBackup.currentBackupVersion
|
||||
val aliceUserId = cryptoTestData.firstSession.myUserId
|
||||
|
||||
|
|
|
@ -579,7 +579,7 @@ class SASTest : InstrumentedTest {
|
|||
requestID!!,
|
||||
cryptoTestData.roomId,
|
||||
bobSession.myUserId,
|
||||
bobSession.sessionParams.credentials.deviceId!!,
|
||||
bobSession.sessionParams.deviceId!!,
|
||||
null)
|
||||
|
||||
bobVerificationService.beginKeyVerificationInDMs(
|
||||
|
@ -587,7 +587,7 @@ class SASTest : InstrumentedTest {
|
|||
requestID!!,
|
||||
cryptoTestData.roomId,
|
||||
aliceSession.myUserId,
|
||||
aliceSession.sessionParams.credentials.deviceId!!,
|
||||
aliceSession.sessionParams.deviceId!!,
|
||||
null)
|
||||
|
||||
// we should reach SHOW SAS on both
|
||||
|
|
|
@ -20,7 +20,6 @@ import im.vector.matrix.android.api.MatrixCallback
|
|||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.api.auth.data.LoginFlowResult
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.auth.login.LoginWizard
|
||||
import im.vector.matrix.android.api.auth.registration.RegistrationWizard
|
||||
import im.vector.matrix.android.api.auth.wellknown.WellknownResult
|
||||
|
@ -37,6 +36,11 @@ interface AuthenticationService {
|
|||
*/
|
||||
fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable
|
||||
|
||||
/**
|
||||
* Request the supported login flows for the corresponding sessionId.
|
||||
*/
|
||||
fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback<LoginFlowResult>): Cancelable
|
||||
|
||||
/**
|
||||
* Return a LoginWizard, to login to the homeserver. The login flow has to be retrieved first.
|
||||
*/
|
||||
|
@ -74,15 +78,6 @@ interface AuthenticationService {
|
|||
*/
|
||||
fun getLastAuthenticatedSession(): Session?
|
||||
|
||||
/**
|
||||
* Get an authenticated session. You should at least call authenticate one time before.
|
||||
* If you logout, this session will no longer be valid.
|
||||
*
|
||||
* @param sessionParams the sessionParams to open with.
|
||||
* @return the associated session if any, or null
|
||||
*/
|
||||
fun getSession(sessionParams: SessionParams): Session?
|
||||
|
||||
/**
|
||||
* Create a session after a SSO successful login
|
||||
*/
|
||||
|
|
|
@ -21,7 +21,48 @@ package im.vector.matrix.android.api.auth.data
|
|||
* You don't have to manually instantiate it.
|
||||
*/
|
||||
data class SessionParams(
|
||||
/**
|
||||
* Please consider using shortcuts instead
|
||||
*/
|
||||
val credentials: Credentials,
|
||||
|
||||
/**
|
||||
* Please consider using shortcuts instead
|
||||
*/
|
||||
val homeServerConnectionConfig: HomeServerConnectionConfig,
|
||||
|
||||
/**
|
||||
* Set to false if the current token is not valid anymore. Application should not have to use this info.
|
||||
*/
|
||||
val isTokenValid: Boolean
|
||||
)
|
||||
) {
|
||||
/*
|
||||
* Shortcuts. Usually the application should only need to use these shortcuts
|
||||
*/
|
||||
|
||||
/**
|
||||
* The userId of the session (Ex: "@user:domain.org")
|
||||
*/
|
||||
val userId = credentials.userId
|
||||
|
||||
/**
|
||||
* The deviceId of the session (Ex: "ABCDEFGH")
|
||||
*/
|
||||
val deviceId = credentials.deviceId
|
||||
|
||||
/**
|
||||
* The current homeserver Url. It can be different that the homeserver url entered
|
||||
* during login phase, because a redirection may have occurred
|
||||
*/
|
||||
val homeServerUrl = homeServerConnectionConfig.homeServerUri.toString()
|
||||
|
||||
/**
|
||||
* The current homeserver host
|
||||
*/
|
||||
val homeServerHost = homeServerConnectionConfig.homeServerUri.host
|
||||
|
||||
/**
|
||||
* The default identity server url if any, returned by the homeserver during login phase
|
||||
*/
|
||||
val defaultIdentityServerUrl = homeServerConnectionConfig.identityServerUri?.toString()
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ interface Session :
|
|||
* Useful shortcut to get access to the userId
|
||||
*/
|
||||
val myUserId: String
|
||||
get() = sessionParams.credentials.userId
|
||||
get() = sessionParams.userId
|
||||
|
||||
/**
|
||||
* The sessionId
|
||||
|
|
|
@ -23,7 +23,6 @@ import im.vector.matrix.android.api.auth.AuthenticationService
|
|||
import im.vector.matrix.android.api.auth.data.Credentials
|
||||
import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
|
||||
import im.vector.matrix.android.api.auth.data.LoginFlowResult
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.auth.data.Versions
|
||||
import im.vector.matrix.android.api.auth.data.isLoginAndRegistrationSupportedBySdk
|
||||
import im.vector.matrix.android.api.auth.data.isSupportedBySdk
|
||||
|
@ -33,6 +32,7 @@ import im.vector.matrix.android.api.auth.wellknown.WellknownResult
|
|||
import im.vector.matrix.android.api.failure.Failure
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.util.Cancelable
|
||||
import im.vector.matrix.android.api.util.NoOpCancellable
|
||||
import im.vector.matrix.android.internal.SessionManager
|
||||
import im.vector.matrix.android.internal.auth.data.LoginFlowResponse
|
||||
import im.vector.matrix.android.internal.auth.data.RiotConfig
|
||||
|
@ -87,8 +87,15 @@ internal class DefaultAuthenticationService @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getSession(sessionParams: SessionParams): Session? {
|
||||
return sessionManager.getOrCreateSession(sessionParams)
|
||||
override fun getLoginFlowOfSession(sessionId: String, callback: MatrixCallback<LoginFlowResult>): Cancelable {
|
||||
val homeServerConnectionConfig = sessionParamsStore.get(sessionId)?.homeServerConnectionConfig
|
||||
|
||||
return if (homeServerConnectionConfig == null) {
|
||||
callback.onFailure(IllegalStateException("Session not found"))
|
||||
NoOpCancellable
|
||||
} else {
|
||||
getLoginFlow(homeServerConnectionConfig, callback)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLoginFlow(homeServerConnectionConfig: HomeServerConnectionConfig, callback: MatrixCallback<LoginFlowResult>): Cancelable {
|
||||
|
|
|
@ -51,7 +51,7 @@ internal class SessionParamsMapper @Inject constructor(moshi: Moshi) {
|
|||
}
|
||||
return SessionParamsEntity(
|
||||
sessionParams.credentials.sessionId(),
|
||||
sessionParams.credentials.userId,
|
||||
sessionParams.userId,
|
||||
credentialsJson,
|
||||
homeServerConnectionConfigJson,
|
||||
sessionParams.isTokenValid)
|
||||
|
|
|
@ -121,7 +121,7 @@ internal class DefaultOutgoingSASDefaultVerificationTransaction(
|
|||
// }
|
||||
//
|
||||
// val requestMessage = KeyVerificationRequest(
|
||||
// fromDevice = session.sessionParams.credentials.deviceId ?: "",
|
||||
// fromDevice = session.sessionParams.deviceId ?: "",
|
||||
// methods = listOf(KeyVerificationStart.VERIF_METHOD_SAS),
|
||||
// timestamp = System.currentTimeMillis().toInt(),
|
||||
// transactionId = transactionId
|
||||
|
|
|
@ -242,6 +242,6 @@ internal class DefaultSession @Inject constructor(
|
|||
|
||||
// For easy debugging
|
||||
override fun toString(): String {
|
||||
return "$myUserId - ${sessionParams.credentials.deviceId}"
|
||||
return "$myUserId - ${sessionParams.deviceId}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@ internal class DefaultSignInAgainTask @Inject constructor(
|
|||
apiCall = signOutAPI.loginAgain(
|
||||
PasswordLoginParams.userIdentifier(
|
||||
// Reuse the same userId
|
||||
sessionParams.credentials.userId,
|
||||
sessionParams.userId,
|
||||
params.password,
|
||||
// The spec says the initial device name will be ignored
|
||||
// https://matrix.org/docs/spec/client_server/latest#post-matrix-client-r0-login
|
||||
// but https://github.com/matrix-org/synapse/issues/6525
|
||||
// Reuse the same deviceId
|
||||
deviceId = sessionParams.credentials.deviceId
|
||||
deviceId = sessionParams.deviceId
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -229,8 +229,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector {
|
|||
handleInvalidToken(globalError)
|
||||
is GlobalError.ConsentNotGivenError ->
|
||||
consentNotGivenHelper.displayDialog(globalError.consentUri,
|
||||
activeSessionHolder.getActiveSession().sessionParams.homeServerConnectionConfig.homeServerUri.host
|
||||
?: "")
|
||||
activeSessionHolder.getActiveSession().sessionParams.homeServerHost ?: "")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ class PushersManager @Inject constructor(
|
|||
profileTag,
|
||||
localeProvider.current().language,
|
||||
appNameProvider.getAppName(),
|
||||
currentSession.sessionParams.credentials.deviceId ?: "MOBILE",
|
||||
currentSession.sessionParams.deviceId ?: "MOBILE",
|
||||
stringProvider.getString(R.string.pusher_http_url),
|
||||
append = false,
|
||||
withEventIdOnly = true
|
||||
|
|
|
@ -197,7 +197,7 @@ class KeysBackupSettingsRecyclerViewController @Inject constructor(private val s
|
|||
endIconResourceId(R.drawable.e2e_warning)
|
||||
} else {
|
||||
if (isSignatureValid) {
|
||||
if (session.sessionParams.credentials.deviceId == it.deviceId) {
|
||||
if (session.sessionParams.deviceId == it.deviceId) {
|
||||
description(stringProvider.getString(R.string.keys_backup_settings_valid_signature_from_this_device))
|
||||
endIconResourceId(R.drawable.e2e_verified)
|
||||
} else {
|
||||
|
|
|
@ -367,7 +367,7 @@ class VerificationBottomSheetViewModel @AssistedInject constructor(
|
|||
)
|
||||
if (trustResult.isVerified()) {
|
||||
// Sign this device and upload the signature
|
||||
session.sessionParams.credentials.deviceId?.let { deviceId ->
|
||||
session.sessionParams.deviceId?.let { deviceId ->
|
||||
session.cryptoService()
|
||||
.crossSigningService().trustDevice(deviceId, object : MatrixCallback<Unit> {
|
||||
override fun onFailure(failure: Throwable) {
|
||||
|
|
|
@ -67,9 +67,10 @@ class UnknownDeviceDetectorSharedViewModel(
|
|||
|
||||
init {
|
||||
|
||||
val currentSessionTs = session.cryptoService().getCryptoDeviceInfo(session.myUserId).firstOrNull {
|
||||
it.deviceId == session.sessionParams.credentials.deviceId
|
||||
}?.firstTimeSeenLocalTs ?: System.currentTimeMillis()
|
||||
val currentSessionTs = session.cryptoService().getCryptoDeviceInfo(session.myUserId)
|
||||
.firstOrNull { it.deviceId == session.sessionParams.deviceId }
|
||||
?.firstTimeSeenLocalTs
|
||||
?: System.currentTimeMillis()
|
||||
Timber.v("## Detector - Current Session first time seen $currentSessionTs")
|
||||
|
||||
ignoredDeviceList.addAll(
|
||||
|
|
|
@ -212,7 +212,7 @@ class BugReporter @Inject constructor(
|
|||
|
||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||
userId = session.myUserId
|
||||
deviceId = session.sessionParams.credentials.deviceId ?: "undefined"
|
||||
deviceId = session.sessionParams.deviceId ?: "undefined"
|
||||
olmVersion = session.cryptoService().getCryptoVersion(context, true)
|
||||
}
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
|
|||
|
||||
// home server
|
||||
findPreference<VectorPreference>(VectorPreferences.SETTINGS_HOME_SERVER_PREFERENCE_KEY)!!
|
||||
.summary = session.sessionParams.homeServerConnectionConfig.homeServerUri.toString()
|
||||
.summary = session.sessionParams.homeServerUrl
|
||||
|
||||
refreshEmailsList()
|
||||
refreshPhoneNumbersList()
|
||||
|
|
|
@ -47,7 +47,7 @@ class VectorSettingsLabsFragment @Inject constructor(
|
|||
// useCryptoPref.isChecked = false
|
||||
//
|
||||
// useCryptoPref.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValueAsVoid ->
|
||||
// if (TextUtils.isEmpty(mSession.sessionParams.credentials.deviceId)) {
|
||||
// if (TextUtils.isEmpty(mSession.sessionParams.deviceId)) {
|
||||
// activity?.let { activity ->
|
||||
// AlertDialog.Builder(activity)
|
||||
// .setMessage(R.string.room_settings_labs_end_to_end_warnings)
|
||||
|
|
|
@ -340,7 +340,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||
showDeviceListPref.isEnabled = devices.size > 0
|
||||
showDeviceListPref.summary = resources.getQuantityString(R.plurals.settings_active_sessions_count, devices.size, devices.size)
|
||||
// val userId = session.myUserId
|
||||
// val deviceId = session.sessionParams.credentials.deviceId
|
||||
// val deviceId = session.sessionParams.deviceId
|
||||
|
||||
// device name
|
||||
// if (null != aMyDeviceInfo) {
|
||||
|
|
|
@ -73,7 +73,7 @@ class DeviceVerificationInfoBottomSheetViewModel @AssistedInject constructor(@As
|
|||
.execute {
|
||||
copy(
|
||||
cryptoDeviceInfo = it,
|
||||
isMine = it.invoke()?.deviceId == session.sessionParams.credentials.deviceId
|
||||
isMine = it.invoke()?.deviceId == session.sessionParams.deviceId
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ class DevicesViewModel @AssistedInject constructor(
|
|||
copy(
|
||||
hasAccountCrossSigning = session.cryptoService().crossSigningService().getMyCrossSigningKeys() != null,
|
||||
accountCrossSigningIsTrusted = session.cryptoService().crossSigningService().isCrossSigningVerified(),
|
||||
myDeviceId = session.sessionParams.credentials.deviceId ?: ""
|
||||
myDeviceId = session.sessionParams.deviceId ?: ""
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -58,9 +58,9 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
val activity: SoftLogoutActivity = (viewModelContext as ActivityViewModelContext).activity()
|
||||
val userId = activity.session.myUserId
|
||||
return SoftLogoutViewState(
|
||||
homeServerUrl = activity.session.sessionParams.homeServerConnectionConfig.homeServerUri.toString(),
|
||||
homeServerUrl = activity.session.sessionParams.homeServerUrl,
|
||||
userId = userId,
|
||||
deviceId = activity.session.sessionParams.credentials.deviceId ?: "",
|
||||
deviceId = activity.session.sessionParams.deviceId ?: "",
|
||||
userDisplayName = activity.session.getUser(userId)?.displayName ?: userId,
|
||||
hasUnsavedKeys = activity.session.hasUnsavedKeys()
|
||||
)
|
||||
|
@ -81,8 +81,6 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
private fun getSupportedLoginFlow() {
|
||||
val homeServerConnectionConfig = session.sessionParams.homeServerConnectionConfig
|
||||
|
||||
currentTask?.cancel()
|
||||
currentTask = null
|
||||
authenticationService.cancelPendingLoginOrRegistration()
|
||||
|
@ -93,7 +91,7 @@ class SoftLogoutViewModel @AssistedInject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
currentTask = authenticationService.getLoginFlow(homeServerConnectionConfig, object : MatrixCallback<LoginFlowResult> {
|
||||
currentTask = authenticationService.getLoginFlowOfSession(session.sessionId, object : MatrixCallback<LoginFlowResult> {
|
||||
override fun onFailure(failure: Throwable) {
|
||||
setState {
|
||||
copy(
|
||||
|
|
Loading…
Reference in New Issue