use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class UpdateSharePermissionsOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// ShareType.USER | ShareType.GROUP
OCShare share = getStorageManager().getShareById(mShareId);
if (share == null) {
// TODO try to get remote share before failing?
return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
mPath = share.getPath();
// Update remote share with password
UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(share.getRemoteId());
updateOp.setPermissions(mPermissions);
RemoteOperationResult result = updateOp.execute(client);
if (result.isSuccess()) {
RemoteOperation getShareOp = new GetRemoteShareOperation(share.getRemoteId());
result = getShareOp.execute(client);
if (result.isSuccess()) {
share = (OCShare) result.getData().get(0);
// TODO check permissions are being saved
updateData(share);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class AuthenticatorActivity method createAccount.
/**
* Creates a new account through the Account Authenticator that started this activity.
*
* This makes the account permanent.
*
* TODO Decide how to name the OAuth accounts
*/
private boolean createAccount(RemoteOperationResult authResult) {
/// create and save new ownCloud account
boolean isOAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType);
boolean isSaml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType);
String lastPermanentLocation = authResult.getLastPermanentLocation();
if (lastPermanentLocation != null) {
mServerInfo.mBaseUrl = AccountUtils.trimWebdavSuffix(lastPermanentLocation);
}
Uri uri = Uri.parse(mServerInfo.mBaseUrl);
String username = mUsernameInput.getText().toString().trim();
if (isOAuth) {
username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();
}
String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.buildAccountName(uri, username);
Account newAccount = new Account(accountName, MainApp.getAccountType());
if (AccountUtils.exists(newAccount, getApplicationContext())) {
// fail - not a new account, but an existing one; disallow
RemoteOperationResult result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_NEW);
updateAuthStatusIconAndText(result);
showAuthStatus();
Log_OC.d(TAG, result.getLogMessage());
return false;
} else {
mAccount = newAccount;
if (isOAuth || isSaml) {
// with external authorizations, the password is never input in the app
mAccountMgr.addAccountExplicitly(mAccount, "", null);
} else {
mAccountMgr.addAccountExplicitly(mAccount, mPasswordInput.getText().toString(), null);
}
// include account version with the new account
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(AccountUtils.ACCOUNT_VERSION));
/// add the new account as default in preferences, if there is none already
Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);
if (defaultAccount == null) {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putString("select_oc_account", accountName);
editor.commit();
}
/// prepare result to return to the Authenticator
// TODO check again what the Authenticator makes with it; probably has the same
// effect as addAccountExplicitly, but it's not well done
final Intent intent = new Intent();
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType());
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());
mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mServerInfo.mBaseUrl);
if (authResult.getData() != null) {
try {
UserInfo userInfo = (UserInfo) authResult.getData().get(0);
mAccountMgr.setUserData(mAccount, Constants.KEY_DISPLAY_NAME, userInfo.mDisplayName);
} catch (ClassCastException c) {
Log_OC.w(TAG, "Couldn't get display name for " + username);
}
} else {
Log_OC.w(TAG, "Couldn't get display name 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);
return true;
}
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class AuthenticatorAsyncTask method doInBackground.
@Override
protected RemoteOperationResult doInBackground(Object... params) {
RemoteOperationResult result;
if (params != null && params.length == 2) {
String url = (String) params[0];
OwnCloudCredentials credentials = (OwnCloudCredentials) params[1];
// Client
Uri uri = Uri.parse(url);
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, true);
client.setCredentials(credentials);
// Operation - try credentials
ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH, mContext, SUCCESS_IF_ABSENT);
result = operation.execute(client);
String targetUrlAfterPermanentRedirection = null;
if (operation.wasRedirected()) {
RedirectionPath redirectionPath = operation.getRedirectionPath();
targetUrlAfterPermanentRedirection = redirectionPath.getLastPermanentLocation();
}
// Operation - get display name
if (result.isSuccess()) {
GetRemoteUserInfoOperation remoteUserNameOperation = new GetRemoteUserInfoOperation();
if (targetUrlAfterPermanentRedirection != null) {
// we can't assume that any subpath of the domain is correctly redirected; ugly stuff
client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(AccountUtils.trimWebdavSuffix(targetUrlAfterPermanentRedirection)), mContext, true);
client.setCredentials(credentials);
}
result = remoteUserNameOperation.execute(client);
}
// let the caller knows what is real URL that should be accessed for the account
// being authenticated if the initial URL is being redirected permanently (HTTP code 301)
result.setLastPermanentLocation(targetUrlAfterPermanentRedirection);
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class CreateShareViaLinkOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// Check if the share link already exists
RemoteOperation operation = new GetRemoteSharesForFileOperation(mPath, false, false);
RemoteOperationResult result = operation.execute(client);
// Create public link if doesn't exist yet
boolean publicShareExists = false;
if (result.isSuccess()) {
OCShare share = null;
for (int i = 0; i < result.getData().size(); i++) {
share = (OCShare) result.getData().get(i);
if (ShareType.PUBLIC_LINK.equals(share.getShareType())) {
publicShareExists = true;
break;
}
}
}
if (!publicShareExists) {
CreateRemoteShareOperation createOp = new CreateRemoteShareOperation(mPath, ShareType.PUBLIC_LINK, "", false, mPassword, OCShare.DEFAULT_PERMISSION);
createOp.setGetShareDetails(true);
result = createOp.execute(client);
}
if (result.isSuccess()) {
if (result.getData().size() > 0) {
Object item = result.getData().get(0);
if (item instanceof OCShare) {
updateData((OCShare) item);
} else {
ArrayList<Object> data = result.getData();
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
result.setData(data);
}
} else {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
}
}
return result;
}
use of com.owncloud.android.lib.common.operations.RemoteOperationResult in project android by owncloud.
the class GetServerInfoOperation method run.
/**
* Performs the operation
*
* @return Result of the operation. If successful, includes an instance of
* {@link ServerInfo} with the information retrieved from the server.
* Call {@link RemoteOperationResult#getData()}.get(0) to get it.
*/
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
// first: check the status of the server (including its version)
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));
mResultData.mIsSslConn = (result.getCode() == ResultCode.OK_SSL);
mResultData.mBaseUrl = normalizeProtocolPrefix(mUrl, mResultData.mIsSslConn);
RemoteOperationResult detectAuthResult = detectAuthorizationMethod(client);
// third: merge results
if (detectAuthResult.isSuccess()) {
mResultData.mAuthMethod = (AuthenticationMethod) detectAuthResult.getData().get(0);
ArrayList<Object> data = new ArrayList<Object>();
data.add(mResultData);
result.setData(data);
} else {
result = detectAuthResult;
}
}
return result;
}
Aggregations