X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/52bd01bcedf1b8f13c49b67ee40a848bae1a9d40..c2abbaaedb69dba35866a48b745b68f3519cbca1:/src/com/owncloud/android/operations/RemoteOperation.java diff --git a/src/com/owncloud/android/operations/RemoteOperation.java b/src/com/owncloud/android/operations/RemoteOperation.java index 711a72b0..fbb93e61 100644 --- a/src/com/owncloud/android/operations/RemoteOperation.java +++ b/src/com/owncloud/android/operations/RemoteOperation.java @@ -21,11 +21,12 @@ import java.io.IOException; import org.apache.commons.httpclient.Credentials; import com.owncloud.android.Log_OC; -import com.owncloud.android.authentication.AccountAuthenticator; +import com.owncloud.android.MainApp; import com.owncloud.android.network.BearerCredentials; import com.owncloud.android.network.OwnCloudClientUtils; import com.owncloud.android.operations.RemoteOperationResult.ResultCode; + import android.accounts.Account; import android.accounts.AccountManager; import android.accounts.AccountsException; @@ -242,18 +243,28 @@ public abstract class RemoteOperation implements Runnable { result = run(mClient); repeat = false; - if (mCallerActivity != null && mAccount != null && mContext != null && !result.isSuccess() && result.getCode() == ResultCode.UNAUTHORIZED) { - /// fail due to lack of authorization in an operation performed in foreground - AccountManager am = AccountManager.get(mContext); + if (mCallerActivity != null && mAccount != null && mContext != null && !result.isSuccess() && +// (result.getCode() == ResultCode.UNAUTHORIZED || (result.isTemporalRedirection() && result.isIdPRedirection()))) { + (result.getCode() == ResultCode.UNAUTHORIZED || result.isIdPRedirection())) { + /// possible fail due to lack of authorization in an operation performed in foreground Credentials cred = mClient.getCredentials(); - if (cred instanceof BearerCredentials) { - am.invalidateAuthToken(AccountAuthenticator.ACCOUNT_TYPE, ((BearerCredentials)cred).getAccessToken()); - } else { - am.clearPassword(mAccount); + String ssoSessionCookie = mClient.getSsoSessionCookie(); + if (cred != null || ssoSessionCookie != null) { + /// confirmed : unauthorized operation + AccountManager am = AccountManager.get(mContext); + boolean bearerAuthorization = (cred != null && cred instanceof BearerCredentials); + boolean samlBasedSsoAuthorization = (cred == null && ssoSessionCookie != null); + if (bearerAuthorization) { + am.invalidateAuthToken(MainApp.getAccountType(), ((BearerCredentials)cred).getAccessToken()); + } else if (samlBasedSsoAuthorization ) { + am.invalidateAuthToken(MainApp.getAccountType(), ssoSessionCookie); + } else { + am.clearPassword(mAccount); + } + mClient = null; + repeat = true; // when repeated, the creation of a new OwnCloudClient after erasing the saved credentials will trigger the login activity + result = null; } - mClient = null; - repeat = true; // when repeated, the creation of a new OwnCloudClient after erasing the saved credentials will trigger the login activity - result = null; } } while (repeat); @@ -278,4 +289,5 @@ public abstract class RemoteOperation implements Runnable { return mClient; } + }