Work around constaint in valid key for DiskLruCache (capital letters are not allowed)
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / DetectAuthenticationMethodOperation.java
index a30829b..b90c25e 100644 (file)
@@ -69,6 +69,7 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation {
      * Constructor
      * 
      * @param context       Android context of the caller.
+     * @param webdavUrl
      */
     public DetectAuthenticationMethodOperation(Context context) {
         mContext = context;
@@ -90,15 +91,18 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation {
         AuthenticationMethod authMethod = AuthenticationMethod.UNKNOWN;
         
         RemoteOperation operation = new ExistenceCheckRemoteOperation("", mContext, false);
-        client.setBasicCredentials("", "");
+        client.clearCredentials();
         client.setFollowRedirects(false);
         
         // try to access the root folder, following redirections but not SAML SSO redirections
-        do {
-            result = operation.execute(client);
+        result = operation.execute(client);
+        String redirectedLocation = result.getRedirectedLocation(); 
+        while (redirectedLocation != null && redirectedLocation.length() > 0 && 
+                !result.isIdPRedirection()) {
             client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
-            
-        } while (result.isTemporalRedirection() && !result.isIdPRedirection());
+            result = operation.execute(client);
+            redirectedLocation = result.getRedirectedLocation();
+        } 
 
         // analyze response  
         if (result.getCode() == ResultCode.UNAUTHORIZED) {
@@ -120,6 +124,9 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation {
         // else - fall back to UNKNOWN
         Log.d(TAG, "Authentication method found: " + authenticationMethodToString(authMethod));
         
+        if (!authMethod.equals(AuthenticationMethod.UNKNOWN)) {
+            result = new RemoteOperationResult(true, result.getHttpCode(), null);
+        }
         ArrayList<Object> data = new ArrayList<Object>();
         data.add(authMethod);
         result.setData(data);