package com.owncloud.android.authentication;\r
\r
import java.security.cert.X509Certificate;\r
+import java.util.Map;\r
\r
import android.accounts.Account;\r
import android.accounts.AccountManager;\r
import android.text.Editable;\r
import android.text.InputType;\r
import android.text.TextWatcher;\r
-import android.util.Log;\r
import android.view.KeyEvent;\r
import android.view.MotionEvent;\r
import android.view.View;\r
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
import com.owncloud.android.lib.common.OwnCloudClientFactory;\r
import com.owncloud.android.lib.common.OwnCloudClient;\r
-import com.owncloud.android.operations.DetectAuthenticationMethodOperation;\r
import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
import com.owncloud.android.operations.GetServerInfoOperation;\r
import com.owncloud.android.operations.OAuth2GetAccessToken;\r
private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
private AuthenticationMethod mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
- private int mDetectAuthOpId = -1;\r
+\r
+ private int mGetServerInfoOpId = -1;\r
+ private int mOauth2GetAccessTokenOpId = -1;\r
\r
private int mAuthStatusText, mAuthStatusIcon; \r
private TextView mAuthStatusLayout;\r
\r
mServerAuthMethod = AuthenticationMethod.valueOf(\r
savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));\r
- mDetectAuthOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID);\r
+ mGetServerInfoOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID);\r
\r
}\r
\r
mOAuth2Check.setVisibility(View.GONE);\r
}\r
\r
- //showRefreshButton(mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled);\r
showRefreshButton(mServerIsChecked && !mServerIsValid && refreshButtonEnabled);\r
mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
\r
outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
\r
outState.putString(KEY_SERVER_AUTH_METHOD, mServerAuthMethod.name());\r
- outState.putInt(KEY_DETECT_AUTH_OP_ID, mDetectAuthOpId);\r
+ outState.putInt(KEY_DETECT_AUTH_OP_ID, mGetServerInfoOpId);\r
//Log.wtf(TAG, "onSaveInstanceState end" );\r
}\r
\r
/// Showing the dialog with instructions for the user.\r
showDialog(DIALOG_OAUTH2_LOGIN_PROGRESS);\r
\r
- /// GET ACCESS TOKEN to the oAuth server \r
+ /// GET ACCESS TOKEN to the oAuth server\r
+ Intent getServerInfoIntent = new Intent();\r
+ getServerInfoIntent.setAction(OperationsService.ACTION_OAUTH2_GET_ACCESS_TOKEN);\r
+ \r
+ getServerInfoIntent.putExtra(\r
+ OperationsService.EXTRA_SERVER_URL, \r
+ mOAuthTokenEndpointText.getText().toString().trim());\r
+ \r
+ getServerInfoIntent.putExtra(\r
+ OperationsService.EXTRA_OAUTH2_QUERY_PARAMETERS, \r
+ queryParameters);\r
+ \r
+ if (mOperationsServiceBinder != null) {\r
+ //Log.wtf(TAG, "getting access token..." );\r
+ mOauth2GetAccessTokenOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
+ }\r
+ \r
+ /*\r
RemoteOperation operation = new OAuth2GetAccessToken( getString(R.string.oauth2_client_id), \r
getString(R.string.oauth2_redirect_uri), \r
getString(R.string.oauth2_grant_type),\r
//OwnCloudClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext(), true);\r
operation.execute(client, this, mHandler);\r
+ */\r
+ \r
}\r
\r
\r
mServerStatusText = R.string.auth_testing_connection;\r
mServerStatusIcon = R.drawable.progress_small;\r
showServerStatus();\r
- mServerInfoOperation = new GetServerInfoOperation(uri, mAuthTokenType, this);\r
- OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
- mServerInfoOperation.execute(client, this, mHandler);\r
\r
- /*\r
- * TODO start joint operation in OperationsService\r
- Intent detectAuthIntent = new Intent();\r
- detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mBaseUrl);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
+ Intent getServerInfoIntent = new Intent();\r
+ getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
+ getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
+ getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType);\r
if (mOperationsServiceBinder != null) {\r
- //Log.wtf(TAG, "starting detection..." );\r
- mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent);\r
+ //Log.wtf(TAG, "checking server..." );\r
+ mGetServerInfoOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
}\r
- */\r
\r
} else {\r
mServerStatusText = 0;\r
mAuthStatusText = R.string.oauth_login_connection;\r
showAuthStatus();\r
\r
-\r
// GET AUTHORIZATION request\r
//Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
\r
if (operation instanceof GetServerInfoOperation) {\r
- if (operation.equals(mServerInfoOperation)) {\r
+ if (operation.hashCode() == mGetServerInfoOpId) {\r
onGetServerInfoFinish(result);\r
} // else nothing ; only the last check operation is considered; \r
- // multiple can be triggered if the user amends a URL before a previous check \r
- // can be triggered\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
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) {\r
} else if (operation instanceof GetRemoteUserNameOperation) {\r
onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
\r
- } else if (operation instanceof DetectAuthenticationMethodOperation) {\r
- Log.wtf(TAG, "received detection response through callback" );\r
- onDetectAuthenticationFinish(result);\r
}\r
\r
}\r
\r
- private void onDetectAuthenticationFinish(RemoteOperationResult result) {\r
- // Read authentication method\r
- mDetectAuthOpId = -1;\r
- if (result.getData().size() > 0) {\r
- AuthenticationMethod authMethod = (AuthenticationMethod) result.getData().get(0);\r
- String basic = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());\r
- String oAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());\r
- String saml = AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
-\r
- if ( ( mAuthTokenType.equals(basic) && !authMethod.equals(AuthenticationMethod.BASIC_HTTP_AUTH) ) ||\r
- ( mAuthTokenType.equals(oAuth) && !authMethod.equals(AuthenticationMethod.BEARER_TOKEN) ) || \r
- ( mAuthTokenType.equals(saml) && !authMethod.equals(AuthenticationMethod.SAML_WEB_SSO) ) ) {\r
-\r
- mOkButton.setEnabled(false);\r
- mServerIsValid = false;\r
- //show an alert message ( Server Status )\r
- updateServerStatusIconNoRegularAuth();\r
- showServerStatus();\r
-\r
- } else {\r
- mOkButton.setEnabled(true);\r
-\r
- // Show server status\r
- showServerStatus();\r
- }\r
-\r
- }\r
- }\r
-\r
-\r
-\r
private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) {\r
\r
if (result.isSuccess()) {\r
mServerIsChecked = true;\r
mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
mServerInfoOperation = null;\r
- mDetectAuthOpId = -1;\r
+ mGetServerInfoOpId = -1;\r
\r
// update server status, but don't show it yet\r
updateServerStatusIconAndText(result);\r
mServerInfo = (GetServerInfoOperation.ServerInfo) (result.getData().get(0));\r
mDiscoveredVersion = mServerInfo.mVersion;\r
mHostBaseUrl = mServerInfo.mBaseUrl;\r
+ mServerAuthMethod = mServerInfo.mAuthMethod;\r
\r
- if (!authSupported(mServerInfo.mAuthMethod)) {\r
+ if (!authSupported(mServerAuthMethod)) {\r
\r
updateServerStatusIconNoRegularAuth(); // overrides updateServerStatusIconAndText() \r
mServerIsValid = false;\r
}\r
\r
\r
- /**\r
- * Try to access with user/pass ""/"", to know if it is a regular server\r
- */\r
- private void detectAuthorizationMethod() {\r
-\r
- Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
- \r
- String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
- \r
- /// test credentials \r
- //Intent detectAuthIntent = new Intent(this, OperationsService.class);\r
- Intent detectAuthIntent = new Intent();\r
- detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
- detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
- \r
- //if (mOperationsBinder != null) { // let's let it crash to detect if is really possible\r
- mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
- if (mOperationsServiceBinder != null) {\r
- //Log.wtf(TAG, "starting detection..." );\r
- mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent);\r
- }\r
- //}\r
- }\r
-\r
-\r
// TODO remove, if possible\r
private String normalizeUrl(String url) {\r
if (url != null && url.length() > 0) {\r
* Processes the result of the request for and access token send \r
* to an OAuth authorization server.\r
* \r
- * @param operation Operation performed requesting the access token.\r
* @param result Result of the operation.\r
*/\r
- private void onGetOAuthAccessTokenFinish(OAuth2GetAccessToken operation, RemoteOperationResult result) {\r
+ private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {\r
+ mOauth2GetAccessTokenOpId = -1;\r
try {\r
dismissDialog(DIALOG_OAUTH2_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
//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(mGetServerInfoOpId);\r
+ if (result != null) {\r
+ //Log.wtf(TAG, "found result of operation finished while rotating");\r
+ onGetServerInfoFinish(result);\r
+ }\r
+ \r
+ } else if (mOauth2GetAccessTokenOpId != -1) {\r
RemoteOperationResult result = \r
- mOperationsServiceBinder.getOperationResultIfFinished(mDetectAuthOpId);\r
+ mOperationsServiceBinder.getOperationResultIfFinished(\r
+ mOauth2GetAccessTokenOpId);\r
if (result != null) {\r
//Log.wtf(TAG, "found result of operation finished while rotating");\r
- onDetectAuthenticationFinish(result);\r
+ onGetOAuthAccessTokenFinish(result);\r
}\r
}\r
}\r