\r
private final Handler mHandler = new Handler();\r
private Thread mOperationThread;\r
- //private GetRemoteStatusOperation mOcServerChkOperation;\r
- private GetRemoteStatusOperation mOcServerChkOperation;\r
+ private GetServerInfoOperation mServerInfoOperation;\r
- private ExistenceCheckRemoteOperation mAuthCheckOperation;\r
+\r
+ //private ExistenceCheckRemoteOperation mAuthCheckOperation;\r
+ private int mExistenceCheckOpId = -1;\r
+ \r
private Uri mNewCapturedUriFromOAuth2Redirection;\r
\r
private AccountManager mAccountMgr;\r
showDialog(DIALOG_LOGIN_PROGRESS);\r
\r
/// test credentials accessing the root folder\r
- mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
- OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
- client.setBasicCredentials(username, password);\r
- mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
+ String remotePath ="";\r
+ boolean successIfAbsent = false;\r
+ boolean followRedirects = true;\r
+ startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects);\r
+ \r
}\r
\r
- Log.wtf(TAG, "starting existenceCheckRemoteOperation..." );\r
+ private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path,\r
+ String username, String password, boolean followRedirects) {\r
+ \r
+ Intent existenceCheckIntent = new Intent();\r
+ existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken);\r
+ existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
+ \r
+ if (mOperationsServiceBinder != null) {\r
++ Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." );\r
+ mExistenceCheckOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent);\r
+ }\r
+ }\r
\r
/**\r
* Starts the OAuth 'grant type' flow to get an access token, with \r
@Override\r
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
\r
- if (operation instanceof GetRemoteStatusOperation) {\r
- onOcServerCheckFinish((GetRemoteStatusOperation) operation, result);\r
+ if (operation instanceof GetServerInfoOperation) {\r
+ if (operation.hashCode() == mGetServerInfoOpId) {\r
+ onGetServerInfoFinish(result);\r
+ } // else nothing ; only the last check operation is considered; \r
+ // multiple can be started if the user amends a URL quickly\r
\r
} else if (operation instanceof OAuth2GetAccessToken) {\r
- onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result);\r
+ onGetOAuthAccessTokenFinish(result);\r
\r
} else if (operation instanceof ExistenceCheckRemoteOperation) {\r
- Log.wtf(TAG, "received detection response through callback" );\r
++ Log_OC.wtf(TAG, "received detection response through callback" );\r
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
- onSamlBasedFederatedSingleSignOnAuthorizationStart(operation, result);\r
+ onSamlBasedFederatedSingleSignOnAuthorizationStart(result);\r
\r
} else {\r
- onAuthorizationCheckFinish((ExistenceCheckRemoteOperation)operation, result);\r
+ onAuthorizationCheckFinish(result);\r
}\r
} else if (operation instanceof GetRemoteUserNameOperation) {\r
onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
\r
}\r
\r
- private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperation operation, RemoteOperationResult result) {\r
+ private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) {\r
++ mExistenceCheckOpId = -1;\r
try {\r
dismissDialog(DIALOG_LOGIN_PROGRESS);\r
} catch (IllegalArgumentException e) {\r
showDialog(DIALOG_LOGIN_PROGRESS);\r
\r
/// time to test the retrieved access token on the ownCloud server\r
- mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
+ @SuppressWarnings("unchecked")\r
+ Map<String, String> tokens = (Map<String, String>)(result.getData().get(0));\r
+ mAuthToken = tokens.get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
+ //mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
- mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
- OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
- client.setBearerCredentials(mAuthToken);\r
- mAuthCheckOperation.execute(client, this, mHandler);\r
+ \r
+ String remotePath ="";\r
+ boolean successIfAbsent = false;\r
+ boolean followRedirects = true;\r
+ startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects);\r
\r
} else {\r
updateAuthStatusIconAndText(result);\r
* @param operation Access check performed.\r
* @param result Result of the operation.\r
*/\r
- private void onAuthorizationCheckFinish(ExistenceCheckRemoteOperation operation, RemoteOperationResult result) {\r
+ private void onAuthorizationCheckFinish(RemoteOperationResult result) {\r
++ mExistenceCheckOpId = -1;\r
try {\r
dismissDialog(DIALOG_LOGIN_PROGRESS);\r
} catch (IllegalArgumentException e) {\r
//Log.wtf(TAG, "registering to listen for operation callbacks" );\r
mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
\r
- if (mDetectAuthOpId != -1) {\r
+ if (mGetServerInfoOpId != -1) {\r
RemoteOperationResult result = \r
- mOperationsServiceBinder.getOperationResultIfFinished(mDetectAuthOpId);\r
+ mOperationsServiceBinder.getOperationResultIfFinished(mGetServerInfoOpId);\r
if (result != null) {\r
-- //Log.wtf(TAG, "found result of operation finished while rotating");\r
- onDetectAuthenticationFinish(result);\r
++ //Log_OC.wtf(TAG, "found result of operation finished while rotating");\r
+ onGetServerInfoFinish(result);\r
}\r
- }\r
- \r
- if (mExistenceCheckOpId != -1) {\r
+ \r
+ } else if (mOauth2GetAccessTokenOpId != -1) {\r
+ RemoteOperationResult result = \r
+ mOperationsServiceBinder.getOperationResultIfFinished(\r
+ mOauth2GetAccessTokenOpId);\r
+ if (result != null) {\r
- //Log.wtf(TAG, "found result of operation finished while rotating");\r
++ //Log_OC.wtf(TAG, "found result of operation finished while rotating");\r
+ onGetOAuthAccessTokenFinish(result);\r
+ }\r
++ \r
++ } else if (mExistenceCheckOpId != -1) {\r
+ RemoteOperationResult result = \r
+ mOperationsServiceBinder.getOperationResultIfFinished(mExistenceCheckOpId);\r
+ if (result != null) {\r
- Log.wtf(TAG, "found result of operation finished while rotating");\r
- if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
++ //Log_OC.wtf(TAG, "found result of operation finished while rotating");\r
++ if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(\r
++ MainApp.getAccountType()).equals(mAuthTokenType)) {\r
+ onSamlBasedFederatedSingleSignOnAuthorizationStart(result);\r
+ \r
+ } else {\r
+ onAuthorizationCheckFinish(result);\r
+ }\r
+ }\r
}\r
}\r
\r
public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
public static final String EXTRA_RESULT = "RESULT";
+
++ // TODO review if ALL OF THEM are necessary
+ public static final String EXTRA_WEBDAV_PATH = "WEBDAV_PATH";
+ public static final String EXTRA_SUCCESS_IF_ABSENT = "SUCCESS_IF_ABSENT";
+ public static final String EXTRA_USERNAME = "USERNAME";
+ public static final String EXTRA_PASSWORD = "PASSWORD";
+ public static final String EXTRA_AUTH_TOKEN = "AUTH_TOKEN";
+ public static final String EXTRA_FOLLOW_REDIRECTS = "FOLLOW_REDIRECTS";
+
public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
public static final String ACTION_UNSHARE = "UNSHARE";
- public static final String ACTION_DETECT_AUTHENTICATION_METHOD = "DETECT_AUTHENTICATION_METHOD";
+ public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
+ public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN";
+ public static final String ACTION_EXISTENCE_CHECK = "EXISTENCE_CHECK";
public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
operation = new CreateShareOperation(remotePath, ShareType.PUBLIC_LINK,
"", false, "", 1, sendIntent);
}
++
} else if (action.equals(ACTION_UNSHARE)) { // Unshare file
String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
if (remotePath.length() > 0) {
remotePath,
OperationsService.this);
}
- } else if (action.equals(ACTION_DETECT_AUTHENTICATION_METHOD)) {
- // Detect Authentication Method
- String webdav_url =
- serverUrl + operationIntent.getStringExtra(EXTRA_WEBDAV_PATH);
- operation = new DetectAuthenticationMethodOperation(
- OperationsService.this,
- webdav_url);
++
+ } else if (action.equals(ACTION_GET_SERVER_INFO)) {
+ // check OC server and get basic information from it
+ String authTokenType =
+ operationIntent.getStringExtra(EXTRA_AUTH_TOKEN_TYPE);
+ operation = new GetServerInfoOperation(
+ serverUrl, authTokenType, OperationsService.this);
+
+ } else if (action.equals(ACTION_OAUTH2_GET_ACCESS_TOKEN)) {
+ /// GET ACCESS TOKEN to the OAuth server
+ String oauth2QueryParameters =
+ operationIntent.getStringExtra(EXTRA_OAUTH2_QUERY_PARAMETERS);
+ operation = new OAuth2GetAccessToken(
+ getString(R.string.oauth2_client_id),
+ getString(R.string.oauth2_redirect_uri),
+ getString(R.string.oauth2_grant_type),
+ oauth2QueryParameters);
++
+ } else if (action.equals(ACTION_EXISTENCE_CHECK)) {
+ // Existence Check
+ String remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
+ boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, true);
+ operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent);
+
}
}