Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 70f0f445 authored by Tobias Kaminsky's avatar Tobias Kaminsky Committed by GitHub
Browse files

Merge pull request #123 from nextcloud/revertCheckForOlderVersion

Revert check for older version
parents fbd93920 9da5aa4d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import android.accounts.OperationCanceledException;
import android.content.Context;

import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;

import java.io.IOException;

@@ -35,7 +36,16 @@ public class DynamicSessionManager implements OwnCloudClientManager {
            throws AccountUtils.AccountNotFoundException,
            OperationCanceledException, AuthenticatorException, IOException {

        OwnCloudVersion ownCloudVersion = null;
        if (account.getSavedAccount() != null) {
            ownCloudVersion = AccountUtils.getServerVersionForAccount(account.getSavedAccount(), context);
        }

        if (ownCloudVersion != null && ownCloudVersion.isPreemptiveAuthenticationPreferred()) {
            return mSingleSessionManager.getClientFor(account, context, useNextcloudUserAgent);
        } else {
            return mSimpleFactoryManager.getClientFor(account, context, useNextcloudUserAgent);
        }
    }

    @Override
+13 −7
Original line number Diff line number Diff line
@@ -282,7 +282,9 @@ public class OwnCloudClient extends HttpClient {
                if (destination != null) {
                	int suffixIndex = locationStr.lastIndexOf(
                	    	(mCredentials instanceof OwnCloudBearerCredentials) ? 
                                    AccountUtils.ODAV_PATH : AccountUtils.WEBDAV_PATH_4_0);
                	    			AccountUtils.ODAV_PATH :
        	    					AccountUtils.WEBDAV_PATH_4_0
                			);
                	String redirectionBase = locationStr.substring(0, suffixIndex);
                	
                	String destinationStr = destination.getValue();
@@ -343,13 +345,17 @@ public class OwnCloudClient extends HttpClient {
    	}
    }

    public Uri getNewWebdavUri() {
    public Uri getNewWebdavUri(boolean filesUri) {
        if (mCredentials instanceof OwnCloudBearerCredentials) {
            return Uri.parse(mBaseUri + AccountUtils.ODAV_PATH);
        } else {
            if (filesUri) {
                return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0);
            } else {
                return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_9_0);
            }
        }
    }
    
    /**
     * Sets the root URI to the ownCloud server.   
+3 −2
Original line number Diff line number Diff line
@@ -114,7 +114,7 @@ public class OwnCloudClientFactory {
            OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);

            OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(
                    username, password);
                    username, password, (version != null && version.isPreemptiveAuthenticationPreferred()));

            client.setCredentials(credentials);
        }
@@ -188,8 +188,9 @@ public class OwnCloudClientFactory {
            Bundle result = future.getResult();
            String password = result.getString(AccountManager.KEY_AUTHTOKEN);

            OwnCloudVersion version = AccountUtils.getServerVersionForAccount(account, appContext);
            OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(
                    username, password);
                    username, password, (version != null && version.isPreemptiveAuthenticationPreferred()));

            client.setCredentials(credentials);
        }
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,10 @@ public class OwnCloudCredentialsFactory {
		return new OwnCloudBasicCredentials(username, password);
	}

    public static OwnCloudCredentials newBasicCredentials(String username, String password, boolean preemptiveMode) {
        return new OwnCloudBasicCredentials(username, password, preemptiveMode);
    }

    public static OwnCloudCredentials newBearerCredentials(String authToken) {
        return new OwnCloudBearerCredentials(authToken);
	}
+62 −30
Original line number Diff line number Diff line
@@ -47,21 +47,27 @@ public class AccountUtils {
	
	private static final String TAG = AccountUtils.class.getSimpleName();
	
    public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";
    public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";
    public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
    public static final String WEBDAV_PATH_9_0 = "/remote.php/dav";
    public static final String ODAV_PATH = "/remote.php/odav";
    private static final String SAML_SSO_PATH = "/remote.php/webdav";
    public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";
    public static final String CARDDAV_PATH_4_0 = "/remote/carddav.php";
    public static final String STATUS_PATH = "/status.php";

    /**
     * Returns the proper URL path to access the WebDAV interface of an ownCloud server,
     * according to its authorization method used.
     * according to its version and the authorization method used.
     * 
     * @param	version         	Version of ownCloud server.
     * @param 	supportsOAuth		If true, access with OAuth 2 authorization is considered. 
     * @param 	supportsSamlSso		If true, and supportsOAuth is false, access with SAML-based single-sign-on is considered.
     * @return default WebDAV path, if no OAuth/Samal
     * @return 						WebDAV path for given OC version, null if OC version unknown
     */
    public static String getWebdavPath(boolean supportsOAuth, boolean supportsSamlSso) {
    public static String getWebdavPath(OwnCloudVersion version, boolean supportsOAuth, boolean supportsSamlSso) {
        if (version != null) {
            if (supportsOAuth) {
                return ODAV_PATH;
            }
@@ -69,7 +75,15 @@ public class AccountUtils {
                return SAML_SSO_PATH;
            }

            if (version.compareTo(OwnCloudVersion.owncloud_v4) >= 0)
                return WEBDAV_PATH_4_0;
            if (version.compareTo(OwnCloudVersion.owncloud_v3) >= 0
                    || version.compareTo(OwnCloudVersion.owncloud_v2) >= 0)
                return WEBDAV_PATH_2_0;
            if (version.compareTo(OwnCloudVersion.owncloud_v1) >= 0)
                return WEBDAV_PATH_1_2;
        }
        return null;
    }
    
    /**
@@ -89,7 +103,8 @@ public class AccountUtils {
        String version  = ama.getUserData(account, Constants.KEY_OC_VERSION);
        boolean supportsOAuth = (ama.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2) != null);
        boolean supportsSamlSso = (ama.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null);
        String webdavpath = getWebdavPath(supportsOAuth, supportsSamlSso);
        OwnCloudVersion ver = new OwnCloudVersion(version);
        String webdavpath = getWebdavPath(ver, supportsOAuth, supportsSamlSso);

        if (baseurl == null || webdavpath == null) 
            throw new AccountNotFoundException(account, "Account not found", null);
@@ -192,27 +207,44 @@ public class AccountUtils {
        		AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;

        String username = AccountUtils.getUsernameForAccount(account);
		String ocVersion = am.getUserData(account, Constants.KEY_OC_VERSION);

		OwnCloudVersion version;
		if (ocVersion == null) {
			// set to oldest supported version
			version = OwnCloudVersion.nextcloud_10;
		} else {
			version = new OwnCloudVersion(ocVersion);
		}

        if (isOauth2) {    
            String accessToken = am.blockingGetAuthToken(account,
                    AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), false);
            String accessToken = am.blockingGetAuthToken(
            		account, 
            		AccountTypeUtils.getAuthTokenTypeAccessToken(account.type), 
            		false);
            
            credentials = OwnCloudCredentialsFactory.newBearerCredentials(accessToken);
        
        } else if (isSamlSso) {
            String accessToken = am.blockingGetAuthToken(account,
                    AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), false);
            String accessToken = am.blockingGetAuthToken(
            		account, 
            		AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(account.type), 
            		false);
            
            credentials = OwnCloudCredentialsFactory.newSamlSsoCredentials(username, accessToken);

        } else {
            String password = am.blockingGetAuthToken(account, AccountTypeUtils.getAuthTokenTypePass(account.type),
            String password = am.blockingGetAuthToken(
					account,
					AccountTypeUtils.getAuthTokenTypePass(account.type),
					false);

            credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);
			credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password,
					version.isPreemptiveAuthenticationPreferred());
		}
        
        return credentials;
        
	}

	
Loading