1 package com
.owncloud
.android
.authentication
;
3 import android
.app
.Activity
;
4 import android
.content
.Context
;
5 import android
.net
.Uri
;
6 import android
.os
.AsyncTask
;
8 import com
.owncloud
.android
.MainApp
;
9 import com
.owncloud
.android
.lib
.common
.OwnCloudClient
;
10 import com
.owncloud
.android
.lib
.common
.OwnCloudClientFactory
;
11 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentials
;
12 import com
.owncloud
.android
.lib
.common
.OwnCloudCredentialsFactory
;
13 import com
.owncloud
.android
.lib
.common
.accounts
.AccountTypeUtils
;
14 import com
.owncloud
.android
.lib
.common
.operations
.RemoteOperationResult
;
15 import com
.owncloud
.android
.lib
.resources
.files
.ExistenceCheckRemoteOperation
;
17 import java
.lang
.ref
.WeakReference
;
21 * Async Task to verify the credentials of a user
23 * @author masensio on 09/02/2015.
25 public class AuthenticatorAsyncTask
extends AsyncTask
<String
, Void
, RemoteOperationResult
> {
28 private static String REMOTE_PATH
= "/";
29 private static boolean SUCCESS_IF_ABSENT
= false
;
31 private Context mContext
;
32 private final WeakReference
<OnAuthenticatorTaskListener
> mListener
;
34 public AuthenticatorAsyncTask(Activity activity
) {
35 mContext
= activity
.getApplicationContext();
36 mListener
= new WeakReference
<OnAuthenticatorTaskListener
>((OnAuthenticatorTaskListener
)activity
);
40 protected RemoteOperationResult
doInBackground(String
... params
) {
42 RemoteOperationResult result
;
43 if (params
!= null
&& params
.length
==5) {
44 String url
= params
[0];
45 String username
= params
[1];
46 String password
= params
[2];
47 String authToken
= params
[3];
48 String authTokenType
= params
[4];
51 String basic
= AccountTypeUtils
.getAuthTokenTypePass(MainApp
.getAccountType());
52 String oAuth
= AccountTypeUtils
.getAuthTokenTypeAccessToken(MainApp
.getAccountType());
53 String saml
= AccountTypeUtils
.getAuthTokenTypeSamlSessionCookie(MainApp
.getAccountType());
55 Uri uri
= Uri
.parse(url
);
56 OwnCloudClient client
= OwnCloudClientFactory
.createOwnCloudClient(uri
, mContext
, false
);
57 OwnCloudCredentials credentials
= null
;
58 if (authTokenType
.equals(basic
)) {
59 credentials
= OwnCloudCredentialsFactory
.newBasicCredentials(
60 username
, password
); // basic
62 } else if (authTokenType
.equals(oAuth
)) {
63 credentials
= OwnCloudCredentialsFactory
.newBearerCredentials(
64 authToken
); // bearer token
66 } else if (authTokenType
.equals(saml
)) {
67 credentials
= OwnCloudCredentialsFactory
.newSamlSsoCredentials(
68 authToken
); // SAML SSO
71 client
.setCredentials(credentials
);
74 ExistenceCheckRemoteOperation operation
= new ExistenceCheckRemoteOperation(REMOTE_PATH
,
75 mContext
, SUCCESS_IF_ABSENT
);
76 result
= operation
.execute(client
);
79 result
= new RemoteOperationResult(RemoteOperationResult
.ResultCode
.UNKNOWN_ERROR
);
86 protected void onPostExecute(RemoteOperationResult result
) {
90 OnAuthenticatorTaskListener listener
= mListener
.get();
93 listener
.onAuthenticatorTaskCallback(result
);
99 * Interface to retrieve data from recognition task
101 public interface OnAuthenticatorTaskListener
{
103 void onAuthenticatorTaskCallback(RemoteOperationResult result
);