Search in sources :

Example 1 with RedirectionPath

use of com.owncloud.android.lib.common.network.RedirectionPath 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;
}
Also used : RedirectionPath(com.owncloud.android.lib.common.network.RedirectionPath) GetRemoteUserInfoOperation(com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation) ExistenceCheckRemoteOperation(com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation) RemoteOperationResult(com.owncloud.android.lib.common.operations.RemoteOperationResult) OwnCloudClient(com.owncloud.android.lib.common.OwnCloudClient) Uri(android.net.Uri) OwnCloudCredentials(com.owncloud.android.lib.common.OwnCloudCredentials)

Aggregations

Uri (android.net.Uri)1 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)1 OwnCloudCredentials (com.owncloud.android.lib.common.OwnCloudCredentials)1 RedirectionPath (com.owncloud.android.lib.common.network.RedirectionPath)1 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)1 ExistenceCheckRemoteOperation (com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation)1 GetRemoteUserInfoOperation (com.owncloud.android.lib.resources.users.GetRemoteUserInfoOperation)1