Search in sources :

Example 1 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation 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;
}
Also used : RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetRemoteShareOperation(com.owncloud.android.lib.resources.shares.GetRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UpdateRemoteShareOperation(com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation) OCShare(com.owncloud.android.lib.resources.shares.OCShare)

Example 2 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation 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;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 3 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by owncloud.

the class UpdateShareViaLinkOperation method run.

@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    OCShare publicShare = getStorageManager().getFirstShareByPathAndType(mPath, ShareType.PUBLIC_LINK, "");
    if (publicShare == null) {
        // TODO try to get remote share before failing?
        return new RemoteOperationResult(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND);
    }
    // Update remote share with password
    UpdateRemoteShareOperation updateOp = new UpdateRemoteShareOperation(publicShare.getRemoteId());
    updateOp.setPassword(mPassword);
    updateOp.setExpirationDate(mExpirationDateInMillis);
    updateOp.setPublicUpload(mPublicUpload);
    RemoteOperationResult result = updateOp.execute(client);
    if (result.isSuccess()) {
        // Retrieve updated share / save directly with password? -> no; the password is not to be saved
        RemoteOperation getShareOp = new GetRemoteShareOperation(publicShare.getRemoteId());
        result = getShareOp.execute(client);
        if (result.isSuccess()) {
            OCShare share = (OCShare) result.getData().get(0);
            updateData(share);
        }
    }
    return result;
}
Also used : RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) GetRemoteShareOperation(com.owncloud.android.lib.resources.shares.GetRemoteShareOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) UpdateRemoteShareOperation(com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation) OCShare(com.owncloud.android.lib.resources.shares.OCShare)

Example 4 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by nextcloud.

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;
}
Also used : CreateRemoteShareOperation(com.owncloud.android.lib.resources.shares.CreateRemoteShareOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OCShare(com.owncloud.android.lib.resources.shares.OCShare) GetRemoteSharesForFileOperation(com.owncloud.android.lib.resources.shares.GetRemoteSharesForFileOperation)

Example 5 with RemoteOperation

use of com.owncloud.android.lib.common.operations.RemoteOperation in project android by nextcloud.

the class DetectAuthenticationMethodOperation method run.

/**
 *  Performs the operation.
 *
 *  Triggers a check of existence on the root folder of the server, granting
 *  that the request is not authenticated.
 *
 *  Analyzes the result of check to find out what authentication method, if
 *  any, is requested by the server.
 */
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
    RemoteOperationResult result = null;
    AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN;
    RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false);
    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.setBaseUri(Uri.parse(result.getRedirectedLocation()));
        result = operation.execute(client);
        redirectedLocation = result.getRedirectedLocation();
    }
    // analyze response
    if (result.getHttpCode() == HttpStatus.SC_UNAUTHORIZED) {
        ArrayList<String> authHeaders = result.getAuthenticateHeaders();
        for (String header : authHeaders) {
            // currently we only support basic auth
            if (header.toLowerCase(Locale.ROOT).startsWith("basic")) {
                authMethod = AuthenticationMethod.BASIC_HTTP_AUTH;
                break;
            }
        }
    // else - fall back to UNKNOWN
    } else if (result.isSuccess()) {
        authMethod = AuthenticationMethod.NONE;
    } else if (result.isIdPRedirection()) {
        authMethod = AuthenticationMethod.SAML_WEB_SSO;
    }
    // else - fall back to UNKNOWN
    Log_OC.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod));
    if (!authMethod.equals(AuthenticationMethod.UNKNOWN)) {
        result = new RemoteOperationResult(true, result.getHttpCode(), result.getHttpPhrase(), null);
    }
    ArrayList<Object> data = new ArrayList<>();
    data.add(authMethod);
    result.setData(data);
    // same result instance, so that other errors
    return result;
// can be handled by the caller transparently
}
Also used : ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperation(com.owncloud.android.lib.common.operations.RemoteOperation) ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) ArrayList(java.util.ArrayList)

Aggregations

RemoteOperation (com.owncloud.android.lib.common.operations.RemoteOperation)28 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)22 Account (android.accounts.Account)9 OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)9 Pair (android.util.Pair)6 OCShare (com.owncloud.android.lib.resources.shares.OCShare)6 OCFile (com.owncloud.android.datamodel.OCFile)4 ExistenceCheckRemoteOperation (com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation)4 GetRemoteShareOperation (com.owncloud.android.lib.resources.shares.GetRemoteShareOperation)4 UpdateRemoteShareOperation (com.owncloud.android.lib.resources.shares.UpdateRemoteShareOperation)4 ArrayList (java.util.ArrayList)4 AuthenticatorException (android.accounts.AuthenticatorException)3 OperationCanceledException (android.accounts.OperationCanceledException)3 Context (android.content.Context)3 Handler (android.os.Handler)3 AccountUtils (com.owncloud.android.authentication.AccountUtils)3 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)3 RefreshFolderOperation (com.owncloud.android.operations.RefreshFolderOperation)3 Message (android.os.Message)2 Gson (com.google.gson.Gson)2