From: David A. Velasco Date: Mon, 12 Aug 2013 09:34:09 +0000 (+0200) Subject: Expiration of SSO session is detected in background operations (download, upload... X-Git-Tag: oc-android-1.4.6~17^2~25 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/68df3cbfe7a7bc6d4df4bd435383ae70e4742496?ds=inline;hp=--cc Expiration of SSO session is detected in background operations (download, upload, sync account) and error notification lets the user access to the login view --- 68df3cbfe7a7bc6d4df4bd435383ae70e4742496 diff --git a/res/values/setup.xml b/res/values/setup.xml index 3e39fabb..f3982412 100644 --- a/res/values/setup.xml +++ b/res/values/setup.xml @@ -1,6 +1,6 @@ - https://bwlsdf-owncloud1.lsdf.kit.edu/oc-shib + https://bwlsdf-owncloud1.lsdf.kit.edu/oc-shib-dev true diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 02a8a452..9410e6df 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -28,6 +28,7 @@ import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; @@ -463,7 +464,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis int contentId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_content : R.string.downloader_download_failed_content; Notification finalNotification = new Notification(R.drawable.icon, getString(tickerId), System.currentTimeMillis()); finalNotification.flags |= Notification.FLAG_AUTO_CANCEL; - boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED); + boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED || + (downloadResult.isTemporalRedirection() && AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mDownloadClient.getAuthTokenType()))); if (needsToUpdateCredentials) { // let the user update credentials with one click Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class); diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 96c7fdcf..6b12fa51 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -791,7 +791,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe Notification finalNotification = new Notification(R.drawable.icon, getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis()); finalNotification.flags |= Notification.FLAG_AUTO_CANCEL; - if (uploadResult.getCode() == ResultCode.UNAUTHORIZED) { + if (uploadResult.getCode() == ResultCode.UNAUTHORIZED || + (uploadResult.isTemporalRedirection() && AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(mUploadClient.getAuthTokenType()))) { // let the user update credentials with one click Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class); updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount()); diff --git a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java index 8653fe78..2bf135bc 100644 --- a/src/com/owncloud/android/syncadapter/FileSyncAdapter.java +++ b/src/com/owncloud/android/syncadapter/FileSyncAdapter.java @@ -28,6 +28,7 @@ import org.apache.jackrabbit.webdav.DavException; import com.owncloud.android.Log_OC; import com.owncloud.android.R; +import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.DataStorageManager; import com.owncloud.android.datamodel.FileDataStorageManager; @@ -223,7 +224,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { sendStickyBroadcast(true, remotePath, null); } else { - if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED) { + if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED || + (result.isTemporalRedirection() && getClient().getSsoSessionCookie() != null)) { mSyncResult.stats.numAuthExceptions++; } else if (result.getException() instanceof DavException) { @@ -304,7 +306,11 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter { private void notifyFailedSynchronization() { Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_ticker), System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; - boolean needsToUpdateCredentials = (mLastFailedResult != null && mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED); + boolean needsToUpdateCredentials = (mLastFailedResult != null && + ( mLastFailedResult.getCode() == ResultCode.UNAUTHORIZED || + (mLastFailedResult.isTemporalRedirection() && AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE.equals(getClient().getAuthTokenType())) + ) + ); // TODO put something smart in the contentIntent below for all the possible errors notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0); if (needsToUpdateCredentials) { diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index 43a6743c..dd484084 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -41,9 +41,11 @@ import org.apache.http.params.CoreProtocolPNames; import com.owncloud.android.Log_OC; +import com.owncloud.android.authentication.AccountAuthenticator; import com.owncloud.android.network.BearerAuthScheme; import com.owncloud.android.network.BearerCredentials; +import android.accounts.AccountAuthenticatorActivity; import android.net.Uri; public class WebdavClient extends HttpClient { @@ -51,6 +53,7 @@ public class WebdavClient extends HttpClient { private Credentials mCredentials; private boolean mFollowRedirects; private String mSsoSessionCookie; + private String mAuthTokenType; final private static String TAG = "WebdavClient"; public static final String USER_AGENT = "Android-ownCloud"; @@ -66,6 +69,7 @@ public class WebdavClient extends HttpClient { getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); mFollowRedirects = true; mSsoSessionCookie = null; + mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD; } public void setBearerCredentials(String accessToken) { @@ -78,6 +82,7 @@ public class WebdavClient extends HttpClient { mCredentials = new BearerCredentials(accessToken); getState().setCredentials(AuthScope.ANY, mCredentials); mSsoSessionCookie = null; + mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN; } public void setBasicCredentials(String username, String password) { @@ -89,6 +94,7 @@ public class WebdavClient extends HttpClient { mCredentials = new UsernamePasswordCredentials(username, password); getState().setCredentials(AuthScope.ANY, mCredentials); mSsoSessionCookie = null; + mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD; } public void setSsoSessionCookie(String accessToken) { @@ -96,6 +102,7 @@ public class WebdavClient extends HttpClient { getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); mSsoSessionCookie = accessToken; mCredentials = null; + mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE; } @@ -215,4 +222,8 @@ public class WebdavClient extends HttpClient { mFollowRedirects = followRedirects; } + public String getAuthTokenType() { + return mAuthTokenType; + } + }