1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-16 02:43:00 +00:00

Include credentials [WIP]

This commit is contained in:
davigonz
2018-06-04 09:21:10 +02:00
parent 11938a1fcc
commit d67a41d5cc
7 changed files with 31 additions and 16 deletions
@@ -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;
}
}
/**