-Subproject commit f323dda0445b455af638c7e8e4653c22959adb91
+Subproject commit 3c116514fb33992d050f7051e756b6c2244953b0
<string name="downloader_download_failed_credentials_error">Download failed, you need to relogin</string>
<string name="common_choose_account">Choose account</string>
<string name="sync_fail_ticker">Synchronization failed</string>
+ <string name="sync_fail_ticker_unauthorized">Synchronization failed, you need to relogin</string>
<string name="sync_fail_content">Synchronization of %1$s could not be completed</string>
<string name="sync_fail_content_unauthorized">Invalid password for %1$s</string>
<string name="sync_conflicts_in_favourites_ticker">Conflicts found</string>
*/
package com.owncloud.android;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
+
import android.app.Application;
import android.content.Context;
/**
* Main Application of the project
*
- * Contains methods to build the "static" strings. These strings were before constants in different classes
+ * Contains methods to build the "static" strings. These strings were before constants in different
+ * classes
*
* @author masensio
+ * @author David A. Velasco
*/
public class MainApp extends Application {
+
+ private static final String AUTH_ON = "on";
+
+ @SuppressWarnings("unused")
+ private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
+ @SuppressWarnings("unused")
+ private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client";
private static Context mContext;
-
+
public void onCreate(){
super.onCreate();
MainApp.mContext = getApplicationContext();
+
+ boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
+
+ if (isSamlAuth) {
+ OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
+
+ } else {
+ OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
+ }
+
}
public static Context getAppContext() {
public static String getLogName() {
return getAppContext().getResources().getString(R.string.log_name);
}
+
}
import com.owncloud.android.MainApp;\r
import com.owncloud.android.R;\r
import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
+import com.owncloud.android.lib.common.OwnCloudAccount;\r
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;\r
+import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;\r
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
Intent getServerInfoIntent = new Intent();\r
getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
- getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType);\r
if (mOperationsServiceBinder != null) {\r
- //Log_OC.wtf(TAG, "checking server..." );\r
mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
} else {\r
Log_OC.wtf(TAG, "Server check tried with OperationService unbound!" );\r
* the root folder of the ownCloud server.\r
*/\r
private void checkBasicAuthorization() {\r
- /// get the path to the root folder through WebDAV from the version server\r
- String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-\r
/// get basic credentials entered by user\r
String username = mUsernameInput.getText().toString();\r
String password = mPasswordInput.getText().toString();\r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
- /// test credentials accessing the root folder\r
- String remotePath ="";\r
- boolean successIfAbsent = false;\r
- boolean followRedirects = true;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects);\r
+ /// validate credentials accessing the root folder\r
+ accessRootFolderRemoteOperation(username, password);\r
\r
}\r
\r
- private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path,\r
- String username, String password, boolean followRedirects) {\r
+ private void accessRootFolderRemoteOperation(String username, String password) {\r
Intent existenceCheckIntent = new Intent();\r
existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, "/");\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password);\r
existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken);\r
- existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." );\r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
\r
- /// get the path to the root folder through WebDAV from the version server\r
- String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-\r
- /// test credentials accessing the root folder\r
- String remotePath ="";\r
- boolean successIfAbsent = false;\r
- boolean followRedirections = false;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirections);\r
+ /// validate credentials accessing the root folder\r
+ accessRootFolderRemoteOperation("", "");\r
\r
}\r
\r
\r
if (!mUsernameInput.getText().toString().equals(username)) {\r
// fail - not a new account, but an existing one; disallow\r
- result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME); \r
+ result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);\r
+ /*\r
+ OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(\r
+ new OwnCloudAccount(\r
+ Uri.parse(mServerInfo.mBaseUrl),\r
+ OwnCloudCredentialsFactory.newSamlSsoCredentials(mAuthToken))\r
+ );\r
+ */\r
+ mAuthToken = "";\r
updateAuthStatusIconAndText(result);\r
showAuthStatus();\r
Log_OC.d(TAG, result.getLogMessage());\r
mWaitingForOpId = Long.MAX_VALUE;\r
dismissDialog(WAIT_DIALOG_TAG);\r
\r
- String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
- if (result.isSuccess() && webdav_path != null) {\r
+ if (result.isSuccess()) {\r
/// be gentle with the user\r
IndeterminateProgressDialog dialog = \r
IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
//mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
\r
- String remotePath ="";\r
- boolean successIfAbsent = false;\r
- boolean followRedirects = true;\r
- startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects);\r
+ accessRootFolderRemoteOperation("", "");\r
\r
} else {\r
updateAuthStatusIconAndText(result);\r
String username = mUsernameInput.getText().toString().trim();\r
if (isOAuth) {\r
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();\r
- } \r
- String accountName = username + "@" + uri.getHost();\r
- if (uri.getPort() >= 0) {\r
- accountName += ":" + uri.getPort();\r
}\r
+ String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.\r
+ buildAccountName(uri, username);\r
Account newAccount = new Account(accountName, MainApp.getAccountType());\r
if (AccountUtils.exists(newAccount, getApplicationContext())) {\r
// fail - not a new account, but an existing one; disallow\r
getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME);\r
getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie);\r
- getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
\r
if (mOperationsServiceBinder != null) {\r
//Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
+++ /dev/null
-/* ownCloud Android client application
- * Copyright (C) 2014 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 <http://www.gnu.org/licenses/>.
- *
- */
-
-package com.owncloud.android.authentication;
-
-import android.accounts.Account;
-import android.os.Parcel;
-import android.os.Parcelable;
-
-/**
- * Account with extra information specific for ownCloud accounts.
- *
- * TODO integrate in the main app
- *
- * @author David A. Velasco
- */
-public class OwnCloudAccount extends Account {
-
- private String mAuthTokenType;
-
- public OwnCloudAccount(String name, String type, String authTokenType) {
- super(name, type);
- // TODO validate authTokentype as supported
- mAuthTokenType = authTokenType;
- }
-
- /**
- * Reconstruct from parcel
- *
- * @param source The source parcel
- */
- public OwnCloudAccount(Parcel source) {
- super(source);
- mAuthTokenType = source.readString();
- }
-
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- super.writeToParcel(dest, flags);
- dest.writeString(mAuthTokenType);
- }
-
-
- public String getAuthTokenType() {
- return mAuthTokenType;
- }
-
-
- public static final Parcelable.Creator<OwnCloudAccount> CREATOR = new Parcelable.Creator<OwnCloudAccount>() {
- @Override
- public OwnCloudAccount createFromParcel(Parcel source) {
- return new OwnCloudAccount(source);
- }
-
- @Override
- public OwnCloudAccount [] newArray(int size) {
- return new OwnCloudAccount[size];
- }
- };
-
-}
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
-import com.owncloud.android.lib.common.OwnCloudClientFactory;
+import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.notifications.NotificationBuilderWithProgressBar;
import com.owncloud.android.notifications.NotificationDelayer;
-import com.owncloud.android.operations.DownloadFileOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
import com.owncloud.android.lib.resources.files.FileUtils;
+import com.owncloud.android.operations.DownloadFileOperation;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.preview.PreviewImageActivity;
/// prepare client object to send the request to the ownCloud server
if (mDownloadClient == null || !mLastAccount.equals(mCurrentDownload.getAccount())) {
mLastAccount = mCurrentDownload.getAccount();
- mStorageManager = new FileDataStorageManager(mLastAccount, getContentResolver());
- mDownloadClient = OwnCloudClientFactory.createOwnCloudClient(mLastAccount, getApplicationContext());
+ mStorageManager =
+ new FileDataStorageManager(mLastAccount, getContentResolver());
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
+ mDownloadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
}
/// perform the download
int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker :
R.string.downloader_download_failed_ticker;
- boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED ||
- (downloadResult.isIdPRedirection()
- && mDownloadClient.getCredentials() == null));
+ boolean needsToUpdateCredentials = (
+ downloadResult.getCode() == ResultCode.UNAUTHORIZED ||
+ downloadResult.isIdPRedirection()
+ );
tickerId = (needsToUpdateCredentials) ?
R.string.downloader_download_failed_credentials_error : tickerId;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
-import com.owncloud.android.lib.common.OwnCloudClientFactory;
+import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.ui.activity.FailedUploadActivity;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.ui.activity.FileDisplayActivity;
/// prepare client object to send requests to the ownCloud server
if (mUploadClient == null || !mLastAccount.equals(mCurrentUpload.getAccount())) {
mLastAccount = mCurrentUpload.getAccount();
- mStorageManager = new FileDataStorageManager(mLastAccount, getContentResolver());
- mUploadClient = OwnCloudClientFactory.createOwnCloudClient(mLastAccount, getApplicationContext());
+ mStorageManager =
+ new FileDataStorageManager(mLastAccount, getContentResolver());
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mLastAccount, this);
+ mUploadClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
}
/// check the existence of the parent folder for the file to upload
String content = null;
// check credentials error
- boolean needsToUpdateCredentials = (uploadResult.getCode() == ResultCode.UNAUTHORIZED ||
- (uploadResult.isIdPRedirection() &&
- mUploadClient.getCredentials() == null));
+ boolean needsToUpdateCredentials = (
+ uploadResult.getCode() == ResultCode.UNAUTHORIZED ||
+ uploadResult.isIdPRedirection()
+ );
tickerId = (needsToUpdateCredentials) ?
R.string.uploader_upload_failed_credentials_error : tickerId;
}
private Context mContext;
- private String mWebDavUrl;
/**
* Constructor
* @param context Android context of the caller.
* @param webdavUrl
*/
- public DetectAuthenticationMethodOperation(Context context, String webdavUrl) {
+ public DetectAuthenticationMethodOperation(Context context) {
mContext = context;
- mWebDavUrl = webdavUrl;
}
AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN;
RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false);
- client.setWebdavUri(Uri.parse(mWebDavUrl));
- client.setBasicCredentials("", "");
+ client.clearCredentials();
client.setFollowRedirects(false);
// try to access the root folder, following redirections but not SAML SSO redirections
result = operation.execute(client);
String redirectedLocation = result.getRedirectedLocation();
- while (redirectedLocation != null && redirectedLocation.length() > 0 && !result.isIdPRedirection()) {
- client.setWebdavUri(Uri.parse(result.getRedirectedLocation()));
+ while (redirectedLocation != null && redirectedLocation.length() > 0 &&
+ !result.isIdPRedirection()) {
+ client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
result = operation.execute(client);
redirectedLocation = result.getRedirectedLocation();
}
private static final String TAG = GetServerInfoOperation.class.getSimpleName();
private String mUrl;
- private String mAuthTokenType;
private Context mContext;
private ServerInfo mResultData;
* Constructor.
*
* @param url URL to an ownCloud server.
- * @param authTokenType Identifies the authorization token supported by the caller;
- * TODO ugly dependency, get rid of it.
* @param context Android context; needed to check network state
* TODO ugly dependency, get rid of it.
*/
- public GetServerInfoOperation(String url, String authTokenType, Context context) {
+ public GetServerInfoOperation(String url, Context context) {
mUrl = trimWebdavSuffix(url);
- mAuthTokenType = authTokenType;
mContext = context;
mResultData = new ServerInfo();
protected RemoteOperationResult run(OwnCloudClient client) {
// first: check the status of the server (including its version)
- GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mUrl, mContext);
+ GetRemoteStatusOperation getStatus = new GetRemoteStatusOperation(mContext);
RemoteOperationResult result = getStatus.execute(client);
-
+
if (result.isSuccess()) {
// second: get authentication method required by the server
mResultData.mVersion = (OwnCloudVersion)(result.getData().get(0));
private RemoteOperationResult detectAuthorizationMethod(OwnCloudClient client) {
Log_OC.d(TAG, "Trying empty authorization to detect authentication method");
- String webdav_path = AccountUtils.getWebdavPath(mResultData.mVersion, mAuthTokenType);
- String webdav_url = mResultData.mBaseUrl + webdav_path;
DetectAuthenticationMethodOperation operation =
- new DetectAuthenticationMethodOperation(mContext, webdav_url);
+ new DetectAuthenticationMethodOperation(mContext);
return operation.execute(client);
}
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
-import android.app.Activity;
import android.content.Context;
import android.os.Handler;
* @param listenerHandler Handler associated to the thread where the methods of the listener objects must be called.
* @return Thread were the remote operation is executed.
*/
+ /*
public Thread execute(FileDataStorageManager storageManager, Context context, OnRemoteOperationListener listener, Handler listenerHandler, Activity callerActivity) {
if (storageManager == null) {
throw new IllegalArgumentException("Trying to execute a sync operation with a NULL storage manager");
mStorageManager = storageManager;
return super.execute(storageManager.getAccount(), context, listener, listenerHandler, callerActivity);
}
+ */
/**
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
+import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
-import com.owncloud.android.lib.common.OwnCloudClientFactory;
+import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
+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.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import android.accounts.Account;
import android.accounts.AccountsException;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
import android.app.Service;
import android.content.Intent;
import android.net.Uri;
public static final String EXTRA_ACCOUNT = "ACCOUNT";
public static final String EXTRA_SERVER_URL = "SERVER_URL";
- public static final String EXTRA_AUTH_TOKEN_TYPE = "AUTH_TOKEN_TYPE";
public static final String EXTRA_OAUTH2_QUERY_PARAMETERS = "OAUTH2_QUERY_PARAMETERS";
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
public static final String EXTRA_RESULT = "RESULT";
// TODO review if ALL OF THEM are necessary
- public static final String EXTRA_WEBDAV_PATH = "WEBDAV_PATH";
public static final String EXTRA_SUCCESS_IF_ABSENT = "SUCCESS_IF_ABSENT";
public static final String EXTRA_USERNAME = "USERNAME";
public static final String EXTRA_PASSWORD = "PASSWORD";
public static final String EXTRA_AUTH_TOKEN = "AUTH_TOKEN";
- public static final String EXTRA_FOLLOW_REDIRECTS = "FOLLOW_REDIRECTS";
public static final String EXTRA_COOKIE = "COOKIE";
public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
private static class Target {
public Uri mServerUrl = null;
public Account mAccount = null;
- public String mWebDavUrl = null;
public String mUsername = null;
public String mPassword = null;
public String mAuthToken = null;
- public boolean mFollowRedirects = true;
public String mCookie = null;
- public Target(Account account, Uri serverUrl, String webdavUrl, String username, String password, String authToken,
- boolean followRedirects, String cookie) {
+ public Target(Account account, Uri serverUrl, String username, String password, String authToken,
+ String cookie) {
mAccount = account;
mServerUrl = serverUrl;
- mWebDavUrl = webdavUrl;
mUsername = username;
mPassword = password;
mAuthToken = authToken;
- mFollowRedirects = followRedirects;
mCookie = cookie;
}
}
@Override
public void onDestroy() {
//Log_OC.wtf(TAG, "onDestroy init" );
+ // Saving cookies
+ try {
+ OwnCloudClientManagerFactory.getDefaultSingleton().
+ saveAllClients(this, MainApp.getAccountType());
+
+ // TODO - get rid of these exceptions
+ } catch (AccountNotFoundException e) {
+ e.printStackTrace();
+ } catch (AuthenticatorException e) {
+ e.printStackTrace();
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
//Log_OC.wtf(TAG, "Clear mUndispatchedFinisiedOperations" );
mUndispatchedFinishedOperations.clear();
+
//Log_OC.wtf(TAG, "onDestroy end" );
super.onDestroy();
}
} else {
Account account = operationIntent.getParcelableExtra(EXTRA_ACCOUNT);
String serverUrl = operationIntent.getStringExtra(EXTRA_SERVER_URL);
- String webDavPath = operationIntent.getStringExtra(EXTRA_WEBDAV_PATH);
- String webDavUrl = serverUrl + webDavPath;
String username = operationIntent.getStringExtra(EXTRA_USERNAME);
String password = operationIntent.getStringExtra(EXTRA_PASSWORD);
String authToken = operationIntent.getStringExtra(EXTRA_AUTH_TOKEN);
- boolean followRedirects = operationIntent.getBooleanExtra(EXTRA_FOLLOW_REDIRECTS, true);
String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
target = new Target(
account,
(serverUrl == null) ? null : Uri.parse(serverUrl),
- ((webDavPath == null) || (serverUrl == null)) ? null : webDavUrl,
username,
password,
authToken,
- followRedirects,
cookie
);
} else if (action.equals(ACTION_GET_SERVER_INFO)) {
// check OC server and get basic information from it
- String authTokenType =
- operationIntent.getStringExtra(EXTRA_AUTH_TOKEN_TYPE);
- operation = new GetServerInfoOperation(
- serverUrl, authTokenType, OperationsService.this);
+ operation = new GetServerInfoOperation(serverUrl, OperationsService.this);
} else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
/// GET ACCESS TOKEN to the OAuth server
} else if (action.equals(ACTION_EXISTENCE_CHECK)) {
// Existence Check
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
- boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, true);
+ boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, false);
operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent);
} else if (action.equals(ACTION_GET_USER_NAME)) {
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
mLastTarget = next.first;
if (mLastTarget.mAccount != null) {
- mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mAccount, getApplicationContext());
- mStorageManager = new FileDataStorageManager(mLastTarget.mAccount, getContentResolver());
+ OwnCloudAccount ocAccount = new OwnCloudAccount(mLastTarget.mAccount, this);
+ mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
+ mStorageManager =
+ new FileDataStorageManager(
+ mLastTarget.mAccount,
+ getContentResolver());
} else {
- mOwnCloudClient = OwnCloudClientFactory.createOwnCloudClient(mLastTarget.mServerUrl, getApplicationContext(),
- mLastTarget.mFollowRedirects); // this is not good enough
- if (mLastTarget.mWebDavUrl != null) {
- mOwnCloudClient.setWebdavUri(Uri.parse(mLastTarget.mWebDavUrl));
- }
- if (mLastTarget.mUsername != null && mLastTarget.mPassword != null) {
- mOwnCloudClient.setBasicCredentials(mLastTarget.mUsername, mLastTarget.mPassword);
- } else if (mLastTarget.mAuthToken != null) {
- mOwnCloudClient.setBearerCredentials(mLastTarget.mAuthToken);
- } else if (mLastTarget.mCookie != null) {
- mOwnCloudClient.setSsoSessionCookie(mLastTarget.mCookie);
+ OwnCloudCredentials credentials = null;
+ if (mLastTarget.mUsername != null &&
+ mLastTarget.mUsername.length() > 0) {
+ credentials = OwnCloudCredentialsFactory.newBasicCredentials(
+ mLastTarget.mUsername,
+ mLastTarget.mPassword); // basic
+
+ } else if (mLastTarget.mAuthToken != null &&
+ mLastTarget.mAuthToken.length() > 0) {
+ credentials = OwnCloudCredentialsFactory.newBearerCredentials(
+ mLastTarget.mAuthToken); // bearer token
+
+ } else if (mLastTarget.mCookie != null &&
+ mLastTarget.mCookie.length() > 0) {
+ credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(
+ mLastTarget.mCookie); // SAML SSO
}
+ OwnCloudAccount ocAccount = new OwnCloudAccount(
+ mLastTarget.mServerUrl, credentials);
+ mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
+ getClientFor(ocAccount, this);
mStorageManager = null;
}
}
import com.owncloud.android.datamodel.FileDataStorageManager;\r
import com.owncloud.android.lib.common.accounts.AccountUtils;\r
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;\r
-import com.owncloud.android.lib.common.OwnCloudClientFactory;\r
+import com.owncloud.android.lib.common.OwnCloudAccount;\r
import com.owncloud.android.lib.common.OwnCloudClient;\r
-\r
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;\r
\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
\r
protected void initClientForCurrentAccount() throws OperationCanceledException, AuthenticatorException, IOException, AccountNotFoundException {\r
AccountUtils.constructFullURLForAccount(getContext(), account);\r
- mClient = OwnCloudClientFactory.createOwnCloudClient(account, getContext());\r
+ OwnCloudAccount ocAccount = new OwnCloudAccount(account, getContext());\r
+ mClient = OwnCloudClientManagerFactory.getDefaultSingleton().\r
+ getClientFor(ocAccount, getContext());\r
}\r
\r
protected OwnCloudClient getClient() {\r
} else {
// in failures, the statistics for the global result are updated
- if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED ||
- ( result.isIdPRedirection() &&
- getClient().getCredentials() == null )) {
- //MainApp.getAuthTokenTypeSamlSessionCookie().equals(getClient().getAuthTokenType()))) {
+ if ( result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED ||
+ result.isIdPRedirection()
+ ) {
mSyncResult.stats.numAuthExceptions++;
} else if (result.getException() instanceof DavException) {
*/
private void notifyFailedSynchronization() {
NotificationCompat.Builder notificationBuilder = createNotificationBuilder();
- notificationBuilder.setTicker(i18n(R.string.sync_fail_ticker));
- boolean needsToUpdateCredentials = (mLastFailedResult != null &&
- ( mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED ||
- ( mLastFailedResult.isIdPRedirection() &&
- getClient().getCredentials() == null )
- //MainApp.getAuthTokenTypeSamlSessionCookie().equals(getClient().getAuthTokenType()))
- )
- );
- // TODO put something smart in the contentIntent below for all the possible errors
- notificationBuilder.setContentTitle(i18n(R.string.sync_fail_ticker));
+ boolean needsToUpdateCredentials = (
+ mLastFailedResult != null && (
+ mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED ||
+ mLastFailedResult.isIdPRedirection()
+ )
+ );
if (needsToUpdateCredentials) {
// let the user update credentials with one click
Intent updateAccountCredentials = new Intent(getContext(), AuthenticatorActivity.class);
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND);
notificationBuilder
+ .setTicker(i18n(R.string.sync_fail_ticker_unauthorized))
+ .setContentTitle(i18n(R.string.sync_fail_ticker_unauthorized))
.setContentIntent(PendingIntent.getActivity(
getContext(), (int)System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT
))
.setContentText(i18n(R.string.sync_fail_content_unauthorized, getAccount().name));
} else {
notificationBuilder
+ .setTicker(i18n(R.string.sync_fail_ticker))
+ .setContentTitle(i18n(R.string.sync_fail_ticker))
.setContentText(i18n(R.string.sync_fail_content, getAccount().name));
}
@Override
protected void onPause() {
+
if (mOperationsServiceBinder != null) {
mOperationsServiceBinder.removeOperationListener(this);
}
}
}
- private void requestCredentialsUpdate() {
+ protected void requestCredentialsUpdate() {
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
updateAccountCredentials.putExtra(
package com.owncloud.android.ui.activity;
import java.io.File;
+import java.io.IOException;
import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.accounts.AuthenticatorException;
+import android.accounts.OperationCanceledException;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
import com.owncloud.android.operations.CreateFolderOperation;
+import com.owncloud.android.lib.common.OwnCloudAccount;
+import com.owncloud.android.lib.common.OwnCloudClient;
+import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
+import com.owncloud.android.lib.common.OwnCloudCredentials;
+import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) && !SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
+ if (SynchronizeFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
+ equals(event) &&
+ /// TODO refactor and make common
+ synchResult != null && !synchResult.isSuccess() &&
+ (synchResult.getCode() == ResultCode.UNAUTHORIZED ||
+ synchResult.isIdPRedirection() ||
+ (synchResult.isException() && synchResult.getException()
+ instanceof AuthenticatorException))) {
+
+ OwnCloudClient client = null;
+ try {
+ OwnCloudAccount ocAccount =
+ new OwnCloudAccount(getAccount(), context);
+ client = (OwnCloudClientManagerFactory.getDefaultSingleton().
+ removeClientFor(ocAccount));
+ // TODO get rid of these exceptions
+ } catch (AccountNotFoundException e) {
+ e.printStackTrace();
+ } catch (AuthenticatorException e) {
+ e.printStackTrace();
+ } catch (OperationCanceledException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ if (client != null) {
+ OwnCloudCredentials cred = client.getCredentials();
+ if (cred != null) {
+ AccountManager am = AccountManager.get(context);
+ if (cred.authTokenExpires()) {
+ am.invalidateAuthToken(
+ getAccount().type,
+ cred.getAuthToken()
+ );
+ } else {
+ am.clearPassword(getAccount());
+ }
+ }
+ }
+
+ requestCredentialsUpdate();
+
}
- removeStickyBroadcast(intent);
- Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
+ }
+ removeStickyBroadcast(intent);
+ Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
+ setSupportProgressBarIndeterminateVisibility(mSyncInProgress /*|| mRefreshSharesInProgress*/);
}
getAccount(),
getApplicationContext()
);
- synchFolderOp.execute(getAccount(), this, null, null, this);
+ synchFolderOp.execute(getAccount(), this, null, null);
setSupportProgressBarIndeterminateVisibility(true);
}
public void uploadFiles() {
try {
- //OwnCloudClient webdav = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
ArrayList<String> local = new ArrayList<String>();
ArrayList<String> remote = new ArrayList<String>();
- /* TODO - mCreateDir can never be true at this moment; we will replace wdc.createDirectory by CreateFolderOperation when that is fixed
- OwnCloudClient wdc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getApplicationContext());
- // create last directory in path if necessary
- if (mCreateDir) {
- wdc.createDirectory(mUploadPath);
- }
- */
-
// this checks the mimeType
for (Parcelable mStream : mStreamsToUpload) {