mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-31 02:17:41 +00:00 
			
		
		
		
	Include credentials [WIP]
This commit is contained in:
		
							parent
							
								
									11938a1fcc
								
							
						
					
					
						commit
						d67a41d5cc
					
				| @ -33,6 +33,7 @@ import android.net.Uri; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentials; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; | ||||
| import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials; | ||||
| import com.owncloud.android.lib.common.methods.HttpBaseMethod; | ||||
| import com.owncloud.android.lib.common.network.RedirectionPath; | ||||
| import com.owncloud.android.lib.common.utils.Log_OC; | ||||
| import com.owncloud.android.lib.resources.status.OwnCloudVersion; | ||||
| @ -49,7 +50,6 @@ import org.apache.commons.httpclient.URI; | ||||
| import org.apache.commons.httpclient.URIException; | ||||
| import org.apache.commons.httpclient.params.HttpMethodParams; | ||||
| import org.apache.commons.httpclient.params.HttpParams; | ||||
| import com.owncloud.android.lib.common.methods.HttpBaseMethod; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| @ -61,6 +61,7 @@ import okhttp3.Protocol; | ||||
| public class OwnCloudClient extends HttpClient { | ||||
| 
 | ||||
|     public static final String WEBDAV_PATH_4_0 = "/remote.php/webdav"; | ||||
|     public static final String NEW_WEBDAV_PATH_4_0 = "/remote.php/dav/files/"; | ||||
|     public static final String STATUS_PATH = "/status.php"; | ||||
|     public static final String FILES_WEB_PATH = "/index.php/apps/files"; | ||||
| 
 | ||||
| @ -299,7 +300,19 @@ public class OwnCloudClient extends HttpClient { | ||||
|     } | ||||
| 
 | ||||
|     public int executeHttpMethod (HttpBaseMethod method) throws Exception { | ||||
|         int status = method.execute(); | ||||
| 
 | ||||
|         boolean repeatWithFreshCredentials = false; | ||||
|         int repeatCounter = 0; | ||||
|         int status; | ||||
| 
 | ||||
|         do { | ||||
|             status = method.execute(); | ||||
|             repeatWithFreshCredentials = checkUnauthorizedAccess(status, repeatCounter); | ||||
|             if (repeatWithFreshCredentials) { | ||||
|                 repeatCounter++; | ||||
|             } | ||||
|         } while (repeatWithFreshCredentials); | ||||
| 
 | ||||
|         return status; | ||||
|     } | ||||
| 
 | ||||
| @ -432,6 +445,10 @@ public class OwnCloudClient extends HttpClient { | ||||
|         return Uri.parse(mBaseUri + WEBDAV_PATH_4_0); | ||||
|     } | ||||
| 
 | ||||
|     public Uri getNewWebDavUri() { | ||||
|         return Uri.parse(mBaseUri + NEW_WEBDAV_PATH_4_0 + mCredentials.getUsername()); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Sets the root URI to the ownCloud server. | ||||
|      * | ||||
|  | ||||
| @ -58,7 +58,7 @@ public class OwnCloudBasicCredentials implements OwnCloudCredentials { | ||||
|     public void applyTo(OwnCloudClient client) { | ||||
|         AuthPolicy.registerAuthScheme(AuthState.PREEMPTIVE_AUTH_SCHEME, BasicScheme.class); | ||||
| 
 | ||||
|         List<String> authPrefs = new ArrayList<String>(1); | ||||
|         List<String> authPrefs = new ArrayList<>(1); | ||||
|         authPrefs.add(AuthPolicy.BASIC); | ||||
| 
 | ||||
|         client.getOkHttpClient().newBuilder() | ||||
|  | ||||
| @ -1,7 +1,5 @@ | ||||
| package com.owncloud.android.lib.common.methods; | ||||
| 
 | ||||
| import java.io.IOException; | ||||
| 
 | ||||
| import at.bitfire.dav4android.DavResource; | ||||
| 
 | ||||
| public abstract class DavMethod implements HttpBaseMethod { | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| package com.owncloud.android.lib.common.methods; | ||||
| 
 | ||||
| public interface HttpBaseMethod { | ||||
| 
 | ||||
|     int execute() throws Exception; | ||||
| } | ||||
| @ -6,6 +6,7 @@ import at.bitfire.dav4android.DavResource; | ||||
| import at.bitfire.dav4android.PropertyUtils; | ||||
| import at.bitfire.dav4android.exception.DavException; | ||||
| import at.bitfire.dav4android.exception.HttpException; | ||||
| import at.bitfire.dav4android.exception.UnauthorizedException; | ||||
| 
 | ||||
| public class PropfindMethod extends DavMethod { | ||||
| 
 | ||||
| @ -16,8 +17,12 @@ public class PropfindMethod extends DavMethod { | ||||
|         mDepth = depth; | ||||
|     }; | ||||
| 
 | ||||
|     public int execute() throws DavException, IOException, HttpException { | ||||
|         mDavResource.propfind(mDepth, PropertyUtils.INSTANCE.getAllPropSet()); | ||||
|     public int execute() throws IOException, HttpException, DavException { | ||||
|         try { | ||||
|             mDavResource.propfind(mDepth, PropertyUtils.INSTANCE.getAllPropSet()); | ||||
|         } catch (UnauthorizedException davException) { | ||||
|             return 401; | ||||
|         } | ||||
|         return mDavResource.getResponse().code(); | ||||
|     } | ||||
| } | ||||
| } | ||||
| @ -206,7 +206,6 @@ public class RemoteOperationResult implements Serializable { | ||||
|         } else { | ||||
|             mCode = ResultCode.UNKNOWN_ERROR; | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -76,14 +76,13 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
| 
 | ||||
|         try { | ||||
| 
 | ||||
|             final HttpUrl location = HttpUrl.parse(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
|             final HttpUrl location = HttpUrl.parse(client.getNewWebDavUri() + WebdavUtils.encodePath(mRemotePath)); | ||||
|             DavOCResource davOCResource = new DavOCResource(client.getOkHttpClient(), location); | ||||
|             PropfindMethod propfindMethod = new PropfindMethod(davOCResource, 1); | ||||
| 
 | ||||
|             int status = client.executeHttpMethod(propfindMethod); | ||||
| 
 | ||||
|             // TODO Refactor from here down | ||||
| 
 | ||||
|             // remote request | ||||
| //            query = new PropFindMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath), | ||||
| //                WebdavUtils.getAllPropSet(),    // PropFind Properties | ||||
| @ -113,8 +112,6 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
| 
 | ||||
|         } catch (Exception e) { | ||||
|             result = new RemoteOperationResult(e); | ||||
| 
 | ||||
| 
 | ||||
|         } finally { | ||||
|             if (query != null) | ||||
|                 query.releaseConnection();  // let the connection available for other methods | ||||
| @ -150,14 +147,14 @@ public class ReadRemoteFolderOperation extends RemoteOperation { | ||||
| 
 | ||||
|         // parse data from remote folder  | ||||
|         WebdavEntry we = new WebdavEntry(remoteData.getResponses()[0], | ||||
|             client.getWebdavUri().getPath()); | ||||
|             client.getNewWebDavUri().getPath()); | ||||
|         mFolderAndFiles.add(fillOCFile(we)); | ||||
| 
 | ||||
|         // loop to update every child | ||||
|         RemoteFile remoteFile = null; | ||||
|         for (int i = 1; i < remoteData.getResponses().length; ++i) { | ||||
|             /// new OCFile instance with the data from the server | ||||
|             we = new WebdavEntry(remoteData.getResponses()[i], client.getWebdavUri().getPath()); | ||||
|             we = new WebdavEntry(remoteData.getResponses()[i], client.getNewWebDavUri().getPath()); | ||||
|             remoteFile = fillOCFile(we); | ||||
|             mFolderAndFiles.add(remoteFile); | ||||
|         } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user