mirror of
https://github.com/nextcloud/android.git
synced 2024-11-28 02:17:43 +03:00
Fixed operation of app after SAML expired sessions while editing share permissions
This commit is contained in:
parent
2681f8c22b
commit
c9017a2b0a
4 changed files with 52 additions and 62 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 275c042f7884f8a56cb4b5cb94ef9be98884e698
|
||||
Subproject commit 95919c9005aac54e7707f0fdc3c5b9dfdb29dac1
|
|
@ -62,6 +62,10 @@ import com.owncloud.android.files.services.FileDownloader;
|
|||
import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperation;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
|
@ -739,7 +743,7 @@ public class FileActivity extends AppCompatActivity
|
|||
(result.isException() && result.getException() instanceof AuthenticatorException)
|
||||
)) {
|
||||
|
||||
requestCredentialsUpdate();
|
||||
requestCredentialsUpdate(this);
|
||||
|
||||
if (result.getCode() == ResultCode.UNAUTHORIZED) {
|
||||
dismissLoadingDialog();
|
||||
|
@ -785,7 +789,38 @@ public class FileActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
|
||||
protected void requestCredentialsUpdate() {
|
||||
/**
|
||||
* Invalidates the credentials stored for the current OC account and requests new credentials to the user,
|
||||
* navigating to {@link AuthenticatorActivity}
|
||||
*
|
||||
* @param context Android Context needed to access the {@link AccountManager}. Received as a parameter
|
||||
* to make the method accessible to {@link android.content.BroadcastReceiver}s.
|
||||
*/
|
||||
protected void requestCredentialsUpdate(Context context) {
|
||||
|
||||
try {
|
||||
/// step 1 - invalidate credentials of current account
|
||||
OwnCloudClient client;
|
||||
OwnCloudAccount ocAccount =
|
||||
new OwnCloudAccount(getAccount(), context);
|
||||
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
removeClientFor(ocAccount));
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// step 2 - request credentials to user
|
||||
Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
|
||||
updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, getAccount());
|
||||
updateAccountCredentials.putExtra(
|
||||
|
@ -793,6 +828,11 @@ public class FileActivity extends AppCompatActivity
|
|||
AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN);
|
||||
updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||
startActivity(updateAccountCredentials);
|
||||
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
Toast.makeText(context, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -968,32 +968,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
(synchResult.isException() && synchResult.getException()
|
||||
instanceof AuthenticatorException))) {
|
||||
|
||||
|
||||
try {
|
||||
OwnCloudClient client;
|
||||
OwnCloudAccount ocAccount =
|
||||
new OwnCloudAccount(getAccount(), context);
|
||||
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
removeClientFor(ocAccount));
|
||||
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(context);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -491,32 +491,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
|
|||
(synchResult.isException() && synchResult.getException()
|
||||
instanceof AuthenticatorException))) {
|
||||
|
||||
try {
|
||||
OwnCloudClient client;
|
||||
OwnCloudAccount ocAccount =
|
||||
new OwnCloudAccount(getAccount(), context);
|
||||
client = (OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
removeClientFor(ocAccount));
|
||||
|
||||
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(context);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue