1
0
mirror of https://github.com/owncloud/android-library.git synced 2025-06-27 01:36:14 +00:00

First propfind using dav4droid and new architecture

This commit is contained in:
davigonz 2018-05-18 12:18:42 +02:00
parent 1249e205d6
commit 3125c8047c
14 changed files with 220 additions and 49 deletions

View File

@ -35,8 +35,10 @@ import java.util.List;
import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener;
import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudClientFactory;
import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory; import com.owncloud.android.lib.refactor.authentication.credentials.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;
import com.owncloud.android.lib.refactor.OwnCloudContext;
import com.owncloud.android.lib.refactor.operations.PropfindOperation;
import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.resources.files.RemoteFile;
import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -66,6 +68,8 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
private OwnCloudClient mClient; private OwnCloudClient mClient;
private OwnCloudContext mOCContext;
private FilesArrayAdapter mFilesAdapter; private FilesArrayAdapter mFilesAdapter;
private View mFrame; private View mFrame;
@ -79,13 +83,21 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
mHandler = new Handler(); mHandler = new Handler();
Uri serverUri = Uri.parse(getString(R.string.server_base_url)); Uri serverUri = Uri.parse(getString(R.string.server_base_url));
mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true); // mClient = OwnCloudClientFactory.createOwnCloudClient(serverUri, this, true);
mClient.setCredentials( // mClient.setCredentials(
OwnCloudCredentialsFactory.newBasicCredentials( // OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username), // getString(R.string.username),
getString(R.string.password) // getString(R.string.password)
) // )
); // );
mOCContext = new OwnCloudContext.Builder()
.setBaseUri(serverUri)
.setCredentials(OwnCloudCredentialsFactory.newBasicCredentials(
getString(R.string.username),
getString(R.string.password)
))
.build();
mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list); mFilesAdapter = new FilesArrayAdapter(this, R.layout.file_in_list);
((ListView)findViewById(R.id.list_view)).setAdapter(mFilesAdapter); ((ListView)findViewById(R.id.list_view)).setAdapter(mFilesAdapter);
@ -148,8 +160,12 @@ public class MainActivity extends Activity implements OnRemoteOperationListener,
} }
private void startRefresh() { private void startRefresh() {
ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
refreshOperation.execute(mClient, this, mHandler); PropfindOperation propfindOperation = new PropfindOperation(mOCContext, FileUtils.PATH_SEPARATOR);
propfindOperation.exec();
// ReadRemoteFolderOperation refreshOperation = new ReadRemoteFolderOperation(FileUtils.PATH_SEPARATOR);
// refreshOperation.execute(mClient, this, mHandler);
} }
private void startUpload() { private void startUpload() {

View File

@ -1,9 +1,6 @@
package com.owncloud.android.lib.refactor; package com.owncloud.android.lib.refactor;
import android.net.Uri;
import com.owncloud.android.lib.refactor.account.OCAccount; import com.owncloud.android.lib.refactor.account.OCAccount;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
public class OCContext { public class OCContext {

View File

@ -0,0 +1,53 @@
package com.owncloud.android.lib.refactor;
import android.net.Uri;
import com.owncloud.android.lib.refactor.authentication.credentials.OCCredentials;
public class OwnCloudContext {
private static final String TAG = OwnCloudContext.class.toString();
public static final String WEBDAV_PATH_4_0 = "/remote.php/dav";
public static final String STATUS_PATH = "/status.php";
public static final String FILES_WEB_PATH = "/index.php/apps/files";
private static final int MAX_REDIRECTIONS_COUNT = 3;
private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
private static final String PARAM_SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header";
private static final boolean PARAM_SINGLE_COOKIE_HEADER_VALUE = true;
private static final String PARAM_PROTOCOL_VERSION = "http.protocol.version";
private OCCredentials mCredentials = null;
private Uri mBaseUri;
public static final class Builder {
OwnCloudContext ocContext = new OwnCloudContext();
public Builder setCredentials(OCCredentials credentials) {
ocContext.mCredentials = credentials;
return this;
}
public Builder setBaseUri(Uri baseUri) {
ocContext.mBaseUri = baseUri;
return this;
}
public OwnCloudContext build() {
return ocContext;
}
}
public OCCredentials getCredentials() {
return mCredentials;
}
public Uri getBaseUri() {
return mBaseUri;
}
public Uri getWebdavUri() {
return Uri.parse(mBaseUri + WEBDAV_PATH_4_0);
}
}

View File

@ -1,7 +1,6 @@
package com.owncloud.android.lib.refactor; package com.owncloud.android.lib.refactor;
import android.net.Uri; import android.net.Uri;
import java.util.Map; import java.util.Map;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;

View File

@ -33,12 +33,11 @@ import android.accounts.OperationCanceledException;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import com.owncloud.android.lib.common.authentication.OwnCloudCredentialsFactory;
import com.owncloud.android.lib.refactor.Log_OC; import com.owncloud.android.lib.refactor.Log_OC;
import com.owncloud.android.lib.refactor.OCContext; import com.owncloud.android.lib.refactor.OCContext;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import com.owncloud.android.lib.refactor.authentication.credentials.OCBasicCredentials; import com.owncloud.android.lib.refactor.authentication.credentials.OCBasicCredentials;
import com.owncloud.android.lib.refactor.authentication.credentials.OCBearerCredentials; import com.owncloud.android.lib.refactor.authentication.credentials.OCBearerCredentials;
import com.owncloud.android.lib.refactor.authentication.credentials.OCCredentials;
import com.owncloud.android.lib.refactor.authentication.credentials.OCSamlSsoCredentials; import com.owncloud.android.lib.refactor.authentication.credentials.OCSamlSsoCredentials;
import com.owncloud.android.lib.refactor.exceptions.AccountNotFoundException; import com.owncloud.android.lib.refactor.exceptions.AccountNotFoundException;
import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.status.OwnCloudVersion;

View File

@ -24,7 +24,6 @@
package com.owncloud.android.lib.refactor.account; package com.owncloud.android.lib.refactor.account;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.accounts.AuthenticatorException; import android.accounts.AuthenticatorException;
@ -32,8 +31,8 @@ import android.accounts.OperationCanceledException;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import com.owncloud.android.lib.refactor.authentication.credentials.OCAnonymousCredentials; import com.owncloud.android.lib.refactor.authentication.credentials.OCAnonymousCredentials;
import com.owncloud.android.lib.refactor.authentication.credentials.OCCredentials;
import com.owncloud.android.lib.refactor.exceptions.AccountNotFoundException; import com.owncloud.android.lib.refactor.exceptions.AccountNotFoundException;
import java.io.IOException; import java.io.IOException;

View File

@ -1,8 +1,5 @@
package com.owncloud.android.lib.refactor.authentication.credentials; package com.owncloud.android.lib.refactor.authentication.credentials;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class OCAnonymousCredentials implements OCCredentials { public class OCAnonymousCredentials implements OCCredentials {
@ -12,6 +9,11 @@ public class OCAnonymousCredentials implements OCCredentials {
return new HashMap<>(0); return new HashMap<>(0);
} }
@Override
public String getCredentialCookie() {
return null;
}
@Override @Override
public String getUsername() { public String getUsername() {
return ""; return "";

View File

@ -23,8 +23,6 @@
*/ */
package com.owncloud.android.lib.refactor.authentication.credentials; package com.owncloud.android.lib.refactor.authentication.credentials;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -47,6 +45,11 @@ public class OCBasicCredentials implements OCCredentials {
return header; return header;
} }
@Override
public String getCredentialCookie() {
return null;
}
@Override @Override
public String getUsername() { public String getUsername() {
return mUsername; return mUsername;
@ -61,5 +64,4 @@ public class OCBasicCredentials implements OCCredentials {
public boolean authTokenCanBeRefreshed() { public boolean authTokenCanBeRefreshed() {
return false; return false;
} }
} }

View File

@ -23,17 +23,12 @@
*/ */
package com.owncloud.android.lib.refactor.authentication.credentials; package com.owncloud.android.lib.refactor.authentication.credentials;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class OCBearerCredentials implements OCCredentials { public class OCBearerCredentials implements OCCredentials {
private String mUsername; private String mUsername;
private String mAccessToken; private String mAccessToken;
public OCBearerCredentials(String username, String accessToken) { public OCBearerCredentials(String username, String accessToken) {
@ -48,6 +43,11 @@ public class OCBearerCredentials implements OCCredentials {
return header; return header;
} }
@Override
public String getCredentialCookie() {
return null;
}
@Override @Override
public String getUsername() { public String getUsername() {
// not relevant for authentication, but relevant for informational purposes // not relevant for authentication, but relevant for informational purposes

View File

@ -22,23 +22,20 @@
* *
*/ */
package com.owncloud.android.lib.refactor.authentication; package com.owncloud.android.lib.refactor.authentication.credentials;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public interface OCCredentials { public interface OCCredentials {
Map<String, String> getCredentialHeaders(); Map<String, String> getCredentialHeaders();
//TODO: Remove this once SAML is obsolet //TODO: Remove this once SAML is obsolet
default String getCredentialCookie() { String getCredentialCookie();
return null;
}
String getUsername(); String getUsername();
String getAuthToken(); String getAuthToken();
boolean authTokenCanBeRefreshed(); boolean authTokenCanBeRefreshed();
} }

View File

@ -25,10 +25,7 @@ package com.owncloud.android.lib.refactor.authentication.credentials;
import android.net.Uri; import android.net.Uri;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Cookie;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -0,0 +1,85 @@
/* ownCloud Android Library is available under MIT license
* Copyright (C) 2016 ownCloud GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package com.owncloud.android.lib.refactor.authentication.credentials;
import java.util.Map;
public class OwnCloudCredentialsFactory {
public static final String CREDENTIAL_CHARSET = "UTF-8";
private static OCAnonymousCredentials sAnonymousCredentials;
public static OCCredentials newBasicCredentials(String username, String password) {
return new OCBasicCredentials(username, password);
}
public static OCCredentials newBearerCredentials(String username, String authToken) {
return new OCBearerCredentials(username, authToken);
}
public static OCCredentials newSamlSsoCredentials(String username, String sessionCookie) {
return new OCSamlSsoCredentials(username, sessionCookie, null);
}
public static final OCCredentials getAnonymousCredentials() {
if (sAnonymousCredentials == null) {
sAnonymousCredentials = new OCAnonymousCredentials();
}
return sAnonymousCredentials;
}
public static final class OCAnonymousCredentials implements OCCredentials {
protected OCAnonymousCredentials() {
}
@Override
public String getAuthToken() {
return "";
}
@Override
public boolean authTokenCanBeRefreshed() {
return false;
}
@Override
public Map<String, String> getCredentialHeaders() {
return null;
}
@Override
public String getCredentialCookie() {
return null;
}
@Override
public String getUsername() {
// no user name
return null;
}
}
}

View File

@ -25,8 +25,6 @@ import com.owncloud.android.lib.refactor.OCContext;
import com.owncloud.android.lib.refactor.RemoteOperationResult; import com.owncloud.android.lib.refactor.RemoteOperationResult;
import com.owncloud.android.lib.refactor.Log_OC; import com.owncloud.android.lib.refactor.Log_OC;
import com.owncloud.android.lib.refactor.RemoteOperation; import com.owncloud.android.lib.refactor.RemoteOperation;
import com.owncloud.android.lib.refactor.authentication.credentials.OCBasicCredentials;
import com.owncloud.android.lib.refactor.authentication.OCCredentials;
import com.owncloud.android.lib.refactor.authentication.oauth.OAuth2Constants; import com.owncloud.android.lib.refactor.authentication.oauth.OAuth2Constants;
import com.owncloud.android.lib.refactor.authentication.oauth.OAuth2GrantType; import com.owncloud.android.lib.refactor.authentication.oauth.OAuth2GrantType;
import com.owncloud.android.lib.refactor.authentication.oauth.OAuth2ResponseParser; import com.owncloud.android.lib.refactor.authentication.oauth.OAuth2ResponseParser;

View File

@ -1,18 +1,45 @@
package com.owncloud.android.lib.refactor.operations; package com.owncloud.android.lib.refactor.operations;
import com.owncloud.android.lib.refactor.OCContext; import com.owncloud.android.lib.refactor.OCContext;
import com.owncloud.android.lib.common.network.WebdavUtils;
import com.owncloud.android.lib.refactor.RemoteOperation; import com.owncloud.android.lib.refactor.RemoteOperation;
import com.owncloud.android.lib.refactor.RemoteOperationResult; import com.owncloud.android.lib.refactor.RemoteOperationResult;
import java.io.IOException;
import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.exception.DavException;
import at.bitfire.dav4android.exception.HttpException;
import at.bitfire.dav4android.property.DisplayName;
import okhttp3.HttpUrl;
public class PropfindOperation extends RemoteOperation { public class PropfindOperation extends RemoteOperation {
public PropfindOperation(OCContext context) { private String mRemotePath;
public PropfindOperation(OCContext context, String remotePath) {
super(context); super(context);
mRemotePath = remotePath;
} }
@Override @Override
public RemoteOperationResult exec() { public RemoteOperationResult exec() {
DavResource davResource = new DavResource(
getClient(),
HttpUrl.parse(getOCContext().getWebdavUri() + WebdavUtils.encodePath(mRemotePath)),
null);
try {
davResource.propfind(1, DisplayName.NAME);
} catch (IOException e) {
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
} catch (DavException e) {
e.printStackTrace();
}
davResource.getProperties();
return null; return null;
} }