Merge branch 'develop' of https://github.com/owncloud/android into material_toolbar
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorAsyncTask.java
index 6e21534..a25ade8 100644 (file)
@@ -1,5 +1,8 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012-2015 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author masensio on 09/02/2015.
+ *   Copyright (C) 2015 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,
@@ -21,12 +24,10 @@ import android.content.Context;
 import android.net.Uri;
 import android.os.AsyncTask;
 
-import com.owncloud.android.MainApp;
 import com.owncloud.android.lib.common.OwnCloudClient;
 import com.owncloud.android.lib.common.OwnCloudClientFactory;
 import com.owncloud.android.lib.common.OwnCloudCredentials;
-import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
-import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
+import com.owncloud.android.lib.common.network.RedirectionPath;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 
@@ -35,10 +36,8 @@ import java.lang.ref.WeakReference;
 
 /**
  * Async Task to verify the credentials of a user
- *
- * @author masensio on 09/02/2015.
  */
-public class AuthenticatorAsyncTask  extends AsyncTask<String, Void, RemoteOperationResult> {
+public class AuthenticatorAsyncTask  extends AsyncTask<Object, Void, RemoteOperationResult> {
 
     private static String REMOTE_PATH = "/";
     private static boolean SUCCESS_IF_ABSENT = false;
@@ -50,48 +49,35 @@ public class AuthenticatorAsyncTask  extends AsyncTask<String, Void, RemoteOpera
     public AuthenticatorAsyncTask(Activity activity) {
         mContext = activity.getApplicationContext();
         mListener = new WeakReference<OnAuthenticatorTaskListener>((OnAuthenticatorTaskListener)activity);
-        mActivity = activity;
     }
 
     @Override
-    protected RemoteOperationResult doInBackground(String... params) {
+    protected RemoteOperationResult doInBackground(Object... params) {
 
         RemoteOperationResult result;
-        if (params!= null && params.length==5) {
-            String url = params[0];
-            String username = params[1];
-            String password = params[2];
-            String authToken = params[3];
-            String authTokenType = params[4];
+        if (params!= null && params.length==2) {
+            String url = (String)params[0];
+            OwnCloudCredentials credentials = (OwnCloudCredentials)params[1];
 
             // Client
-            String basic = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());
-            String oAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());
-            String saml =  AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());
-
             Uri uri = Uri.parse(url);
-            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, false);
-            OwnCloudCredentials credentials = null;
-            if (authTokenType.equals(basic)) {
-                credentials = OwnCloudCredentialsFactory.newBasicCredentials(
-                        username, password); // basic
-
-            } else if (authTokenType.equals(oAuth)) {
-                credentials = OwnCloudCredentialsFactory.newBearerCredentials(
-                        authToken);  // bearer token
-
-            } else if (authTokenType.equals(saml)) {
-                credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(
-                        authToken); // SAML SSO
-            }
-
+            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(uri, mContext, true);
             client.setCredentials(credentials);
 
             // Operation
-            ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(REMOTE_PATH,
-                    mContext, SUCCESS_IF_ABSENT);
+            ExistenceCheckRemoteOperation operation = new ExistenceCheckRemoteOperation(
+                    REMOTE_PATH,
+                    mContext,
+                    SUCCESS_IF_ABSENT
+            );
             result = operation.execute(client);
 
+            if (operation.wasRedirected()) {
+                RedirectionPath redirectionPath = operation.getRedirectionPath();
+                String permanentLocation = redirectionPath.getLastPermanentLocation();
+                result.setLastPermanentLocation(permanentLocation);
+            }
+
         } else {
             result = new RemoteOperationResult(RemoteOperationResult.ResultCode.UNKNOWN_ERROR);
         }