Browse Source

Expiration of SSO session is detected in background operations (download, upload, sync account) and error notification lets the user access to the login view

David A. Velasco 11 years ago
parent
commit
68df3cbfe7

+ 1 - 1
res/values/setup.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
 <resources>
-    <string name="server_url">https://bwlsdf-owncloud1.lsdf.kit.edu/oc-shib</string>
+    <string name="server_url">https://bwlsdf-owncloud1.lsdf.kit.edu/oc-shib-dev</string>
     <bool name="show_server_url_input">true</bool>
     <bool name="show_server_url_input">true</bool>
     
     
     <!-- Flags to setup the authentication methods available in the app -->
     <!-- Flags to setup the authentication methods available in the app -->

+ 3 - 1
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.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ConcurrentMap;
 
 
+import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 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;
             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());
             Notification finalNotification = new Notification(R.drawable.icon, getString(tickerId), System.currentTimeMillis());
             finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
             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) {
             if (needsToUpdateCredentials) {
                 // let the user update credentials with one click
                 // let the user update credentials with one click
                 Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
                 Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);

+ 2 - 1
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,
             Notification finalNotification = new Notification(R.drawable.icon,
                     getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis());
                     getString(R.string.uploader_upload_failed_ticker), System.currentTimeMillis());
             finalNotification.flags |= Notification.FLAG_AUTO_CANCEL;
             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
                 // let the user update credentials with one click
                 Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
                 Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
                 updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount());
                 updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, upload.getAccount());

+ 8 - 2
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.Log_OC;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
+import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.authentication.AuthenticatorActivity;
 import com.owncloud.android.datamodel.DataStorageManager;
 import com.owncloud.android.datamodel.DataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -223,7 +224,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             sendStickyBroadcast(true, remotePath, null);
             sendStickyBroadcast(true, remotePath, null);
             
             
         } else {
         } else {
-            if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED) {
+            if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED ||
+                    (result.isTemporalRedirection() && getClient().getSsoSessionCookie() != null)) {
                 mSyncResult.stats.numAuthExceptions++;
                 mSyncResult.stats.numAuthExceptions++;
                 
                 
             } else if (result.getException() instanceof DavException) {
             } else if (result.getException() instanceof DavException) {
@@ -304,7 +306,11 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private void notifyFailedSynchronization() {
     private void notifyFailedSynchronization() {
         Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_ticker), System.currentTimeMillis());
         Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_ticker), System.currentTimeMillis());
         notification.flags |= Notification.FLAG_AUTO_CANCEL;
         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
         // 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);
         notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);
         if (needsToUpdateCredentials) {
         if (needsToUpdateCredentials) {

+ 11 - 0
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.Log_OC;
 
 
+import com.owncloud.android.authentication.AccountAuthenticator;
 import com.owncloud.android.network.BearerAuthScheme;
 import com.owncloud.android.network.BearerAuthScheme;
 import com.owncloud.android.network.BearerCredentials;
 import com.owncloud.android.network.BearerCredentials;
 
 
+import android.accounts.AccountAuthenticatorActivity;
 import android.net.Uri;
 import android.net.Uri;
 
 
 public class WebdavClient extends HttpClient {
 public class WebdavClient extends HttpClient {
@@ -51,6 +53,7 @@ public class WebdavClient extends HttpClient {
     private Credentials mCredentials;
     private Credentials mCredentials;
     private boolean mFollowRedirects;
     private boolean mFollowRedirects;
     private String mSsoSessionCookie;
     private String mSsoSessionCookie;
+    private String mAuthTokenType;
     final private static String TAG = "WebdavClient";
     final private static String TAG = "WebdavClient";
     public static final String USER_AGENT = "Android-ownCloud";
     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);
         getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
         mFollowRedirects = true;
         mFollowRedirects = true;
         mSsoSessionCookie = null;
         mSsoSessionCookie = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
     }
     }
 
 
     public void setBearerCredentials(String accessToken) {
     public void setBearerCredentials(String accessToken) {
@@ -78,6 +82,7 @@ public class WebdavClient extends HttpClient {
         mCredentials = new BearerCredentials(accessToken);
         mCredentials = new BearerCredentials(accessToken);
         getState().setCredentials(AuthScope.ANY, mCredentials);
         getState().setCredentials(AuthScope.ANY, mCredentials);
         mSsoSessionCookie = null;
         mSsoSessionCookie = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN;
     }
     }
 
 
     public void setBasicCredentials(String username, String password) {
     public void setBasicCredentials(String username, String password) {
@@ -89,6 +94,7 @@ public class WebdavClient extends HttpClient {
         mCredentials = new UsernamePasswordCredentials(username, password);
         mCredentials = new UsernamePasswordCredentials(username, password);
         getState().setCredentials(AuthScope.ANY, mCredentials);
         getState().setCredentials(AuthScope.ANY, mCredentials);
         mSsoSessionCookie = null;
         mSsoSessionCookie = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_PASSWORD;
     }
     }
     
     
     public void setSsoSessionCookie(String accessToken) {
     public void setSsoSessionCookie(String accessToken) {
@@ -96,6 +102,7 @@ public class WebdavClient extends HttpClient {
         getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
         getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
         mSsoSessionCookie = accessToken;
         mSsoSessionCookie = accessToken;
         mCredentials = null;
         mCredentials = null;
+        mAuthTokenType = AccountAuthenticator.AUTH_TOKEN_TYPE_SAML_WEB_SSO_SESSION_COOKIE;
     }
     }
     
     
     
     
@@ -215,4 +222,8 @@ public class WebdavClient extends HttpClient {
         mFollowRedirects = followRedirects;
         mFollowRedirects = followRedirects;
     }
     }
 
 
+    public String getAuthTokenType() {
+        return mAuthTokenType;
+    }
+
 }
 }