-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Login Flow v1 #14461
Remove Login Flow v1 #14461
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,25 +24,17 @@ | |
import android.content.ServiceConnection; | ||
import android.content.SharedPreferences; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Color; | ||
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.IBinder; | ||
import android.preference.PreferenceManager; | ||
import android.text.TextUtils; | ||
import android.util.AndroidRuntimeException; | ||
import android.view.KeyEvent; | ||
import android.view.View; | ||
import android.view.inputmethod.EditorInfo; | ||
import android.webkit.CookieManager; | ||
import android.webkit.CookieSyncManager; | ||
import android.webkit.URLUtil; | ||
import android.webkit.WebResourceRequest; | ||
import android.webkit.WebResourceResponse; | ||
import android.webkit.WebView; | ||
import android.widget.AdapterView; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.LinearLayout; | ||
|
@@ -77,8 +69,6 @@ | |
import com.owncloud.android.databinding.AccountSetupWebviewBinding; | ||
import com.owncloud.android.datamodel.FileDataStorageManager; | ||
import com.owncloud.android.lib.common.OwnCloudAccount; | ||
import com.owncloud.android.lib.common.OwnCloudClient; | ||
import com.owncloud.android.lib.common.OwnCloudClientFactory; | ||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; | ||
import com.owncloud.android.lib.common.OwnCloudCredentials; | ||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; | ||
|
@@ -92,9 +82,6 @@ | |
import com.owncloud.android.lib.common.operations.RemoteOperationResult; | ||
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; | ||
import com.owncloud.android.lib.common.utils.Log_OC; | ||
import com.owncloud.android.lib.resources.status.GetCapabilitiesRemoteOperation; | ||
import com.owncloud.android.lib.resources.status.NextcloudVersion; | ||
import com.owncloud.android.lib.resources.status.OCCapability; | ||
import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||
import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation; | ||
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod; | ||
|
@@ -103,7 +90,6 @@ | |
import com.owncloud.android.providers.DocumentsStorageProvider; | ||
import com.owncloud.android.services.OperationsService; | ||
import com.owncloud.android.services.OperationsService.OperationsServiceBinder; | ||
import com.owncloud.android.ui.NextcloudWebViewClient; | ||
import com.owncloud.android.ui.activity.FileDisplayActivity; | ||
import com.owncloud.android.ui.activity.SettingsActivity; | ||
import com.owncloud.android.ui.dialog.IndeterminateProgressDialog; | ||
|
@@ -112,18 +98,14 @@ | |
import com.owncloud.android.utils.DisplayUtils; | ||
import com.owncloud.android.utils.ErrorMessageAdapter; | ||
import com.owncloud.android.utils.PermissionUtil; | ||
import com.owncloud.android.utils.WebViewUtil; | ||
import com.owncloud.android.utils.theme.CapabilityUtils; | ||
import com.owncloud.android.utils.theme.ViewThemeUtils; | ||
|
||
import org.json.JSONObject; | ||
|
||
import java.io.InputStream; | ||
import java.net.URLDecoder; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.Executors; | ||
|
@@ -134,12 +116,10 @@ | |
|
||
import androidx.activity.result.ActivityResultLauncher; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.VisibleForTesting; | ||
import androidx.appcompat.app.ActionBar; | ||
import androidx.core.content.ContextCompat; | ||
import androidx.fragment.app.DialogFragment; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.fragment.app.FragmentManager; | ||
|
@@ -188,14 +168,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity | |
private static final String KEY_PASSWORD = "PASSWORD"; | ||
private static final String KEY_ASYNC_TASK_IN_PROGRESS = "AUTH_IN_PROGRESS"; | ||
|
||
/** | ||
* Login Flow v1 | ||
*/ | ||
// public static final String WEB_LOGIN = "/index.php/login/flow"; | ||
|
||
/** | ||
* Login Flow v2 | ||
*/ | ||
public static final String WEB_LOGIN = "/index.php/login/v2"; | ||
|
||
public static final String PROTOCOL_SUFFIX = "://"; | ||
|
@@ -253,9 +225,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity | |
private String token; | ||
|
||
private boolean onlyAdd = false; | ||
@SuppressLint("ResourceAsColor") @ColorInt | ||
private int primaryColor = R.color.primary; | ||
private boolean strictMode = false; | ||
|
||
private ViewThemeUtils viewThemeUtils; | ||
|
||
|
@@ -275,8 +244,6 @@ protected void onCreate(Bundle savedInstanceState) { | |
viewThemeUtils = viewThemeUtilsFactory.withPrimaryAsBackground(); | ||
viewThemeUtils.platform.colorStatusBar(this, getResources().getColor(R.color.primary)); | ||
|
||
// WebViewUtil webViewUtil = new WebViewUtil(this); | ||
|
||
Uri data = getIntent().getData(); | ||
boolean directLogin = data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme)); | ||
if (savedInstanceState == null && !directLogin) { | ||
|
@@ -343,7 +310,6 @@ protected void onCreate(Bundle savedInstanceState) { | |
accountSetupWebviewBinding = AccountSetupWebviewBinding.inflate(getLayoutInflater()); | ||
setContentView(accountSetupWebviewBinding.getRoot()); | ||
anonymouslyPostLoginRequest(webloginUrl); | ||
// initWebViewLogin(webloginUrl, false); | ||
} else { | ||
accountSetupBinding = AccountSetupBinding.inflate(getLayoutInflater()); | ||
setContentView(accountSetupBinding.getRoot()); | ||
|
@@ -362,13 +328,10 @@ protected void onCreate(Bundle savedInstanceState) { | |
|
||
initServerPreFragment(savedInstanceState); | ||
ProcessLifecycleOwner.get().getLifecycle().addObserver(lifecycleEventObserver); | ||
|
||
// webViewUtil.checkWebViewVersion(); | ||
} | ||
} | ||
|
||
private void showEnforcedServers() { | ||
|
||
showAuthStatus(); | ||
accountSetupBinding.hostUrlFrame.setVisibility(View.GONE); | ||
accountSetupBinding.hostUrlInputHelperText.setVisibility(View.GONE); | ||
|
@@ -421,9 +384,8 @@ public void onNothingSelected(AdapterView<?> parent) { | |
|
||
private void deleteCookies() { | ||
try { | ||
CookieSyncManager.createInstance(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to use CookieSyncManager. Document |
||
CookieManager.getInstance().removeAllCookies(null); | ||
} catch (AndroidRuntimeException e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Android 8, if the device has WebView Shell as the default web browser.
This function will throw the IllegalArgumentException. |
||
} catch (Exception e) { | ||
Log_OC.e(TAG, e.getMessage()); | ||
} | ||
} | ||
|
@@ -485,124 +447,15 @@ private void launchDefaultWebBrowser(String url) { | |
startActivity(intent); | ||
} | ||
|
||
private static String getWebLoginUserAgent() { | ||
return Build.MANUFACTURER.substring(0, 1).toUpperCase(Locale.getDefault()) + | ||
Build.MANUFACTURER.substring(1).toLowerCase(Locale.getDefault()) + " " + Build.MODEL + " (Android)"; | ||
} | ||
|
||
/** | ||
* @Deprecated This function is deprecated. Please use the {@link #anonymouslyPostLoginRequest(String)} method instead, which utilizes the improved login flow v2. | ||
*/ | ||
@Deprecated | ||
@SuppressFBWarnings("ANDROID_WEB_VIEW_JAVASCRIPT") | ||
@SuppressLint("SetJavaScriptEnabled") | ||
private void initWebViewLogin(String baseURL, boolean useGenericUserAgent) { | ||
viewThemeUtils.platform.colorCircularProgressBar(accountSetupWebviewBinding.loginWebviewProgressBar, ColorRole.ON_PRIMARY_CONTAINER); | ||
accountSetupWebviewBinding.loginWebview.setVisibility(View.GONE); | ||
new WebViewUtil(this).setProxyKKPlus(accountSetupWebviewBinding.loginWebview); | ||
|
||
accountSetupWebviewBinding.loginWebview.getSettings().setAllowFileAccess(false); | ||
accountSetupWebviewBinding.loginWebview.getSettings().setJavaScriptEnabled(true); | ||
accountSetupWebviewBinding.loginWebview.getSettings().setDomStorageEnabled(true); | ||
|
||
if (useGenericUserAgent) { | ||
accountSetupWebviewBinding.loginWebview.getSettings().setUserAgentString(MainApp.getUserAgent()); | ||
} else { | ||
accountSetupWebviewBinding.loginWebview.getSettings().setUserAgentString(getWebLoginUserAgent()); | ||
} | ||
accountSetupWebviewBinding.loginWebview.getSettings().setSaveFormData(false); | ||
accountSetupWebviewBinding.loginWebview.getSettings().setSavePassword(false); | ||
|
||
Map<String, String> headers = new HashMap<>(); | ||
headers.put(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE); | ||
|
||
String url; | ||
if (baseURL != null && !baseURL.isEmpty()) { | ||
url = baseURL; | ||
} else { | ||
url = getResources().getString(R.string.webview_login_url); | ||
} | ||
|
||
new WebViewUtil(this).setProxyKKPlus(accountSetupWebviewBinding.loginWebview); | ||
if (url.startsWith(HTTPS_PROTOCOL)) { | ||
strictMode = true; | ||
} | ||
|
||
accountSetupWebviewBinding.loginWebview.loadUrl(url, headers); | ||
|
||
setClient(); | ||
} | ||
|
||
@Override | ||
public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
if (accountSetupWebviewBinding != null && event.getAction() == KeyEvent.ACTION_DOWN && | ||
keyCode == KeyEvent.KEYCODE_BACK) { | ||
if (accountSetupWebviewBinding.loginWebview.canGoBack()) { | ||
accountSetupWebviewBinding.loginWebview.goBack(); | ||
} else { | ||
finish(); | ||
} | ||
return true; | ||
} | ||
return super.onKeyDown(keyCode, event); | ||
} | ||
|
||
private void setClient() { | ||
accountSetupWebviewBinding.loginWebview.setWebViewClient(new NextcloudWebViewClient(getSupportFragmentManager()) { | ||
@Override | ||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { | ||
return super.shouldInterceptRequest(view, request); | ||
} | ||
|
||
@Override | ||
public void onPageStarted(WebView view, String url, Bitmap favicon) { | ||
super.onPageStarted(view, url, favicon); | ||
} | ||
|
||
@Override | ||
public boolean shouldOverrideUrlLoading(WebView view, String url) { | ||
if (url.startsWith(getString(R.string.login_data_own_scheme) + PROTOCOL_SUFFIX + "login/")) { | ||
parseAndLoginFromWebView(url); | ||
return true; | ||
} | ||
if (strictMode && url.startsWith(HTTP_PROTOCOL)) { | ||
Snackbar.make(view, R.string.strict_mode, Snackbar.LENGTH_LONG).show(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onPageFinished(WebView view, String url) { | ||
super.onPageFinished(view, url); | ||
|
||
accountSetupWebviewBinding.loginWebviewProgressBar.setVisibility(View.GONE); | ||
accountSetupWebviewBinding.loginWebview.setVisibility(View.VISIBLE); | ||
|
||
if (mServerInfo.mVersion != null && mServerInfo.mVersion.isOlderThan(NextcloudVersion.nextcloud_25)) { | ||
viewThemeUtils.platform.colorStatusBar(AuthenticatorActivity.this, primaryColor); | ||
getWindow().setNavigationBarColor(primaryColor); | ||
} else { | ||
viewThemeUtils.platform.resetStatusBar(AuthenticatorActivity.this); | ||
getWindow().setNavigationBarColor(ContextCompat.getColor(AuthenticatorActivity.this, R.color.bg_default)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { | ||
accountSetupWebviewBinding.loginWebviewProgressBar.setVisibility(View.GONE); | ||
accountSetupWebviewBinding.loginWebview.setVisibility(View.VISIBLE); | ||
|
||
InputStream resources = getResources().openRawResource(R.raw.custom_error); | ||
String customError = DisplayUtils.getData(resources); | ||
|
||
if (!customError.isEmpty()) { | ||
accountSetupWebviewBinding.loginWebview.loadData(customError, "text/html; charset=UTF-8", null); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void parseAndLoginFromWebView(String dataString) { | ||
try { | ||
String prefix = getString(R.string.login_data_own_scheme) + PROTOCOL_SUFFIX + "login/"; | ||
|
@@ -826,7 +679,6 @@ protected void onNewIntent(Intent intent) { | |
accountSetupWebviewBinding = AccountSetupWebviewBinding.inflate(getLayoutInflater()); | ||
setContentView(accountSetupWebviewBinding.getRoot()); | ||
anonymouslyPostLoginRequest(getString(R.string.provider_registration_server)); | ||
// initWebViewLogin(getString(R.string.provider_registration_server), true); | ||
} | ||
} | ||
|
||
|
@@ -900,7 +752,7 @@ private void checkOcServer() { | |
|
||
mServerInfo = new GetServerInfoOperation.ServerInfo(); | ||
|
||
if (uri.length() != 0) { | ||
if (!uri.isEmpty()) { | ||
if (accountSetupBinding != null) { | ||
uri = AuthenticatorUrlUtils.INSTANCE.stripIndexPhpOrAppsFiles(uri); | ||
accountSetupBinding.hostUrlInput.setText(uri); | ||
|
@@ -1043,24 +895,6 @@ private void onGetServerInfoFinish(RemoteOperationResult result) { | |
webViewPassword != null && !webViewPassword.isEmpty()) { | ||
checkBasicAuthorization(webViewUser, webViewPassword); | ||
} else { | ||
new Thread(() -> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This remote operation is only used for the primaryColor. Since primaryColor is not used, no need for this remote operation. |
||
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mServerInfo.mBaseUrl), | ||
this, | ||
true); | ||
RemoteOperationResult remoteOperationResult = new GetCapabilitiesRemoteOperation().execute(client); | ||
|
||
if (remoteOperationResult.isSuccess() && | ||
remoteOperationResult.getData() != null && | ||
remoteOperationResult.getData().size() > 0) { | ||
OCCapability capability = (OCCapability) remoteOperationResult.getData().get(0); | ||
try { | ||
primaryColor = Color.parseColor(capability.getServerColor()); | ||
} catch (Exception e) { | ||
// falls back to primary color | ||
} | ||
} | ||
}).start(); | ||
|
||
accountSetupWebviewBinding = AccountSetupWebviewBinding.inflate(getLayoutInflater()); | ||
setContentView(accountSetupWebviewBinding.getRoot()); | ||
|
||
|
@@ -1071,7 +905,6 @@ private void onGetServerInfoFinish(RemoteOperationResult result) { | |
} else { | ||
initLoginInfoView(); | ||
} | ||
// initWebViewLogin(mServerInfo.mBaseUrl + WEB_LOGIN, false); | ||
} | ||
} | ||
} else { | ||
|
@@ -1310,10 +1143,6 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult<UserInfo> result) | |
accountManager.setCurrentOwnCloudAccount(mAccount.name); | ||
getUserCapabilitiesAndFinish(); | ||
} else { | ||
// init webView again | ||
if (accountSetupWebviewBinding != null) { | ||
accountSetupWebviewBinding.loginWebview.setVisibility(View.GONE); | ||
} | ||
accountSetupBinding = AccountSetupBinding.inflate(getLayoutInflater()); | ||
setContentView(accountSetupBinding.getRoot()); | ||
initOverallUi(); | ||
|
@@ -1341,10 +1170,6 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult<UserInfo> result) | |
} else { // authorization fail due to client side - probably wrong credentials | ||
if (accountSetupWebviewBinding != null) { | ||
anonymouslyPostLoginRequest(mServerInfo.mBaseUrl + WEB_LOGIN); | ||
// initWebViewLogin(mServerInfo.mBaseUrl + WEB_LOGIN, false); | ||
DisplayUtils.showSnackMessage(this, | ||
accountSetupWebviewBinding.loginWebview, R.string.auth_access_failed, | ||
result.getLogMessage(this)); | ||
} else { | ||
DisplayUtils.showSnackMessage(this, R.string.auth_access_failed, result.getLogMessage(this)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused variable after removing the login flow v1