mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-11-03 20:08:00 +00:00 
			
		
		
		
	Merge pull request #174 from owncloud/oauth2_support_bugfixing
Oauth2 support - bugfixing
This commit is contained in:
		
						commit
						c560f4fb4b
					
				@ -58,6 +58,10 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class OwnCloudClient extends HttpClient {
 | 
					public class OwnCloudClient extends HttpClient {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
 | 
				
			||||||
 | 
					    public static final String STATUS_PATH = "/status.php";
 | 
				
			||||||
 | 
					    public static final String FILES_WEB_PATH = "/index.php/apps/files";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final String TAG = OwnCloudClient.class.getSimpleName();
 | 
					    private static final String TAG = OwnCloudClient.class.getSimpleName();
 | 
				
			||||||
    private static final int MAX_REDIRECTIONS_COUNT = 3;
 | 
					    private static final int MAX_REDIRECTIONS_COUNT = 3;
 | 
				
			||||||
    private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
 | 
					    private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
 | 
				
			||||||
@ -322,9 +326,7 @@ public class OwnCloudClient extends HttpClient {
 | 
				
			|||||||
                    destination = method.getRequestHeader("destination");
 | 
					                    destination = method.getRequestHeader("destination");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                if (destination != null) {
 | 
					                if (destination != null) {
 | 
				
			||||||
                    int suffixIndex = locationStr.lastIndexOf(
 | 
					                    int suffixIndex = locationStr.lastIndexOf(WEBDAV_PATH_4_0);
 | 
				
			||||||
                            AccountUtils.WEBDAV_PATH_4_0
 | 
					 | 
				
			||||||
                    );
 | 
					 | 
				
			||||||
                    String redirectionBase = locationStr.substring(0, suffixIndex);
 | 
					                    String redirectionBase = locationStr.substring(0, suffixIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    String destinationStr = destination.getValue();
 | 
					                    String destinationStr = destination.getValue();
 | 
				
			||||||
@ -378,7 +380,7 @@ public class OwnCloudClient extends HttpClient {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Uri getWebdavUri() {
 | 
					    public Uri getWebdavUri() {
 | 
				
			||||||
        return Uri.parse(mBaseUri + AccountUtils.WEBDAV_PATH_4_0);
 | 
					        return Uri.parse(mBaseUri + WEBDAV_PATH_4_0);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -51,9 +51,6 @@ public class AccountUtils {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private static final String TAG = AccountUtils.class.getSimpleName();
 | 
					    private static final String TAG = AccountUtils.class.getSimpleName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav";
 | 
					 | 
				
			||||||
    public static final String STATUS_PATH = "/status.php";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructs full url to host and webdav resource basing on host version
 | 
					     * Constructs full url to host and webdav resource basing on host version
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -65,7 +62,7 @@ public class AccountUtils {
 | 
				
			|||||||
    public static String getWebDavUrlForAccount(Context context, Account account)
 | 
					    public static String getWebDavUrlForAccount(Context context, Account account)
 | 
				
			||||||
        throws AccountNotFoundException {
 | 
					        throws AccountNotFoundException {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return getBaseUrlForAccount(context, account) + WEBDAV_PATH_4_0;
 | 
					        return getBaseUrlForAccount(context, account) + OwnCloudClient.WEBDAV_PATH_4_0;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -138,13 +135,13 @@ public class AccountUtils {
 | 
				
			|||||||
        OwnCloudCredentials credentials = null;
 | 
					        OwnCloudCredentials credentials = null;
 | 
				
			||||||
        AccountManager am = AccountManager.get(context);
 | 
					        AccountManager am = AccountManager.get(context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        boolean isOauth2 = am.getUserData(
 | 
					        String supportsOAuth2 = am.getUserData(account, AccountUtils.Constants.KEY_SUPPORTS_OAUTH2);
 | 
				
			||||||
            account,
 | 
					        boolean isOauth2 = supportsOAuth2 != null && supportsOAuth2.equals("TRUE");
 | 
				
			||||||
            AccountUtils.Constants.KEY_SUPPORTS_OAUTH2) != null;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        boolean isSamlSso = am.getUserData(
 | 
					        String supportsSamlSSo = am.getUserData(account,
 | 
				
			||||||
            account,
 | 
					                AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO);
 | 
				
			||||||
            AccountUtils.Constants.KEY_SUPPORTS_SAML_WEB_SSO) != null;
 | 
					
 | 
				
			||||||
 | 
					        boolean isSamlSso = supportsSamlSSo != null && supportsSamlSSo.equals("TRUE");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        String username = AccountUtils.getUsernameForAccount(account);
 | 
					        String username = AccountUtils.getUsernameForAccount(account);
 | 
				
			||||||
        OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));
 | 
					        OwnCloudVersion version = new OwnCloudVersion(am.getUserData(account, Constants.KEY_OC_VERSION));
 | 
				
			||||||
 | 
				
			|||||||
@ -45,6 +45,7 @@ public class OAuth2QueryParser {
 | 
				
			|||||||
    public Map<String, String> parse(String query) {
 | 
					    public Map<String, String> parse(String query) {
 | 
				
			||||||
        mOAuth2ParsedAuthorizationResponse.clear();
 | 
					        mOAuth2ParsedAuthorizationResponse.clear();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (query != null) {
 | 
				
			||||||
            String[] pairs = query.split("&");
 | 
					            String[] pairs = query.split("&");
 | 
				
			||||||
            int i = 0;
 | 
					            int i = 0;
 | 
				
			||||||
            String key = "";
 | 
					            String key = "";
 | 
				
			||||||
@ -66,6 +67,7 @@ public class OAuth2QueryParser {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                i++;
 | 
					                i++;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return mOAuth2ParsedAuthorizationResponse;
 | 
					        return mOAuth2ParsedAuthorizationResponse;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -78,7 +78,7 @@ public class GetRemoteStatusOperation extends RemoteOperation {
 | 
				
			|||||||
        GetMethod get = null;
 | 
					        GetMethod get = null;
 | 
				
			||||||
        String baseUrlSt = client.getBaseUri().toString();
 | 
					        String baseUrlSt = client.getBaseUri().toString();
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            get = new GetMethod(baseUrlSt + AccountUtils.STATUS_PATH);
 | 
					            get = new GetMethod(baseUrlSt + OwnCloudClient.STATUS_PATH);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            HttpParams params = get.getParams().getDefaultParams();
 | 
					            HttpParams params = get.getParams().getDefaultParams();
 | 
				
			||||||
            params.setParameter(HttpMethodParams.USER_AGENT,
 | 
					            params.setParameter(HttpMethodParams.USER_AGENT,
 | 
				
			||||||
 | 
				
			|||||||
@ -297,7 +297,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
 | 
				
			|||||||
		client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("user", "fakeToken"));
 | 
							client.setCredentials(OwnCloudCredentialsFactory.newBearerCredentials("user", "fakeToken"));
 | 
				
			||||||
		Uri webdavUri = client.getWebdavUri();
 | 
							Uri webdavUri = client.getWebdavUri();
 | 
				
			||||||
		assertTrue("WebDAV URI does not point to the right entry point",
 | 
							assertTrue("WebDAV URI does not point to the right entry point",
 | 
				
			||||||
				webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0));
 | 
									webdavUri.getPath().endsWith(OwnCloudClient.WEBDAV_PATH_4_0));
 | 
				
			||||||
		assertTrue("WebDAV URI is not a subpath of base URI", 
 | 
							assertTrue("WebDAV URI is not a subpath of base URI", 
 | 
				
			||||||
				webdavUri.getAuthority().equals(mServerUri.getAuthority()) &&
 | 
									webdavUri.getAuthority().equals(mServerUri.getAuthority()) &&
 | 
				
			||||||
				webdavUri.getPath().startsWith(mServerUri.getPath()));
 | 
									webdavUri.getPath().startsWith(mServerUri.getPath()));
 | 
				
			||||||
@ -306,7 +306,7 @@ public class OwnCloudClientTest extends AndroidTestCase {
 | 
				
			|||||||
				mUsername, mPassword));
 | 
									mUsername, mPassword));
 | 
				
			||||||
		webdavUri = client.getWebdavUri();
 | 
							webdavUri = client.getWebdavUri();
 | 
				
			||||||
		assertTrue("WebDAV URI does not point to the right entry point",
 | 
							assertTrue("WebDAV URI does not point to the right entry point",
 | 
				
			||||||
				webdavUri.getPath().endsWith(AccountUtils.WEBDAV_PATH_4_0));
 | 
									webdavUri.getPath().endsWith(OwnCloudClient.WEBDAV_PATH_4_0));
 | 
				
			||||||
		PropFindMethod propfind = null;
 | 
							PropFindMethod propfind = null;
 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			propfind = new PropFindMethod(webdavUri + "/",
 | 
								propfind = new PropFindMethod(webdavUri + "/",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user