Merge remote-tracking branch 'origin/enable_cookies' into enable_cookies

Conflicts:
	src/com/owncloud/android/authentication/AuthenticatorActivity.java
	src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java
This commit is contained in:
masensio 2015-02-13 14:39:35 +01:00
commit fba65e37f6
5 changed files with 79 additions and 68 deletions

View file

@ -193,6 +193,7 @@
<string name="auth_fail_get_user_name">Your server is not returning a correct user id, please contact an administrator
</string>
<string name="auth_can_not_auth_against_server">Cannot authenticate against this server</string>
<string name="auth_account_does_not_exist">Account does not exist in the device yet</string>
<string name="fd_keep_in_sync">Keep file up to date</string>
<string name="common_rename">Rename</string>

View file

@ -65,7 +65,10 @@ import com.actionbarsherlock.app.SherlockDialogFragment;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.network.CertificateCombinedException;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
@ -1020,20 +1023,20 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
if (!mUsernameInput.getText().toString().equals(username)) {
// fail - not a new account, but an existing one; disallow
result = new RemoteOperationResult(ResultCode.ACCOUNT_NOT_THE_SAME);
/*
OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(
new OwnCloudAccount(
Uri.parse(mServerInfo.mBaseUrl),
OwnCloudCredentialsFactory.newSamlSsoCredentials(mAuthToken))
);
*/
mAuthToken = "";
updateAuthStatusIconAndText(result);
showAuthStatus();
Log_OC.d(TAG, result.getLogMessage());
} else {
updateToken();
success = true;
try {
updateAccountAuthentication();
success = true;
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
finish();
}
}
}
@ -1399,8 +1402,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
success = createAccount();
} else {
updateToken();
success = true;
try {
updateAccountAuthentication();
success = true;
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);
Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
finish();
}
}
if (success) {
@ -1441,10 +1451,23 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
/**
* Sets the proper response to get that the Account Authenticator that started this activity
* Updates the authentication token.
*
* Sets the proper response so that the AccountAuthenticator that started this activity
* saves a new authorization token for mAccount.
*
* Kills the session kept by OwnCloudClientManager so that a new one will created with
* the new credentials when needed.
*/
private void updateToken() {
private void updateAccountAuthentication() throws AccountNotFoundException {
try {
OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(
new OwnCloudAccount(mAccount, this)
);
} catch (Exception e) {
Log_OC.e(TAG, "Exception", e);
}
Bundle response = new Bundle();
response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);
response.putString(AccountManager.KEY_ACCOUNT_TYPE, mAccount.type);

View file

@ -49,7 +49,7 @@ public class AuthenticatorAsyncTask extends AsyncTask<String, Void, RemoteOpera
public AuthenticatorAsyncTask(Activity activity) {
mContext = activity.getApplicationContext();
mListener = new WeakReference<>((OnAuthenticatorTaskListener)activity);
mListener = new WeakReference<OnAuthenticatorTaskListener>((OnAuthenticatorTaskListener)activity);
mActivity = activity;
}

View file

@ -1110,40 +1110,34 @@ OnSslUntrustedCertListener, OnEnforceableRefreshListener {
(synchResult.isException() && synchResult.getException()
instanceof AuthenticatorException))) {
OwnCloudClient client = null;
try {
OwnCloudAccount ocAccount =
OwnCloudClient client;
OwnCloudAccount ocAccount =
new OwnCloudAccount(getAccount(), context);
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
removeClientFor(ocAccount));
// TODO get rid of these exceptions
} catch (AccountNotFoundException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
AccountManager am = AccountManager.get(context);
if (cred.authTokenExpires()) {
am.invalidateAuthToken(
getAccount().type,
cred.getAuthToken()
);
} else {
am.clearPassword(getAccount());
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
AccountManager am = AccountManager.get(context);
if (cred.authTokenExpires()) {
am.invalidateAuthToken(
getAccount().type,
cred.getAuthToken()
);
} else {
am.clearPassword(getAccount());
}
}
}
requestCredentialsUpdate();
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e);
}
requestCredentialsUpdate();
}
}
removeStickyBroadcast(intent);

View file

@ -489,40 +489,33 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
(synchResult.isException() && synchResult.getException()
instanceof AuthenticatorException))) {
OwnCloudClient client = null;
try {
OwnCloudAccount ocAccount =
OwnCloudClient client;
OwnCloudAccount ocAccount =
new OwnCloudAccount(getAccount(), context);
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
removeClientFor(ocAccount));
// TODO get rid of these exceptions
} catch (AccountNotFoundException e) {
e.printStackTrace();
} catch (AuthenticatorException e) {
e.printStackTrace();
} catch (OperationCanceledException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
AccountManager am = AccountManager.get(context);
if (cred.authTokenExpires()) {
am.invalidateAuthToken(
getAccount().type,
cred.getAuthToken()
);
} else {
am.clearPassword(getAccount());
if (client != null) {
OwnCloudCredentials cred = client.getCredentials();
if (cred != null) {
AccountManager am = AccountManager.get(context);
if (cred.authTokenExpires()) {
am.invalidateAuthToken(
getAccount().type,
cred.getAuthToken()
);
} else {
am.clearPassword(getAccount());
}
}
}
requestCredentialsUpdate();
} catch (AccountNotFoundException e) {
Log_OC.e(TAG, "Account " + getAccount() + " was removed!", e);
}
requestCredentialsUpdate();
}
}
removeStickyBroadcast(intent);