Skip to content

Commit

Permalink
fix: some end points are not routed through the proxy server 4.6 (#2754)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohamad Jaara <[email protected]>
  • Loading branch information
AndroidBob and MohamadJaara authored Mar 19, 2024
1 parent 334db7b commit 01a0da9
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 95 deletions.
10 changes: 0 additions & 10 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,6 @@ class UseCaseModule {
fun provideGetServerConfigUserCase(@KaliumCoreLogic coreLogic: CoreLogic) =
coreLogic.getGlobalScope().fetchServerConfigFromDeepLink

@ViewModelScoped
@Provides
fun provideFetchApiVersionUserCase(@KaliumCoreLogic coreLogic: CoreLogic) =
coreLogic.getGlobalScope().fetchApiVersion

@ViewModelScoped
@Provides
fun provideObserveServerConfigUseCase(@KaliumCoreLogic coreLogic: CoreLogic) =
coreLogic.getGlobalScope().observeServerConfig

@ViewModelScoped
@Provides
fun provideUpdateApiVersionsUseCase(@KaliumCoreLogic coreLogic: CoreLogic) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ class MigrateActiveAccountsUseCase @Inject constructor(
private suspend fun handleMissingData(
serverConfig: ServerConfig,
refreshToken: String,
): Either<CoreFailure, AccountTokens> = coreLogic.authenticationScope(serverConfig) {
): Either<CoreFailure, AccountTokens> = coreLogic.authenticationScope(
serverConfig,
// scala did not support proxy mode so we can pass null
proxyCredentials = null
) {
ssoLoginScope.getLoginSession(refreshToken)
}.let {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.wire.kalium.logic.StorageFailure
import com.wire.kalium.logic.configuration.server.CommonApiVersionType
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.failure.ServerConfigFailure
import com.wire.kalium.logic.feature.server.FetchApiVersionResult
import com.wire.kalium.logic.feature.auth.autoVersioningAuth.AutoVersionAuthScopeUseCase
import com.wire.kalium.logic.feature.server.GetServerConfigResult
import com.wire.kalium.logic.feature.server.StoreServerConfigResult
import com.wire.kalium.logic.functional.Either
Expand Down Expand Up @@ -66,13 +66,13 @@ class MigrateServerConfigUseCase @Inject constructor(
}

private suspend fun ServerConfig.Links.fetchApiVersionAndStore(): Either<CoreFailure, ServerConfig> =
coreLogic.getGlobalScope().fetchApiVersion(this).let { // it also already stores the fetched config
// scala did not support proxy mode so we can pass null here
coreLogic.versionedAuthenticationScope(this)(null).let { // it also already stores the fetched config
when (it) {
is FetchApiVersionResult.Success -> Either.Right(it.serverConfig)
FetchApiVersionResult.Failure.TooNewVersion -> Either.Left(ServerConfigFailure.NewServerVersion)
FetchApiVersionResult.Failure.UnknownServerVersion -> Either.Left(ServerConfigFailure.UnknownServerVersion)
is FetchApiVersionResult.Failure.Generic -> Either.Left(it.genericFailure)
is AutoVersionAuthScopeUseCase.Result.Failure.Generic -> Either.Left(it.genericFailure)
AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion -> Either.Left(ServerConfigFailure.NewServerVersion)
AutoVersionAuthScopeUseCase.Result.Failure.UnknownServerVersion -> Either.Left(ServerConfigFailure.UnknownServerVersion)
is AutoVersionAuthScopeUseCase.Result.Success -> Either.Right(it.authenticationScope.currentServerConfig())
}
}

}
11 changes: 6 additions & 5 deletions app/src/main/kotlin/com/wire/android/ui/WireActivityState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

package com.wire.android.ui

sealed class WireActivityState {
sealed class
WireActivityState {

data class NavigationGraph(val startNavigationRoute: String, val navigationArguments: List<Any>): WireActivityState()
data class ClientUpdateRequired(val clientUpdateUrl: String): WireActivityState()
object ServerVersionNotSupported: WireActivityState()
object Loading: WireActivityState()
data class NavigationGraph(val startNavigationRoute: String, val navigationArguments: List<Any>) : WireActivityState()
data class ClientUpdateRequired(val clientUpdateUrl: String) : WireActivityState()
object ServerVersionNotSupported : WireActivityState()
object Loading : WireActivityState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class WireActivityViewModel @Inject constructor(
}

private fun observeUpdateAppState() {
viewModelScope.launch(dispatchers.io()) {
viewModelScope.launch {
observeIfAppUpdateRequired(BuildConfig.VERSION_CODE)
.distinctUntilChanged()
.collect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,32 @@ private fun ServerEnrollmentDialogContent(
onDismiss: () -> Unit,
onClick: () -> Unit,
) {
WireDialog(
title = stringResource(id = R.string.server_details_dialog_title),
text = LocalContext.current.resources.stringWithStyledArgs(
val text = if (serverLinks.apiProxy == null) {
LocalContext.current.resources.stringWithStyledArgs(
R.string.server_details_dialog_body,
MaterialTheme.wireTypography.body02,
MaterialTheme.wireTypography.body02,
normalColor = colorsScheme().secondaryText,
argsColor = colorsScheme().onBackground,
serverLinks.title,
serverLinks.api
),
)
} else {
LocalContext.current.resources.stringWithStyledArgs(
R.string.server_details_dialog_body_with_proxy,
MaterialTheme.wireTypography.body02,
MaterialTheme.wireTypography.body02,
normalColor = colorsScheme().secondaryText,
argsColor = colorsScheme().onBackground,
serverLinks.title,
serverLinks.api,
serverLinks.apiProxy!!.host,
serverLinks.apiProxy!!.needsAuthentication.toString()
)
}
WireDialog(
title = stringResource(id = R.string.server_details_dialog_title),
text = text,
onDismiss = onDismiss,
optionButton1Properties = WireDialogButtonProperties(
stringResource(id = R.string.label_ok),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class CreateAccountCodeViewModel @Inject constructor(
fun resendCode() {
codeState = codeState.copy(loading = true)
viewModelScope.launch {
val authScope = coreLogic.versionedAuthenticationScope(serverConfig)().let {
// create account does not support proxy yet
val authScope = coreLogic.versionedAuthenticationScope(serverConfig)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

Expand Down Expand Up @@ -130,7 +131,8 @@ class CreateAccountCodeViewModel @Inject constructor(
private fun onCodeContinue(onSuccess: () -> Unit) {
codeState = codeState.copy(loading = true)
viewModelScope.launch {
val authScope = coreLogic.versionedAuthenticationScope(serverConfig)().let {
// create account does not support proxy yet
val authScope = coreLogic.versionedAuthenticationScope(serverConfig)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.feature.auth.ValidateEmailUseCase
import com.wire.kalium.logic.feature.auth.autoVersioningAuth.AutoVersionAuthScopeUseCase
import com.wire.kalium.logic.feature.register.RequestActivationCodeResult
import com.wire.kalium.logic.feature.server.FetchApiVersionResult
import com.wire.kalium.logic.feature.server.FetchApiVersionUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand All @@ -44,7 +42,6 @@ import javax.inject.Inject
class CreateAccountEmailViewModel @Inject constructor(
savedStateHandle: SavedStateHandle,
private val authServerConfigProvider: AuthServerConfigProvider,
private val fetchApiVersion: FetchApiVersionUseCase,
private val validateEmail: ValidateEmailUseCase,
@KaliumCoreLogic private val coreLogic: CoreLogic,
) : ViewModel() {
Expand All @@ -69,25 +66,6 @@ class CreateAccountEmailViewModel @Inject constructor(
fun onEmailContinue(onSuccess: () -> Unit) {
emailState = emailState.copy(loading = true, continueEnabled = false)
viewModelScope.launch {
fetchApiVersion(authServerConfigProvider.authServer.value).let {
when (it) {
is FetchApiVersionResult.Success -> {}
is FetchApiVersionResult.Failure.UnknownServerVersion -> {
emailState = emailState.copy(showServerVersionNotSupportedDialog = true)
return@launch
}

is FetchApiVersionResult.Failure.TooNewVersion -> {
emailState = emailState.copy(showClientUpdateDialog = true)
return@launch
}

is FetchApiVersionResult.Failure.Generic -> {
return@launch
}
}
}

val emailError =
if (validateEmail(emailState.email.text.trim().lowercase())) CreateAccountEmailViewState.EmailError.None
else CreateAccountEmailViewState.EmailError.TextFieldError.InvalidEmailError
Expand All @@ -106,7 +84,7 @@ class CreateAccountEmailViewModel @Inject constructor(
fun onTermsAccept(onSuccess: () -> Unit) {
emailState = emailState.copy(loading = true, continueEnabled = false, termsDialogVisible = false, termsAccepted = true)
viewModelScope.launch {
val authScope = coreLogic.versionedAuthenticationScope(serverConfig)().let {
val authScope = coreLogic.versionedAuthenticationScope(serverConfig)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.wire.android.ui.authentication.login

import androidx.compose.ui.text.input.TextFieldValue
import com.wire.android.ui.common.dialogs.CustomServerDialogState
import com.wire.kalium.logic.data.auth.login.ProxyCredentials

data class LoginState(
val userIdentifier: TextFieldValue = TextFieldValue(""),
Expand All @@ -36,7 +37,14 @@ data class LoginState(
val loginError: LoginError = LoginError.None,
val isProxyEnabled: Boolean = false,
val customServerDialogState: CustomServerDialogState? = null,
)
) {
fun getProxyCredentials(): ProxyCredentials? =
if (proxyIdentifier.text.isNotBlank() && proxyPassword.text.isNotBlank()) {
ProxyCredentials(proxyIdentifier.text, proxyPassword.text)
} else {
null
}
}

fun LoginState.updateEmailLoginEnabled() =
copy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.auth.AddAuthenticatedUserUseCase
import com.wire.kalium.logic.feature.auth.AuthenticationResult
import com.wire.kalium.logic.feature.auth.DomainLookupUseCase
import com.wire.kalium.logic.feature.auth.autoVersioningAuth.AutoVersionAuthScopeUseCase
import com.wire.kalium.logic.feature.client.RegisterClientResult
import com.wire.kalium.logic.feature.client.RegisterClientUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -68,8 +67,6 @@ open class LoginViewModel @Inject constructor(
}
}

protected suspend fun authScope(): AutoVersionAuthScopeUseCase.Result = coreLogic.versionedAuthenticationScope(serverConfig)()

private val loginNavArgs: LoginNavArgs = savedStateHandle.navArgs()
private val preFilledUserIdentifier: PreFilledUserIdentifierType = loginNavArgs.userHandle.let {
if (it.isNullOrEmpty()) PreFilledUserIdentifierType.None else PreFilledUserIdentifierType.PreFilled(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.wire.android.ui.authentication.verificationcode.VerificationCodeState
import com.wire.android.ui.common.textfield.CodeFieldValue
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.auth.login.ProxyCredentials
import com.wire.kalium.logic.data.auth.verification.VerifiableAction
import com.wire.kalium.logic.feature.auth.AddAuthenticatedUserUseCase
import com.wire.kalium.logic.feature.auth.AuthenticationResult
Expand Down Expand Up @@ -137,29 +136,27 @@ class LoginEmailViewModel @Inject constructor(

private suspend fun resolveCurrentAuthScope(): AuthenticationScope? =
coreLogic.versionedAuthenticationScope(serverConfig).invoke(
AutoVersionAuthScopeUseCase.ProxyAuthentication.UsernameAndPassword(
ProxyCredentials(loginState.proxyIdentifier.text, loginState.proxyPassword.text)
)
).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

is AutoVersionAuthScopeUseCase.Result.Failure.UnknownServerVersion -> {
updateEmailLoginError(LoginError.DialogError.ServerVersionNotSupported)
return null
}
loginState.getProxyCredentials()
).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

is AutoVersionAuthScopeUseCase.Result.Failure.UnknownServerVersion -> {
updateEmailLoginError(LoginError.DialogError.ServerVersionNotSupported)
return null
}

is AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion -> {
updateEmailLoginError(LoginError.DialogError.ClientUpdateRequired)
return null
}
is AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion -> {
updateEmailLoginError(LoginError.DialogError.ClientUpdateRequired)
return null
}

is AutoVersionAuthScopeUseCase.Result.Failure.Generic -> {
updateEmailLoginError(LoginError.DialogError.GenericError(it.genericFailure))
return null
is AutoVersionAuthScopeUseCase.Result.Failure.Generic -> {
updateEmailLoginError(LoginError.DialogError.GenericError(it.genericFailure))
return null
}
}
}
}

private suspend fun handleAuthenticationFailure(it: AuthenticationResult.Failure, authScope: AuthenticationScope) {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ class LoginSSOViewModel @Inject constructor(
if (loginState.customServerDialogState != null) {
authServerConfigProvider.updateAuthServer(loginState.customServerDialogState!!.serverLinks)

val authScope = coreLogic.versionedAuthenticationScope(loginState.customServerDialogState!!.serverLinks)().let {
// sso does not support proxy
// TODO: add proxy support
val authScope = coreLogic.versionedAuthenticationScope(loginState.customServerDialogState!!.serverLinks)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic,
AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion,
Expand Down Expand Up @@ -134,7 +136,9 @@ class LoginSSOViewModel @Inject constructor(
val defaultAuthScope: AuthenticationScope =
coreLogic.versionedAuthenticationScope(
authServerConfigProvider.defaultServerLinks()
)().let {
// domain lockup does not support proxy
// TODO: add proxy support
)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Failure.Generic,
AutoVersionAuthScopeUseCase.Result.Failure.TooNewVersion,
Expand Down Expand Up @@ -168,7 +172,8 @@ class LoginSSOViewModel @Inject constructor(
private fun ssoLoginWithCodeFlow() {
viewModelScope.launch {
val authScope =
authScope().let {
// sso does not support proxy
coreLogic.versionedAuthenticationScope(serverConfig)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

Expand Down Expand Up @@ -207,7 +212,7 @@ class LoginSSOViewModel @Inject constructor(
loginState = loginState.copy(ssoLoginLoading = true, loginError = LoginError.None).updateSSOLoginEnabled()
viewModelScope.launch {
val authScope =
authScope().let {
coreLogic.versionedAuthenticationScope(serverConfig)(null).let {
when (it) {
is AutoVersionAuthScopeUseCase.Result.Success -> it.authenticationScope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ internal fun CustomServerDialog(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_api),
value = serverLinks.api
)
if (serverLinks.apiProxy != null) {
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_proxy_url),
value = serverLinks.apiProxy!!.host
)

CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_proxy_authentication),
value = serverLinks.apiProxy!!.needsAuthentication.toString()
)
}
if (showDetails) {
CustomServerPropertyInfo(
title = stringResource(id = R.string.custom_backend_dialog_body_backend_websocket),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<string name="welcome_screen_carousel_item_message_5">Wire wird unabhängig geprüft und ist ISO-, CCPA-, DSGVO- und SOX-konform</string>
<string name="welcome_button_create_team">Team erstellen</string>
<string name="server_details_dialog_body">Backend-Name:\n%1$s\n\nBackend-URL:\n%2$s</string>
<string name="server_details_dialog_body_with_proxy">Backend name:\n%1$s\n\nBackend URL:\n%2$s\n\nProxy-URL:\n%3$s\n\nProxy-Authentifizierung:\n%4$s</string>
<string name="server_details_dialog_title">Lokales Backend</string>
<string name="welcome_migration_dialog_title">Willkommen in unserer neuen App 👋</string>
<string name="welcome_migration_dialog_content">Wir haben die App überarbeitet, um sie für alle benutzerfreundlicher zu machen.\n\nErfahren Sie mehr über die neu gestaltete App – zusätzliche Optionen und verbesserte Barrierefreiheit bei gleichbleibend hoher Sicherheit.</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<string name="welcome_screen_carousel_item_message_5">Wire is independently audited and ISO, CCPA, GDPR, SOX-compliant</string>
<string name="welcome_button_create_team">Create a Team</string>
<string name="server_details_dialog_body">Backend name:\n%1$s\n\nBackend URL:\n%2$s</string>
<string name="server_details_dialog_body_with_proxy">Backend name:\n%1$s\n\nBackend URL:\n%2$s\n\nProxy URL:\n%3$s\n\nProxy authentication:\n%4$s</string>
<string name="server_details_dialog_title">On-premises Backend</string>
<string name="welcome_migration_dialog_title">Welcome To Our New Android App 👋</string>
<string name="welcome_migration_dialog_content">We rebuilt the app to make it more usable for everyone.\n\nFind out more about Wire’s redesigned app—new options and improved accessibility, with the same strong security.</string>
Expand Down Expand Up @@ -1013,6 +1014,8 @@
<string name="custom_backend_dialog_body">If you proceed, your client will be redirected to the following on-premises backend:</string>
<string name="custom_backend_dialog_body_backend_name">Backend name:</string>
<string name="custom_backend_dialog_body_backend_api">Backend URL:</string>
<string name="custom_backend_dialog_body_backend_proxy_url">Proxy URL:</string>
<string name="custom_backend_dialog_body_backend_proxy_authentication">Proxy authentication:</string>
<string name="custom_backend_dialog_body_backend_blacklist">Blacklist URL:</string>
<string name="custom_backend_dialog_body_backend_teams">Teams URL:</string>
<string name="custom_backend_dialog_body_backend_accounts">Accounts URL:</string>
Expand Down
Loading

0 comments on commit 01a0da9

Please sign in to comment.