diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java index 041f72fa..6fb5345f 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClientFactory.java @@ -24,123 +24,13 @@ package com.owncloud.android.lib.common; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.AccountManagerFuture; -import android.accounts.AuthenticatorException; -import android.accounts.OperationCanceledException; -import android.app.Activity; import android.content.Context; import android.net.Uri; -import android.os.Bundle; - -import com.owncloud.android.lib.common.accounts.AccountTypeUtils; -import com.owncloud.android.lib.common.accounts.AccountUtils; -import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; -import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.resources.status.OwnCloudVersion; - -import java.io.IOException; public class OwnCloudClientFactory { final private static String TAG = OwnCloudClientFactory.class.getSimpleName(); - /** - * Creates a OwnCloudClient setup for an ownCloud account - *

- * Do not call this method from the main thread. - * - * @param account The ownCloud account - * @param appContext Android application context - * @param currentActivity Caller {@link Activity} - * @return A OwnCloudClient object ready to be used - * @throws AuthenticatorException If the authenticator failed to get the authorization - * token for the account. - * @throws OperationCanceledException If the authenticator operation was cancelled while - * getting the authorization token for the account. - * @throws IOException If there was some I/O error while getting the - * authorization token for the account. - * @throws AccountNotFoundException If 'account' is unknown for the AccountManager - */ - public static OwnCloudClient createOwnCloudClient(Account account, Context appContext, - Activity currentActivity) - throws OperationCanceledException, AuthenticatorException, IOException, - AccountNotFoundException { - Uri baseUri = Uri.parse(AccountUtils.getBaseUrlForAccount(appContext, account)); - AccountManager am = AccountManager.get(appContext); - // TODO avoid calling to getUserData here - boolean isOauth2 = - am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null; - boolean isSamlSso = - am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null; - OwnCloudClient client = createOwnCloudClient(baseUri, appContext, !isSamlSso); - - String username = AccountUtils.getUsernameForAccount(account); - if (isOauth2) { // TODO avoid a call to getUserData here - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), - null, - currentActivity, - null, - null); - - Bundle result = future.getResult(); - String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); - if (accessToken == null) { - throw new AuthenticatorException("WTF!"); - } - client.setCredentials( - OwnCloudCredentialsFactory.newBearerCredentials(username, accessToken) - ); - - } else if (isSamlSso) { // TODO avoid a call to getUserData here - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), - null, - currentActivity, - null, - null); - - Bundle result = future.getResult(); - String accessToken = result.getString(AccountManager.KEY_AUTHTOKEN); - if (accessToken == null) { - throw new AuthenticatorException("WTF!"); - } - client.setCredentials( - OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken) - ); - - } else { - AccountManagerFuture future = am.getAuthToken( - account, - AccountTypeUtils.getAuthTokenTypePass(account.type), - null, - currentActivity, - null, - null - ); - - Bundle result = future.getResult(); - String password = result.getString(AccountManager.KEY_AUTHTOKEN); - OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext); - client.setCredentials( - OwnCloudCredentialsFactory.newBasicCredentials( - username, - password, - (version != null && version.isPreemptiveAuthenticationPreferred()) - ) - ); - } - - // Restore cookies - AccountUtils.restoreCookies(account, client, appContext); - - return client; - } - /** * Creates a OwnCloudClient to access a URL and sets the desired parameters for ownCloud * client connections. diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java index 83d1625c..935004dd 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/authentication/oauth/OwnCloudOAuth2RequestBuilder.java @@ -152,5 +152,4 @@ public class OwnCloudOAuth2RequestBuilder implements OAuth2RequestBuilder { ); } } - } diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt index 321f170b..f74a7e75 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/shares/GetRemoteSharesForFileOperation.kt @@ -75,7 +75,7 @@ class GetRemoteSharesForFileOperation( val getMethod = GetMethod(URL(uriBuilder.build().toString())) - getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE) + getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE) val status = client.executeHttpMethod(getMethod)