diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 09939cd92a30..5b07cdbaa6a0 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -59,6 +59,9 @@
+
+
+
@@ -204,4 +207,4 @@
-
\ No newline at end of file
+
diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt
index 27384974685c..662d98cc9235 100644
--- a/scripts/analysis/findbugs-results.txt
+++ b/scripts/analysis/findbugs-results.txt
@@ -1 +1 @@
-439
\ No newline at end of file
+436
\ No newline at end of file
diff --git a/src/gplay/AndroidManifest.xml b/src/gplay/AndroidManifest.xml
index 6bb71ae93184..4334383cbc53 100644
--- a/src/gplay/AndroidManifest.xml
+++ b/src/gplay/AndroidManifest.xml
@@ -40,14 +40,6 @@
android:exported="true"
android:launchMode="singleTask"
android:theme="@style/Theme.ownCloud.noActionBar.Login">
-
-
-
-
-
-
-
-
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 22c82a839a1d..81dc3fb74e8b 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -265,14 +265,6 @@
android:launchMode="singleTask"
android:configChanges="orientation|screenSize|keyboardHidden"
android:theme="@style/Theme.ownCloud.noActionBar.Login">
-
-
-
-
-
-
-
-
diff --git a/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java b/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java
index 8d43e8e92c81..d4cc84d65afc 100644
--- a/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java
+++ b/src/main/java/com/nextcloud/client/account/UserAccountManagerImpl.java
@@ -170,23 +170,6 @@ private Account migrateAccount(Context context, Account currentAccount, AccountM
accountMgr.getUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_COOKIES)
);
- // copy type of authentication
- final String isSamlStr = accountMgr.getUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO);
- if (Boolean.parseBoolean(isSamlStr)) {
- accountMgr.setUserData(newAccount, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
- }
-
- final String isOauthStr = accountMgr.getUserData(account, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_SUPPORTS_OAUTH2);
- if (Boolean.parseBoolean(isOauthStr)) {
- accountMgr.setUserData(newAccount, com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
- }
-
- /* TODO - study if it's possible to run this method in a background thread to copy the authToken
- if (isOAuth || isSaml) {
- accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken);
- }
- */
-
// don't forget the account saved in preferences as the current one
if (currentAccount.name.equals(account.name)) {
AccountUtils.setCurrentOwnCloudAccount(context, newAccountName);
diff --git a/src/main/java/com/owncloud/android/MainApp.java b/src/main/java/com/owncloud/android/MainApp.java
index 11940eedfcba..9dce6bb6bead 100644
--- a/src/main/java/com/owncloud/android/MainApp.java
+++ b/src/main/java/com/owncloud/android/MainApp.java
@@ -64,7 +64,6 @@
import com.owncloud.android.jobs.MediaFoldersDetectionJob;
import com.owncloud.android.jobs.NCJobCreator;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.activity.ContactsPreferenceActivity;
@@ -198,16 +197,8 @@ public void onCreate() {
MainApp.storagePath = preferences.getStoragePath(getApplicationContext().getFilesDir().getAbsolutePath());
- boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
-
OwnCloudClientManagerFactory.setUserAgent(getUserAgent());
OwnCloudClientManagerFactory.setNextcloudUserAgent(getNextcloudUserAgent());
- if (isSamlAuth) {
- OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
- } else {
- OwnCloudClientManagerFactory
- .setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT_IF_SERVER_SUPPORTS_SERVER_MONITORING);
- }
// initialise thumbnails cache on background thread
new ThumbnailsCacheManager.InitDiskCacheTask().execute();
diff --git a/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java b/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java
index fb9bed184912..8cd5d4afa207 100644
--- a/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java
+++ b/src/main/java/com/owncloud/android/authentication/AccountAuthenticator.java
@@ -40,15 +40,15 @@
/**
* Authenticator for ownCloud accounts.
- *
+ *
* Controller class accessed from the system AccountManager,
* providing integration of ownCloud accounts with the Android system.
- *
+ *
* TODO - better separation in operations for OAuth-capable and regular ownCloud accounts.
* TODO - review completeness
*/
public class AccountAuthenticator extends AbstractAccountAuthenticator {
-
+
/**
* Is used by android system to assign accounts to authenticators.
* Should be used by application and all extensions.
@@ -59,9 +59,9 @@ public class AccountAuthenticator extends AbstractAccountAuthenticator {
public static final String KEY_ACCOUNT = "account";
private static final String TAG = AccountAuthenticator.class.getSimpleName();
-
+
private Context mContext;
-
+
private Handler mHandler;
public AccountAuthenticator(Context context) {
@@ -101,17 +101,17 @@ public Bundle addAccount(AccountAuthenticatorResponse response,
intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE);
setIntentFlags(intent);
-
+
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
} else {
// Return an error
bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
- final String message = String.format(mContext.getString(R.string.auth_unsupported_multiaccount), mContext.getString(R.string.app_name));
+ final String message = String.format(mContext.getString(R.string.auth_unsupported_multiaccount), mContext.getString(R.string.app_name));
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, message);
-
+
mHandler.post(() -> Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show());
}
-
+
return bundle;
}
@@ -160,7 +160,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response,
Log_OC.e(TAG, "Failed to validate account type " + account.type + ": " + e.getMessage(), e);
return e.getFailureBundle();
}
-
+
/// check if required token is stored
final AccountManager am = AccountManager.get(mContext);
String accessToken;
@@ -176,7 +176,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response,
result.putString(AccountManager.KEY_AUTHTOKEN, accessToken);
return result;
}
-
+
/// if not stored, return Intent to access the AuthenticatorActivity and UPDATE the token for the account
Intent intent = new Intent(mContext, AuthenticatorActivity.class);
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
@@ -184,7 +184,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response,
intent.putExtra(KEY_LOGIN_OPTIONS, options);
intent.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account);
intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
-
+
final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
@@ -242,10 +242,7 @@ private void validateAuthTokenType(String authTokenType) throws UnsupportedAuthT
String accountType = MainApp.getAccountType(mContext);
if (!authTokenType.equals(accountType) &&
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(accountType)) &&
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeAccessToken(accountType)) &&
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeRefreshToken(accountType)) &&
- !authTokenType.equals(AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType))) {
+ !authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(accountType))) {
throw new UnsupportedAuthTokenTypeException();
}
}
diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java
index 649736fbf94b..8580d1e0dd4e 100644
--- a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java
+++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java
@@ -44,7 +44,6 @@
import android.accounts.Account;
import android.accounts.AccountManager;
import android.annotation.SuppressLint;
-import android.app.Dialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -55,6 +54,7 @@
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
@@ -78,7 +78,6 @@
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
-import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
@@ -91,13 +90,11 @@
import com.nextcloud.client.account.UserAccountManager;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
-import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.OwnCloudCredentials;
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.UserInfo;
-import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
@@ -111,7 +108,6 @@
import com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation;
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;
import com.owncloud.android.operations.GetServerInfoOperation;
-import com.owncloud.android.operations.OAuth2GetAccessToken;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
import com.owncloud.android.ui.activity.FileDisplayActivity;
@@ -119,16 +115,18 @@
import com.owncloud.android.ui.components.CustomEditText;
import com.owncloud.android.ui.dialog.CredentialsDialogFragment;
import com.owncloud.android.ui.dialog.IndeterminateProgressDialog;
-import com.owncloud.android.ui.dialog.SamlWebViewDialog;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
import com.owncloud.android.utils.DisplayUtils;
import com.owncloud.android.utils.ErrorMessageAdapter;
import com.owncloud.android.utils.PermissionUtil;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLDecoder;
-import java.security.SecureRandom;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Locale;
@@ -148,8 +146,7 @@
* This Activity is used to add an ownCloud account to the App
*/
public class AuthenticatorActivity extends AccountAuthenticatorActivity
- implements OnRemoteOperationListener, OnFocusChangeListener, OnEditorActionListener,
- SsoWebViewClientListener, OnSslUntrustedCertListener,
+ implements OnRemoteOperationListener, OnFocusChangeListener, OnEditorActionListener, OnSslUntrustedCertListener,
AuthenticatorAsyncTask.OnAuthenticatorTaskListener {
private static final String TAG = AuthenticatorActivity.class.getSimpleName();
@@ -158,8 +155,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_USE_PROVIDER_AS_WEBLOGIN = "USE_PROVIDER_AS_WEBLOGIN";
- private static final String KEY_AUTH_TOKEN_TYPE = "AUTH_TOKEN_TYPE";
-
private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";
private static final String KEY_OC_VERSION = "OC_VERSION";
private static final String KEY_SERVER_VALID = "SERVER_VALID";
@@ -174,14 +169,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";
private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN";
- private static final String AUTH_ON = "on";
- private static final String AUTH_OPTIONAL = "optional";
-
public static final byte ACTION_CREATE = 0;
public static final byte ACTION_UPDATE_EXPIRED_TOKEN = 2; // detected by the app
private static final String UNTRUSTED_CERT_DIALOG_TAG = "UNTRUSTED_CERT_DIALOG";
- private static final String SAML_DIALOG_TAG = "SAML_DIALOG";
private static final String WAIT_DIALOG_TAG = "WAIT_DIALOG";
private static final String CREDENTIALS_DIALOG_TAG = "CREDENTIALS_DIALOG";
private static final String KEY_AUTH_IS_FIRST_ATTEMPT_TAG = "KEY_AUTH_IS_FIRST_ATTEMPT";
@@ -208,14 +199,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
/// parameters from EXTRAs in starter Intent
private byte mAction;
private Account mAccount;
- private String mAuthTokenType;
/// activity-level references / state
private final Handler mHandler = new Handler();
private ServiceConnection mOperationsServiceConnection;
private OperationsServiceBinder mOperationsServiceBinder;
private AccountManager mAccountMgr;
- private Uri mNewCapturedUriFromOAuth2Redirection;
/// Server PRE-Fragment elements
private CustomEditText mHostUrlInput;
@@ -232,9 +221,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
private GetServerInfoOperation.ServerInfo mServerInfo = new GetServerInfoOperation.ServerInfo();
/// Authentication PRE-Fragment elements
- private CheckBox mOAuth2Check;
- private TextView mOAuthAuthEndpointText;
- private TextView mOAuthTokenEndpointText;
private EditText mUsernameInput;
private EditText mPasswordInput;
private View mOkButton;
@@ -254,10 +240,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
/// Identifier of operation in progress which result shouldn't be lost
private long mWaitingForOpId = Long.MAX_VALUE;
- private String basicTokenType;
- private String oauthTokenType;
- private String samlTokenType;
-
private boolean webViewLoginMethod;
private String webViewUser;
private String webViewPassword;
@@ -284,10 +266,6 @@ protected void onCreate(Bundle savedInstanceState) {
FirstRunActivity.runIfNeeded(this);
}
- basicTokenType = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType(this));
- oauthTokenType = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this));
- samlTokenType = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this));
-
// delete cookies for webView
deleteCookies();
@@ -304,15 +282,11 @@ protected void onCreate(Bundle savedInstanceState) {
/// init activity state
mAccountMgr = AccountManager.get(this);
- mNewCapturedUriFromOAuth2Redirection = null;
/// get input values
mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE);
mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);
- if (savedInstanceState == null) {
- initAuthTokenType();
- } else {
- mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE);
+ if (savedInstanceState != null) {
mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID);
mIsFirstAuthAttempt = savedInstanceState.getBoolean(KEY_AUTH_IS_FIRST_ATTEMPT_TAG);
}
@@ -428,7 +402,6 @@ private void initWebViewLogin(String baseURL, boolean showLegacyLogin, boolean u
mPasswordInputLayout.setVisibility(View.VISIBLE);
mUsernameInputLayout.setVisibility(View.VISIBLE);
mUsernameInput.requestFocus();
- mOAuth2Check.setVisibility(View.INVISIBLE);
mAuthStatusView.setVisibility(View.INVISIBLE);
mServerStatusView.setVisibility(View.INVISIBLE);
mTestServerButton.setVisibility(View.INVISIBLE);
@@ -486,7 +459,7 @@ public void onPageFinished(WebView view, String url) {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
- X509Certificate cert = SsoWebViewClient.getX509CertificateFromError(error);
+ X509Certificate cert = getX509CertificateFromError(error);
try {
if (cert != null && NetworkUtils.isCertInKnownServersStore(cert, getApplicationContext())) {
@@ -591,39 +564,6 @@ public static LoginUrlInfo parseLoginDataUrl(String prefix, String dataString) t
return loginUrlInfo;
}
- private void initAuthTokenType() {
- Bundle extras = getIntent().getExtras();
- mAuthTokenType = null;
-
- if (extras != null) {
- mAuthTokenType = extras.getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);
- }
-
- if (mAuthTokenType == null) {
- if (mAccount != null) {
- boolean oAuthRequired = mAccountMgr.getUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2) != null;
- boolean samlWebSsoRequired = mAccountMgr.getUserData
- (mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
- mAuthTokenType = chooseAuthTokenType(oAuthRequired, samlWebSsoRequired);
- } else {
- boolean oAuthSupported = AUTH_ON.equals(getString(R.string.auth_method_oauth2));
- boolean samlWebSsoSupported = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
- mAuthTokenType = chooseAuthTokenType(oAuthSupported, samlWebSsoSupported);
- }
- }
- }
-
- private String chooseAuthTokenType(boolean oauth, boolean saml) {
- if (saml) {
- return samlTokenType;
- } else if (oauth) {
- return oauthTokenType;
- } else {
- return basicTokenType;
- }
- }
-
-
/**
* Configures elements in the user interface under direct control of the Activity.
*/
@@ -634,7 +574,6 @@ private void initOverallUi() {
mPasswordInput = findViewById(R.id.account_password);
mUsernameInput = findViewById(R.id.account_username);
mAuthStatusView = findViewById(R.id.auth_status_text);
- mOAuth2Check = findViewById(R.id.oauth_onOff_check);
mServerStatusView = findViewById(R.id.server_status_text);
mTestServerButton = findViewById(R.id.testServerButton);
@@ -650,35 +589,18 @@ private void initOverallUi() {
private void setupInstructionMessage() {
- String instructionsMessageText = calculateInstructionMessageText(mAction, mAuthTokenType);
TextView instructionsView = findViewById(R.id.instructions_message);
- if (instructionsMessageText != null) {
+ if (mAction == ACTION_UPDATE_EXPIRED_TOKEN) {
instructionsView.setVisibility(View.VISIBLE);
+
+ String instructionsMessageText = getString(R.string.auth_expired_basic_auth_toast);
instructionsView.setText(instructionsMessageText);
} else {
instructionsView.setVisibility(View.GONE);
}
}
- @Nullable
- private String calculateInstructionMessageText(byte action, String authTokenType) {
- if (action == ACTION_UPDATE_EXPIRED_TOKEN) {
- if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(authTokenType)) {
- return getString(R.string.auth_expired_oauth_token_toast);
-
- } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this))
- .equals(authTokenType)) {
- return getString(R.string.auth_expired_saml_sso_token_toast);
-
- } else {
- return getString(R.string.auth_expired_basic_auth_toast);
- }
- }
-
- return null;
- }
-
public void onTestServerConnectionClick(View v) {
checkOcServer();
}
@@ -776,31 +698,15 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
};
-
-
- // TODO find out if this is really necessary, or if it can done in a different way
- findViewById(R.id.scroll).setOnTouchListener((view, event) -> {
- if (event.getAction() == MotionEvent.ACTION_DOWN &&
- AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(
- MainApp.getAccountType(getBaseContext())).equals(mAuthTokenType) &&
- mHostUrlInput.hasFocus()) {
- checkOcServer();
- }
- return false;
- });
}
}
-
/**
* @param savedInstanceState Saved activity state, as in {{@link #onCreate(Bundle)}
*/
private void initAuthorizationPreFragment(Bundle savedInstanceState) {
/// step 0 - get UI elements in layout
- mOAuth2Check = findViewById(R.id.oauth_onOff_check);
- mOAuthAuthEndpointText = findViewById(R.id.oAuthEntryPoint_1);
- mOAuthTokenEndpointText = findViewById(R.id.oAuthEntryPoint_2);
mUsernameInput = findViewById(R.id.account_username);
mPasswordInput = findViewById(R.id.account_password);
mAuthStatusView = findViewById(R.id.auth_status_text);
@@ -820,8 +726,6 @@ private void initAuthorizationPreFragment(Bundle savedInstanceState) {
}
/// step 2 - set properties of UI elements (text, visibility, enabled...)
- mOAuth2Check.setChecked(
- AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType));
if (presetUserName != null) {
mUsernameInput.setText(presetUserName);
}
@@ -833,7 +737,6 @@ private void initAuthorizationPreFragment(Bundle savedInstanceState) {
if (isPasswordExposed) {
showPassword();
}
- updateAuthenticationPreFragmentVisibility();
showAuthStatus();
mOkButton.setEnabled(mServerIsValid);
@@ -855,53 +758,9 @@ public boolean onDrawableTouch(final MotionEvent event) {
}
-
- /**
- * Changes the visibility of input elements depending on
- * the current authorization method.
- */
- private void updateAuthenticationPreFragmentVisibility() {
- if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
- // SAML-based web Single Sign On
- mOAuth2Check.setVisibility(View.GONE);
- mOAuthAuthEndpointText.setVisibility(View.GONE);
- mOAuthTokenEndpointText.setVisibility(View.GONE);
- mUsernameInput.setVisibility(View.GONE);
- mPasswordInput.setVisibility(View.GONE);
-
- } else {
- if (mAction == ACTION_CREATE &&
- AUTH_OPTIONAL.equals(getString(R.string.auth_method_oauth2))) {
- mOAuth2Check.setVisibility(View.VISIBLE);
- } else {
- mOAuth2Check.setVisibility(View.GONE);
- }
-
- if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
- // OAuth 2 authorization
- mOAuthAuthEndpointText.setVisibility(View.VISIBLE);
- mOAuthTokenEndpointText.setVisibility(View.VISIBLE);
- mUsernameInput.setVisibility(View.GONE);
- mPasswordInput.setVisibility(View.GONE);
-
- } else {
- // basic HTTP authorization
- mOAuthAuthEndpointText.setVisibility(View.GONE);
- mOAuthTokenEndpointText.setVisibility(View.GONE);
- mUsernameInput.setVisibility(View.VISIBLE);
- mPasswordInput.setVisibility(View.VISIBLE);
- }
- }
- }
-
-
/**
* Saves relevant state before {@link #onPause()}
*
- * Do NOT save {@link #mNewCapturedUriFromOAuth2Redirection}; it keeps a temporal flag,
- * intended to defer the processing of the redirection caught in
- * {@link #onNewIntent(Intent)} until {@link #onResume()}
- *
* See {@link super#onSaveInstanceState(Bundle)}
*/
@Override
@@ -910,7 +769,6 @@ protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
/// global state
- outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType);
outState.putLong(KEY_WAITING_FOR_OP_ID, mWaitingForOpId);
if (!webViewLoginMethod) {
@@ -966,14 +824,7 @@ public void onRestoreInstanceState(Bundle savedInstanceState) {
String username = savedInstanceState.getString(KEY_USERNAME);
String password = savedInstanceState.getString(KEY_PASSWORD);
- OwnCloudCredentials credentials = null;
- if (basicTokenType.equals(mAuthTokenType)) {
- credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
-
- } else if (oauthTokenType.equals(mAuthTokenType)) {
- credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);
-
- }
+ OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
accessRootFolder(credentials);
}
}
@@ -994,9 +845,6 @@ protected void onNewIntent(Intent intent) {
}
Uri data = intent.getData();
- if (data != null && data.toString().startsWith(getString(R.string.oauth2_redirect_uri))) {
- mNewCapturedUriFromOAuth2Redirection = data;
- }
if (data != null && data.toString().startsWith(getString(R.string.login_data_own_scheme))) {
parseAndLoginFromWebView(data.toString());
@@ -1024,10 +872,6 @@ protected void onResume() {
mHostUrlInput.setOnFocusChangeListener(this);
mHostUrlInput.addTextChangedListener(mHostUrlInputWatcher);
- if (mNewCapturedUriFromOAuth2Redirection != null) {
- getOAuth2AccessTokenFromCapturedRedirection();
- }
-
String dataString = getIntent().getDataString();
if (dataString != null) {
try {
@@ -1085,39 +929,6 @@ protected void onDestroy() {
super.onDestroy();
}
- /**
- * Parses the redirection with the response to the GET AUTHORIZATION request to the
- * oAuth server and requests for the access token (GET ACCESS TOKEN)
- */
- private void getOAuth2AccessTokenFromCapturedRedirection() {
- /// Parse data from OAuth redirection
- String queryParameters = mNewCapturedUriFromOAuth2Redirection.getQuery();
- mNewCapturedUriFromOAuth2Redirection = null;
-
- /// Showing the dialog with instructions for the user.
- IndeterminateProgressDialog dialog =
- IndeterminateProgressDialog.newInstance(R.string.auth_getting_authorization, true);
- dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
-
- /// GET ACCESS TOKEN to the oAuth server
- Intent getServerInfoIntent = new Intent();
- getServerInfoIntent.setAction(OperationsService.ACTION_OAUTH2_GET_ACCESS_TOKEN);
-
- getServerInfoIntent.putExtra(
- OperationsService.EXTRA_SERVER_URL,
- mOAuthTokenEndpointText.getText().toString().trim());
-
- getServerInfoIntent.putExtra(
- OperationsService.EXTRA_OAUTH2_QUERY_PARAMETERS,
- queryParameters);
-
- if (mOperationsServiceBinder != null) {
- //Log_OC.e(TAG, "getting access token..." );
- mWaitingForOpId = mOperationsServiceBinder.queueNewOperation(getServerInfoIntent);
- }
- }
-
-
/**
* Handles the change of focus on the text inputs for the server URL and the password
*/
@@ -1289,14 +1100,7 @@ public void onOkClick() {
return;
}
- if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType(this)).equals(mAuthTokenType)) {
- startOauthorization();
- } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this))
- .equals(mAuthTokenType)) {
- startSamlBasedFederatedSingleSignOnAuthorization();
- } else {
- checkBasicAuthorization(null, null);
- }
+ checkBasicAuthorization(null, null);
}
@@ -1334,57 +1138,6 @@ private void accessRootFolder(OwnCloudCredentials credentials) {
mAsyncTask.execute(params);
}
-
- /**
- * Starts the OAuth 'grant type' flow to get an access token, with
- * a GET AUTHORIZATION request to the BUILT-IN authorization server.
- */
- private void startOauthorization() {
- // be gentle with the user
- mAuthStatusIcon = R.drawable.progress_small;
- mAuthStatusText = getResources().getString(R.string.oauth_login_connection);
- showAuthStatus();
-
- // GET AUTHORIZATION request
- Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());
- Uri.Builder uriBuilder = uri.buildUpon();
- uriBuilder.appendQueryParameter(
- OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type)
- );
- uriBuilder.appendQueryParameter(
- OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)
- );
- uriBuilder.appendQueryParameter(
- OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id)
- );
- uriBuilder.appendQueryParameter(
- OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope)
- );
- uri = uriBuilder.build();
- Log_OC.d(TAG, "Starting browser to view " + uri.toString());
- Intent i = new Intent(Intent.ACTION_VIEW, uri);
-
- DisplayUtils.startIntentIfAppAvailable(i, this, R.string.no_browser_available);
- }
-
-
- /**
- * Starts the Web Single Sign On flow to get access to the root folder
- * in the server.
- */
- private void startSamlBasedFederatedSingleSignOnAuthorization() {
- /// be gentle with the user
- mAuthStatusIcon = R.drawable.progress_small;
- mAuthStatusText = getResources().getString(R.string.auth_connecting_auth_server);
- showAuthStatus();
-
- /// Show SAML-based SSO web dialog
- String targetUrl = mServerInfo.mBaseUrl
- + AuthenticatorUrlUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType, this);
- SamlWebViewDialog dialog = SamlWebViewDialog.newInstance(targetUrl, targetUrl);
- dialog.show(getSupportFragmentManager(), SAML_DIALOG_TAG);
- }
-
/**
* Callback method invoked when a RemoteOperation executed by this Activity finishes.
*
@@ -1392,20 +1145,15 @@ private void startSamlBasedFederatedSingleSignOnAuthorization() {
*/
@Override
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
-
if (operation instanceof GetServerInfoOperation) {
if (operation.hashCode() == mWaitingForOpId) {
onGetServerInfoFinish(result);
} // else nothing ; only the last check operation is considered;
// multiple can be started if the user amends a URL quickly
- } else if (operation instanceof OAuth2GetAccessToken) {
- onGetOAuthAccessTokenFinish(result);
-
} else if (operation instanceof GetRemoteUserInfoOperation) {
onGetUserNameFinish(result);
}
-
}
private void onGetUserNameFinish(RemoteOperationResult result) {
@@ -1548,9 +1296,7 @@ private void setOldLoginVisibility(int visible) {
}
private boolean authSupported(AuthenticationMethod authMethod) {
- return (basicTokenType.equals(mAuthTokenType) && AuthenticationMethod.BASIC_HTTP_AUTH.equals(authMethod)) ||
- (oauthTokenType.equals(mAuthTokenType) && AuthenticationMethod.BEARER_TOKEN.equals(authMethod)) ||
- (samlTokenType.equals(mAuthTokenType) && AuthenticationMethod.SAML_WEB_SSO.equals(authMethod));
+ return AuthenticationMethod.BASIC_HTTP_AUTH.equals(authMethod);
}
/**
@@ -1706,40 +1452,6 @@ private void updateServerStatusIconNoRegularAuth() {
mServerStatusText = getResources().getString(R.string.auth_can_not_auth_against_server);
}
- /**
- * Processes the result of the request for and access token send
- * to an OAuth authorization server.
- *
- * @param result Result of the operation.
- */
- private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {
- mWaitingForOpId = Long.MAX_VALUE;
- dismissDialog(WAIT_DIALOG_TAG);
-
- if (result.isSuccess()) {
- /// be gentle with the user
- IndeterminateProgressDialog dialog =
- IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);
- dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);
-
- /// time to test the retrieved access token on the ownCloud server
- @SuppressWarnings("unchecked")
- Map tokens = (Map) (result.getData().get(0));
- mAuthToken = tokens.get(OAuth2Constants.KEY_ACCESS_TOKEN);
- Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);
-
- /// validate token accessing to root folder / getting session
- OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(
- mAuthToken);
- accessRootFolder(credentials);
-
- } else {
- updateAuthStatusIconAndText(result);
- showAuthStatus();
- Log_OC.d(TAG, "Access failed: " + result.getLogMessage());
- }
- }
-
/**
* Processes the result of the access check performed to try the user credentials.
*
@@ -1801,7 +1513,6 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult result) {
CustomEditText serverAddressField = findViewById(R.id.hostUrlInput);
serverAddressField.setText(mServerInfo.mBaseUrl);
- findViewById(R.id.oauth_onOff_check).setVisibility(View.GONE);
findViewById(R.id.server_status_text).setVisibility(View.GONE);
mAuthStatusView = findViewById(R.id.auth_status_text);
@@ -1855,7 +1566,6 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult result) {
CustomEditText serverAddressField = findViewById(R.id.hostUrlInput);
serverAddressField.setText(mServerInfo.mBaseUrl);
- findViewById(R.id.oauth_onOff_check).setVisibility(View.GONE);
findViewById(R.id.server_status_text).setVisibility(View.GONE);
mAuthStatusView = findViewById(R.id.auth_status_text);
@@ -1884,32 +1594,16 @@ public void onAuthenticatorTaskCallback(RemoteOperationResult result) {
* the new credentials when needed.
*/
private void updateAccountAuthentication() throws AccountNotFoundException {
- String accountType = MainApp.getAccountType(this);
-
Bundle response = new Bundle();
response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);
- if (AccountTypeUtils.getAuthTokenTypeAccessToken(accountType).equals(mAuthTokenType)) {
- response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
- // the next line is necessary, notifications are calling directly to the
- // AuthenticatorActivity to update, without AccountManager intervention
- mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
-
- } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType).equals(mAuthTokenType)) {
- response.putString(AccountManager.KEY_AUTHTOKEN, mAuthToken);
- // the next line is necessary; by now, notifications are calling directly to the
- // AuthenticatorActivity to update, without AccountManager intervention
- mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
-
+ if (webViewLoginMethod) {
+ response.putString(AccountManager.KEY_AUTHTOKEN, webViewPassword);
+ mAccountMgr.setPassword(mAccount, webViewPassword);
} else {
- if (!webViewLoginMethod) {
- response.putString(AccountManager.KEY_AUTHTOKEN, mPasswordInput.getText().toString());
- mAccountMgr.setPassword(mAccount, mPasswordInput.getText().toString());
- } else {
- response.putString(AccountManager.KEY_AUTHTOKEN, webViewPassword);
- mAccountMgr.setPassword(mAccount, webViewPassword);
- }
+ response.putString(AccountManager.KEY_AUTHTOKEN, mPasswordInput.getText().toString());
+ mAccountMgr.setPassword(mAccount, mPasswordInput.getText().toString());
}
// remove managed clients for this account to enforce creation with fresh credentials
@@ -1936,9 +1630,6 @@ private boolean createAccount(RemoteOperationResult authResult) {
String accountType = MainApp.getAccountType(this);
// create and save new ownCloud account
- boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(accountType).equals(mAuthTokenType);
- boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType).equals(mAuthTokenType);
-
String lastPermanentLocation = authResult.getLastPermanentLocation();
if (lastPermanentLocation != null) {
mServerInfo.mBaseUrl = AuthenticatorUrlUtils.trimWebdavSuffix(lastPermanentLocation);
@@ -1951,9 +1642,6 @@ private boolean createAccount(RemoteOperationResult authResult) {
} else {
username = webViewUser;
}
- if (isOAuth) {
- username = "OAuth_user" + new SecureRandom().nextLong();
- }
String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username);
Account newAccount = new Account(accountName, accountType);
@@ -1970,15 +1658,10 @@ private boolean createAccount(RemoteOperationResult authResult) {
} else {
mAccount = newAccount;
- if (isOAuth || isSaml) {
- // with external authorizations, the password is never input in the app
- mAccountMgr.addAccountExplicitly(mAccount, EMPTY_STRING, null);
+ if (webViewLoginMethod) {
+ mAccountMgr.addAccountExplicitly(mAccount, webViewPassword, null);
} else {
- if (!webViewLoginMethod) {
- mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
- } else {
- mAccountMgr.addAccountExplicitly(mAccount, webViewPassword, null);
- }
+ mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
}
/// add the new account as default in preferences, if there is none already
@@ -1996,9 +1679,7 @@ private boolean createAccount(RemoteOperationResult authResult) {
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, accountType);
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
intent.putExtra(AccountManager.KEY_USERDATA, username);
- if (isOAuth || isSaml) {
- mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);
- }
+
/// add user data to the new account; TODO probably can be done in the last parameter
// addAccountExplicitly, or in KEY_USERDATA
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mServerInfo.mVersion.getVersion());
@@ -2023,12 +1704,6 @@ private boolean createAccount(RemoteOperationResult authResult) {
Log_OC.w(TAG, "Couldn't get display name and user id for " + username);
}
- if (isSaml) {
- mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
- } else if (isOAuth) {
- mAccountMgr.setUserData(mAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
- }
-
setAccountAuthenticatorResult(intent.getExtras());
setResult(RESULT_OK, intent);
@@ -2125,25 +1800,6 @@ public void onViewPasswordClick() {
mPasswordInput.setSelection(selectionStart, selectionEnd);
}
-
- /**
- * Called when the checkbox for OAuth authorization is clicked.
- *
- * Hides or shows the input fields for user & password.
- *
- * @param view 'View password' 'button'
- */
- public void onCheckClick(View view) {
- CheckBox oAuth2Check = (CheckBox) view;
- if (oAuth2Check.isChecked()) {
- mAuthTokenType = oauthTokenType;
- } else {
- mAuthTokenType = basicTokenType;
- }
- updateAuthenticationPreFragmentVisibility();
- }
-
-
/**
* Called when the 'action' button in an IME is pressed ('enter' in software keyboard).
*
@@ -2215,38 +1871,6 @@ private void getRemoteUserNameOperation(String sessionCookie) {
}
}
-
- @Override
- public void onSsoFinished(String sessionCookie) {
- if (sessionCookie != null && sessionCookie.length() > 0) {
- Log_OC.d(TAG, "Successful SSO - time to save the account");
- mAuthToken = sessionCookie;
- getRemoteUserNameOperation(sessionCookie);
- Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);
- if (fd instanceof DialogFragment) {
- Dialog d = ((DialogFragment) fd).getDialog();
- if (d != null && d.isShowing()) {
- d.dismiss();
- }
- }
-
- } else {
- // TODO - show fail
- Log_OC.d(TAG, "SSO failed");
- }
-
- }
-
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType(this)).equals(mAuthTokenType) &&
- mHostUrlInput.hasFocus() && event.getAction() == MotionEvent.ACTION_DOWN) {
- checkOcServer();
- }
- return super.onTouchEvent(event);
- }
-
-
/**
* Show untrusted cert dialog
*/
@@ -2279,34 +1903,6 @@ private void showUntrustedCertDialog(RemoteOperationResult result) {
}
- /**
- * Called from SslValidatorDialog when a new server certificate was correctly saved.
- */
- public void onSavedCertificate() {
- Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);
- if (fd == null) {
- // if SAML dialog is not shown,
- // the SslDialog was shown due to an SSL error in the server check
- checkOcServer();
- }
- }
-
- /**
- * Called from SslValidatorDialog when a new server certificate could not be saved
- * when the user requested it.
- */
- @Override
- public void onFailedSavingCertificate() {
- dismissDialog(SAML_DIALOG_TAG);
- DisplayUtils.showSnackMessage(this, R.string.ssl_validator_not_saved);
- }
-
- @Override
- public void onCancelCertificate() {
- dismissDialog(SAML_DIALOG_TAG);
- }
-
-
private void doOnResumeAndBound() {
//Log_OC.e(TAG, "registering to listen for operation callbacks" );
mOperationsServiceBinder.addOperationListener(this, mHandler);
@@ -2335,7 +1931,6 @@ private void dismissDialog(String dialogTag) {
}
}
-
/**
* Implements callback methods for service binding.
*/
@@ -2431,4 +2026,43 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
parseAndLoginFromWebView(result);
}
}
+
+ /**
+ * Obtain the X509Certificate from SslError
+ *
+ * @param error SslError
+ * @return X509Certificate from error
+ */
+ public static X509Certificate getX509CertificateFromError(SslError error) {
+ Bundle bundle = SslCertificate.saveState(error.getCertificate());
+ X509Certificate x509Certificate;
+ byte[] bytes = bundle.getByteArray("x509-certificate");
+ if (bytes == null) {
+ x509Certificate = null;
+ } else {
+ try {
+ CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+ Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
+ x509Certificate = (X509Certificate) cert;
+ } catch (CertificateException e) {
+ x509Certificate = null;
+ }
+ }
+ return x509Certificate;
+ }
+
+ /**
+ * Called from SslValidatorDialog when a new server certificate was correctly saved.
+ */
+ public void onSavedCertificate() {
+ checkOcServer();
+ }
+
+ /**
+ * Called from SslValidatorDialog when a new server certificate could not be saved when the user requested it.
+ */
+ @Override
+ public void onFailedSavingCertificate() {
+ DisplayUtils.showSnackMessage(this, R.string.ssl_validator_not_saved);
+ }
}
diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java
index f65d1258a17c..e20b53993d50 100644
--- a/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java
+++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java
@@ -23,8 +23,6 @@
import android.content.Context;
-import com.owncloud.android.MainApp;
-import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import java.util.Locale;
@@ -38,9 +36,6 @@ public final class AuthenticatorUrlUtils {
private static final String HTTPS_PROTOCOL = "https://";
private static final String HTTP_PROTOCOL = "http://";
- private static final String ODAV_PATH = "/remote.php/odav";
- private static final String SAML_SSO_PATH = "/remote.php/webdav";
-
private AuthenticatorUrlUtils() {
}
@@ -55,18 +50,7 @@ private AuthenticatorUrlUtils() {
* is unknown; versions prior to ownCloud 4 are not supported anymore
*/
public static String getWebdavPath(OwnCloudVersion version, String authTokenType, Context context) {
- if (version != null) {
- String accountType = MainApp.getAccountType(context);
- if (AccountTypeUtils.getAuthTokenTypeAccessToken(accountType).equals(authTokenType)) {
- return ODAV_PATH;
- }
- if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(accountType).equals(authTokenType)) {
- return SAML_SSO_PATH;
- }
-
return WEBDAV_PATH_4_0_AND_LATER;
- }
- return null;
}
public static String normalizeUrlSuffix(String url) {
@@ -99,7 +83,7 @@ public static String normalizeUrl(String url, boolean sslWhenUnprefixed) {
public static String trimWebdavSuffix(String url) {
String trimmedUrl = url;
- while(trimmedUrl.endsWith("/")) {
+ while (trimmedUrl.endsWith("/")) {
trimmedUrl = trimmedUrl.substring(0, url.length() - 1);
}
@@ -107,13 +91,7 @@ public static String trimWebdavSuffix(String url) {
if (pos >= 0) {
trimmedUrl = trimmedUrl.substring(0, pos);
- } else {
- pos = trimmedUrl.lastIndexOf(ODAV_PATH);
- if (pos >= 0) {
- trimmedUrl = trimmedUrl.substring(0, pos);
- }
}
-
return trimmedUrl;
}
diff --git a/src/main/java/com/owncloud/android/authentication/OAuth2Constants.java b/src/main/java/com/owncloud/android/authentication/OAuth2Constants.java
deleted file mode 100644
index 982efe047607..000000000000
--- a/src/main/java/com/owncloud/android/authentication/OAuth2Constants.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ownCloud Android client application
- *
- * @author David A. Velasco
- * Copyright (C) 2015 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package com.owncloud.android.authentication;
-
-/**
- * Constant values for OAuth 2 protocol.
- *
- * Includes required and optional parameter NAMES used in the 'authorization code' grant type.
- */
-public final class OAuth2Constants {
- /// Parameters to send to the Authorization Endpoint
- public static final String KEY_RESPONSE_TYPE = "response_type";
- public static final String KEY_REDIRECT_URI = "redirect_uri";
- public static final String KEY_CLIENT_ID = "client_id";
- public static final String KEY_SCOPE = "scope";
- public static final String KEY_STATE = "state";
-
- /// Additional parameters to send to the Token Endpoint
- public static final String KEY_GRANT_TYPE = "grant_type";
- public static final String KEY_CODE = "code";
-
- /// Parameters received in an OK response from the Token Endpoint
- public static final String KEY_ACCESS_TOKEN = "access_token";
- public static final String KEY_TOKEN_TYPE = "token_type";
- public static final String KEY_EXPIRES_IN = "expires_in";
- public static final String KEY_REFRESH_TOKEN = "refresh_token";
-
- /// Parameters in an ERROR response
- public static final String KEY_ERROR = "error";
- public static final String KEY_ERROR_DESCRIPTION = "error_description";
- public static final String KEY_ERROR_URI = "error_uri";
- public static final String VALUE_ERROR_ACCESS_DENIED = "access_denied";
-
- private OAuth2Constants() {
- // No instance
- }
-}
diff --git a/src/main/java/com/owncloud/android/authentication/SsoWebViewClient.java b/src/main/java/com/owncloud/android/authentication/SsoWebViewClient.java
deleted file mode 100644
index 80338393d347..000000000000
--- a/src/main/java/com/owncloud/android/authentication/SsoWebViewClient.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * ownCloud Android client application
- *
- * @author David A. Velasco
- * Copyright (C) 2015 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package com.owncloud.android.authentication;
-
-import android.content.Context;
-import android.graphics.Bitmap;
-import android.net.http.SslCertificate;
-import android.net.http.SslError;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Message;
-import android.view.View;
-import android.webkit.CookieManager;
-import android.webkit.HttpAuthHandler;
-import android.webkit.SslErrorHandler;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-
-import com.owncloud.android.lib.common.network.NetworkUtils;
-import com.owncloud.android.lib.common.utils.Log_OC;
-
-import java.io.ByteArrayInputStream;
-import java.lang.ref.WeakReference;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-
-
-/**
- * Custom {@link WebViewClient} client aimed to catch the end of a single-sign-on process
- * running in the {@link WebView} that is attached to.
- *
- * Assumes that the single-sign-on is kept thanks to a cookie set at the end of the
- * authentication process.
- */
-public class SsoWebViewClient extends WebViewClient {
-
- private static final String TAG = SsoWebViewClient.class.getSimpleName();
-
- private Context mContext;
- private Handler mListenerHandler;
- private WeakReference mListenerRef;
- private String mTargetUrl;
- private String mLastReloadedUrlAtError;
-
- public interface SsoWebViewClientListener {
- void onSsoFinished(String sessionCookie);
- }
-
- public SsoWebViewClient (Context context, Handler listenerHandler, SsoWebViewClientListener listener) {
- mContext = context;
- mListenerHandler = listenerHandler;
- mListenerRef = new WeakReference(listener);
- mTargetUrl = "fake://url.to.be.set";
- mLastReloadedUrlAtError = null;
- }
-
- public String getTargetUrl() {
- return mTargetUrl;
- }
-
- public void setTargetUrl(String targetUrl) {
- mTargetUrl = targetUrl;
- }
-
- @Override
- public void onPageStarted (WebView view, String url, Bitmap favicon) {
- Log_OC.d(TAG, "onPageStarted : " + url);
- view.clearCache(true);
- super.onPageStarted(view, url, favicon);
- }
-
- @Override
- public void onFormResubmission (WebView view, Message dontResend, Message resend) {
- Log_OC.d(TAG, "onFormResubMission ");
-
- // necessary to grant reload of last page when device orientation is changed after sending a form
- resend.sendToTarget();
- }
-
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- return false;
- }
-
- @Override
- public void onReceivedError (WebView view, int errorCode, String description, String failingUrl) {
- Log_OC.e(TAG, "onReceivedError : " + failingUrl + ", code " + errorCode + ", description: " + description);
- if (!failingUrl.equals(mLastReloadedUrlAtError)) {
- view.reload();
- mLastReloadedUrlAtError = failingUrl;
- } else {
- mLastReloadedUrlAtError = null;
- super.onReceivedError(view, errorCode, description, failingUrl);
- }
- }
-
- @Override
- public void onPageFinished (WebView view, String url) {
- Log_OC.d(TAG, "onPageFinished : " + url);
- mLastReloadedUrlAtError = null;
- if (url.startsWith(mTargetUrl)) {
- view.setVisibility(View.GONE);
- CookieManager cookieManager = CookieManager.getInstance();
- final String cookies = cookieManager.getCookie(url);
- //Log_OC.d(TAG, "Cookies: " + cookies);
- if (mListenerHandler != null && mListenerRef != null) {
- // this is good idea because onPageFinished is not running in the UI thread
- mListenerHandler.post(() -> {
- SsoWebViewClientListener listener = mListenerRef.get();
- if (listener != null) {
- // Send Cookies to the listener
- listener.onSsoFinished(cookies);
- }
- });
- }
- }
- }
-
- @Override
- public void onReceivedSslError (final WebView view, final SslErrorHandler handler, SslError error) {
- Log_OC.e(TAG, "onReceivedSslError : " + error);
- // Test 1
- X509Certificate x509Certificate = getX509CertificateFromError(error);
- boolean isKnownServer = false;
-
- if (x509Certificate != null) {
- try {
- isKnownServer = NetworkUtils.isCertInKnownServersStore(x509Certificate, mContext);
- } catch (Exception e) {
- Log_OC.e(TAG, "Exception: " + e.getMessage());
- }
- }
-
- if (isKnownServer) {
- handler.proceed();
- } else {
- ((AuthenticatorActivity)mContext).showUntrustedCertDialog(x509Certificate, error, handler);
- }
- }
-
- /**
- * Obtain the X509Certificate from SslError
- * @param error SslError
- * @return X509Certificate from error
- */
- public static X509Certificate getX509CertificateFromError(SslError error) {
- Bundle bundle = SslCertificate.saveState(error.getCertificate());
- X509Certificate x509Certificate;
- byte[] bytes = bundle.getByteArray("x509-certificate");
- if (bytes == null) {
- x509Certificate = null;
- } else {
- try {
- CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
- Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
- x509Certificate = (X509Certificate) cert;
- } catch (CertificateException e) {
- x509Certificate = null;
- }
- }
- return x509Certificate;
- }
-
- @Override
- public void onReceivedHttpAuthRequest (WebView view, HttpAuthHandler handler, String host, String realm) {
- Log_OC.d(TAG, "onReceivedHttpAuthRequest : " + host);
-
- ((AuthenticatorActivity)mContext).createAuthenticationDialog(view, handler);
- }
-}
diff --git a/src/main/java/com/owncloud/android/files/services/FileDownloader.java b/src/main/java/com/owncloud/android/files/services/FileDownloader.java
index 406c454ddd78..80c9d500ec56 100644
--- a/src/main/java/com/owncloud/android/files/services/FileDownloader.java
+++ b/src/main/java/com/owncloud/android/files/services/FileDownloader.java
@@ -1,4 +1,4 @@
-/**
+/*
* ownCloud Android client application
*
* Copyright (C) 2012 Bartek Przybylski
@@ -450,7 +450,7 @@ private void downloadFile(String downloadKey) {
/// perform the download
- downloadResult = mCurrentDownload.execute(mDownloadClient, mCurrentDownload.getFile().isEncrypted());
+ downloadResult = mCurrentDownload.execute(mDownloadClient);
if (downloadResult.isSuccess()) {
saveDownloadedFile();
}
@@ -460,11 +460,8 @@ private void downloadFile(String downloadKey) {
downloadResult = new RemoteOperationResult(e);
} finally {
- Pair removeResult =
- mPendingDownloads.removePayload(
- mCurrentAccount.name,
- mCurrentDownload.getRemotePath()
- );
+ Pair removeResult = mPendingDownloads.removePayload(
+ mCurrentAccount.name, mCurrentDownload.getRemotePath());
/// notify result
notifyDownloadResult(mCurrentDownload, downloadResult);
diff --git a/src/main/java/com/owncloud/android/operations/CommentFileOperation.java b/src/main/java/com/owncloud/android/operations/CommentFileOperation.java
index 26037e50b18e..6b3fe2eb9dc0 100644
--- a/src/main/java/com/owncloud/android/operations/CommentFileOperation.java
+++ b/src/main/java/com/owncloud/android/operations/CommentFileOperation.java
@@ -56,7 +56,7 @@ public CommentFileOperation(String message, String fileId, String userId) {
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result = new CommentFileRemoteOperation(message, fileId, userId).execute(client, true);
+ RemoteOperationResult result = new CommentFileRemoteOperation(message, fileId, userId).execute(client);
if (!result.isSuccess()) {
Log_OC.e(this, "File with Id " + fileId + " could not be commented");
diff --git a/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java b/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java
index 24aca30a36eb..792936f653a7 100644
--- a/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java
+++ b/src/main/java/com/owncloud/android/operations/CreateFolderOperation.java
@@ -65,7 +65,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
if (result.isSuccess()) {
RemoteOperationResult remoteFolderOperationResult = new ReadFolderRemoteOperation(mRemotePath)
- .execute(client, true);
+ .execute(client);
createdRemoteFolder = (RemoteFile) remoteFolderOperationResult.getData().get(0);
saveFolderInDB();
diff --git a/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java b/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java
index 277f201767c9..6842c2f8053b 100644
--- a/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java
+++ b/src/main/java/com/owncloud/android/operations/DownloadFileOperation.java
@@ -158,7 +158,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
while (listener.hasNext()) {
downloadOperation.addDatatransferProgressListener(listener.next());
}
- result = downloadOperation.execute(client, client.isUseNextcloudUserAgent());
+ result = downloadOperation.execute(client);
if (result.isSuccess()) {
modificationTimestamp = downloadOperation.getModificationTimestamp();
diff --git a/src/main/java/com/owncloud/android/operations/OAuth2GetAccessToken.java b/src/main/java/com/owncloud/android/operations/OAuth2GetAccessToken.java
deleted file mode 100644
index f42006adf3fc..000000000000
--- a/src/main/java/com/owncloud/android/operations/OAuth2GetAccessToken.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * ownCloud Android client application
- *
- * Copyright (C) 2015 ownCloud Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package com.owncloud.android.operations;
-
-import com.owncloud.android.authentication.OAuth2Constants;
-import com.owncloud.android.lib.common.OwnCloudClient;
-import com.owncloud.android.lib.common.operations.RemoteOperation;
-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 org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class OAuth2GetAccessToken extends RemoteOperation {
- private static final String TAG = OAuth2GetAccessToken.class.getSimpleName();
-
- private static final int KEY_INDEX = 0;
- private static final int VALUE_INDEX = 1;
-
- private String mClientId;
- private String mRedirectUri;
- private String mGrantType;
-
- private String mOAuth2AuthorizationResponse;
- private Map mOAuth2ParsedAuthorizationResponse;
- private Map mResultTokenMap;
-
-
- public OAuth2GetAccessToken(String clientId, String redirectUri, String grantType, String oAuth2AuthorizationResponse) {
- mClientId = clientId;
- mRedirectUri = redirectUri;
- mGrantType = grantType;
- mOAuth2AuthorizationResponse = oAuth2AuthorizationResponse;
- mOAuth2ParsedAuthorizationResponse = new HashMap<>();
- mResultTokenMap = null;
- }
-
- /*
- public Map getResultTokenMap() {
- return mResultTokenMap;
- }
- */
-
- @Override
- @SuppressWarnings("PMD.AvoidDuplicateLiterals")
- protected RemoteOperationResult run(OwnCloudClient client) {
- RemoteOperationResult result = null;
- PostMethod postMethod = null;
-
- try {
- parseAuthorizationResponse();
- if (mOAuth2ParsedAuthorizationResponse.keySet().contains(OAuth2Constants.KEY_ERROR)) {
- if (OAuth2Constants.VALUE_ERROR_ACCESS_DENIED.equals(mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_ERROR))) {
- result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR_ACCESS_DENIED);
- } else {
- result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR);
- }
- }
-
- if (result == null) {
- NameValuePair[] nameValuePairs = new NameValuePair[4];
- nameValuePairs[0] = new NameValuePair(OAuth2Constants.KEY_GRANT_TYPE, mGrantType);
- nameValuePairs[1] = new NameValuePair(OAuth2Constants.KEY_CODE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_CODE));
- nameValuePairs[2] = new NameValuePair(OAuth2Constants.KEY_REDIRECT_URI, mRedirectUri);
- nameValuePairs[3] = new NameValuePair(OAuth2Constants.KEY_CLIENT_ID, mClientId);
- //nameValuePairs[4] = new NameValuePair(OAuth2Constants.KEY_SCOPE, mOAuth2ParsedAuthorizationResponse.get(OAuth2Constants.KEY_SCOPE));
-
- postMethod = new PostMethod(client.getWebdavUri().toString());
- postMethod.setRequestBody(nameValuePairs);
- client.executeMethod(postMethod);
-
- String response = postMethod.getResponseBodyAsString();
- if (response != null && response.length() > 0) {
- JSONObject tokenJson = new JSONObject(response);
- parseAccessTokenResult(tokenJson);
- if (mResultTokenMap.get(OAuth2Constants.KEY_ERROR) != null || mResultTokenMap.get(OAuth2Constants.KEY_ACCESS_TOKEN) == null) {
- result = new RemoteOperationResult(ResultCode.OAUTH2_ERROR);
-
- } else {
- result = new RemoteOperationResult(true, postMethod);
- ArrayList