mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 08:26:10 +00:00
Merge pull request #34 from owncloud/update_error_messages_for_non_permitted_actions
Added error codes and controls for non permitted actions
This commit is contained in:
commit
6b155fb802
@ -33,3 +33,4 @@
|
|||||||
android:targetSdkVersion="19" />
|
android:targetSdkVersion="19" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
||||||
|
@ -43,14 +43,13 @@ import org.apache.commons.httpclient.params.HttpMethodParams;
|
|||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.params.CoreProtocolPNames;
|
import org.apache.http.params.CoreProtocolPNames;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
|
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials;
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||||
import com.owncloud.android.lib.common.network.WebdavUtils;
|
import com.owncloud.android.lib.common.network.WebdavUtils;
|
||||||
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class OwnCloudClient extends HttpClient {
|
public class OwnCloudClient extends HttpClient {
|
||||||
|
|
||||||
private static final String TAG = OwnCloudClient.class.getSimpleName();
|
private static final String TAG = OwnCloudClient.class.getSimpleName();
|
||||||
@ -88,7 +87,7 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
HttpVersion.HTTP_1_1);
|
HttpVersion.HTTP_1_1);
|
||||||
|
|
||||||
getParams().setCookiePolicy(
|
getParams().setCookiePolicy(
|
||||||
CookiePolicy.BROWSER_COMPATIBILITY); // to keep sessions
|
CookiePolicy.IGNORE_COOKIES);
|
||||||
getParams().setParameter(
|
getParams().setParameter(
|
||||||
PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers
|
PARAM_SINGLE_COOKIE_HEADER, // to avoid problems with some web servers
|
||||||
PARAM_SINGLE_COOKIE_HEADER_VALUE);
|
PARAM_SINGLE_COOKIE_HEADER_VALUE);
|
||||||
@ -189,8 +188,8 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
Log.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
Log.d(TAG + " #" + mInstanceNumber, "REQUEST " +
|
||||||
method.getName() + " " + method.getPath());
|
method.getName() + " " + method.getPath());
|
||||||
|
|
||||||
logCookiesAtRequest(method.getRequestHeaders(), "before");
|
// logCookiesAtRequest(method.getRequestHeaders(), "before");
|
||||||
logCookiesAtState("before");
|
// logCookiesAtState("before");
|
||||||
|
|
||||||
int status = super.executeMethod(method);
|
int status = super.executeMethod(method);
|
||||||
|
|
||||||
@ -198,9 +197,9 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
status = patchRedirection(status, method);
|
status = patchRedirection(status, method);
|
||||||
}
|
}
|
||||||
|
|
||||||
logCookiesAtRequest(method.getRequestHeaders(), "after");
|
// logCookiesAtRequest(method.getRequestHeaders(), "after");
|
||||||
logCookiesAtState("after");
|
// logCookiesAtState("after");
|
||||||
logSetCookiesAtResponse(method.getResponseHeaders());
|
// logSetCookiesAtResponse(method.getResponseHeaders());
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
@ -348,13 +347,13 @@ public class OwnCloudClient extends HttpClient {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCookiesString(){
|
public String getCookiesString() {
|
||||||
Cookie[] cookies = getState().getCookies();
|
Cookie[] cookies = getState().getCookies();
|
||||||
String cookiesString ="";
|
String cookiesString = "";
|
||||||
for (Cookie cookie: cookies) {
|
for (Cookie cookie : cookies) {
|
||||||
cookiesString = cookiesString + cookie.toString() + ";";
|
cookiesString = cookiesString + cookie.toString() + ";";
|
||||||
|
|
||||||
logCookie(cookie);
|
// logCookie(cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cookiesString;
|
return cookiesString;
|
||||||
|
@ -29,6 +29,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.cookie.CookiePolicy;
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AuthenticatorException;
|
import android.accounts.AuthenticatorException;
|
||||||
import android.accounts.OperationCanceledException;
|
import android.accounts.OperationCanceledException;
|
||||||
@ -102,6 +104,9 @@ public class SingleSessionManager implements OwnCloudClientManager {
|
|||||||
account.getBaseUri(),
|
account.getBaseUri(),
|
||||||
context.getApplicationContext(),
|
context.getApplicationContext(),
|
||||||
true); // TODO remove dependency on OwnCloudClientFactory
|
true); // TODO remove dependency on OwnCloudClientFactory
|
||||||
|
client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
|
||||||
|
// enable cookie tracking
|
||||||
|
|
||||||
|
|
||||||
// Restore Cookies ??
|
// Restore Cookies ??
|
||||||
AccountUtils.restoreCookies(accountName, client, context);
|
AccountUtils.restoreCookies(accountName, client, context);
|
||||||
|
@ -29,11 +29,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import org.apache.commons.httpclient.Cookie;
|
import org.apache.commons.httpclient.Cookie;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
|
||||||
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.AccountsException;
|
import android.accounts.AccountsException;
|
||||||
@ -43,6 +38,11 @@ import android.content.Context;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudCredentials;
|
||||||
|
import com.owncloud.android.lib.common.OwnCloudCredentialsFactory;
|
||||||
|
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
|
||||||
|
|
||||||
public class AccountUtils {
|
public class AccountUtils {
|
||||||
|
|
||||||
private static final String TAG = AccountUtils.class.getSimpleName();
|
private static final String TAG = AccountUtils.class.getSimpleName();
|
||||||
@ -220,7 +220,7 @@ public class AccountUtils {
|
|||||||
String cookiesString = client.getCookiesString();
|
String cookiesString = client.getCookiesString();
|
||||||
if (cookiesString != "") {
|
if (cookiesString != "") {
|
||||||
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
ac.setUserData(savedAccount, Constants.KEY_COOKIES, cookiesString);
|
||||||
Log.d(TAG, "Saving Cookies: "+ cookiesString );
|
// Log.d(TAG, "Saving Cookies: "+ cookiesString );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,32 +35,30 @@ import android.net.Uri;
|
|||||||
public class WebdavUtils {
|
public class WebdavUtils {
|
||||||
public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat(
|
public static final SimpleDateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat(
|
||||||
"dd.MM.yyyy hh:mm");
|
"dd.MM.yyyy hh:mm");
|
||||||
private static final String DATETIME_FORMATS[] = {
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ss'Z'",
|
|
||||||
"EEE, dd MMM yyyy HH:mm:ss zzz",
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ss.sss'Z'",
|
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZ",
|
|
||||||
"EEE MMM dd HH:mm:ss zzz yyyy",
|
|
||||||
"EEEEEE, dd-MMM-yy HH:mm:ss zzz",
|
|
||||||
"EEE MMMM d HH:mm:ss yyyy",
|
|
||||||
"yyyy-MM-dd hh:mm:ss" };
|
|
||||||
|
|
||||||
public static String prepareXmlForPropFind() {
|
private static final SimpleDateFormat DATETIME_FORMATS[] = {
|
||||||
String ret = "<?xml version=\"1.0\" ?><D:propfind xmlns:D=\"DAV:\"><D:allprop/></D:propfind>";
|
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US),
|
||||||
return ret;
|
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
|
||||||
}
|
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sss'Z'", Locale.US),
|
||||||
|
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.US),
|
||||||
public static String prepareXmlForPatch() {
|
new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US),
|
||||||
return "<?xml version=\"1.0\" ?><D:propertyupdate xmlns:D=\"DAV:\"></D:propertyupdate>";
|
new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
|
||||||
}
|
new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US),
|
||||||
|
new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.US)
|
||||||
|
};
|
||||||
|
|
||||||
public static Date parseResponseDate(String date) {
|
public static Date parseResponseDate(String date) {
|
||||||
Date returnDate = null;
|
Date returnDate = null;
|
||||||
|
SimpleDateFormat format = null;
|
||||||
for (int i = 0; i < DATETIME_FORMATS.length; ++i) {
|
for (int i = 0; i < DATETIME_FORMATS.length; ++i) {
|
||||||
try {
|
try {
|
||||||
returnDate = new SimpleDateFormat (DATETIME_FORMATS[i], Locale.US).parse(date);
|
format = DATETIME_FORMATS[i];
|
||||||
|
synchronized(format) {
|
||||||
|
returnDate = format.parse(date);
|
||||||
|
}
|
||||||
return returnDate;
|
return returnDate;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
|
// this is not the format
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -41,13 +41,13 @@ import org.apache.commons.httpclient.HttpStatus;
|
|||||||
import org.apache.jackrabbit.webdav.DavException;
|
import org.apache.jackrabbit.webdav.DavException;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
|
||||||
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
|
||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountsException;
|
import android.accounts.AccountsException;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;
|
||||||
|
import com.owncloud.android.lib.common.network.CertificateCombinedException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result of a remote operation required to an ownCloud server.
|
* The result of a remote operation required to an ownCloud server.
|
||||||
@ -98,7 +98,9 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
ACCOUNT_NOT_THE_SAME,
|
ACCOUNT_NOT_THE_SAME,
|
||||||
INVALID_CHARACTER_IN_NAME,
|
INVALID_CHARACTER_IN_NAME,
|
||||||
SHARE_NOT_FOUND,
|
SHARE_NOT_FOUND,
|
||||||
LOCAL_STORAGE_NOT_REMOVED
|
LOCAL_STORAGE_NOT_REMOVED,
|
||||||
|
FORBIDDEN,
|
||||||
|
SHARE_FORBIDDEN
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mSuccess = false;
|
private boolean mSuccess = false;
|
||||||
@ -140,6 +142,9 @@ public class RemoteOperationResult implements Serializable {
|
|||||||
case HttpStatus.SC_INSUFFICIENT_STORAGE:
|
case HttpStatus.SC_INSUFFICIENT_STORAGE:
|
||||||
mCode = ResultCode.QUOTA_EXCEEDED;
|
mCode = ResultCode.QUOTA_EXCEEDED;
|
||||||
break;
|
break;
|
||||||
|
case HttpStatus.SC_FORBIDDEN:
|
||||||
|
mCode = ResultCode.FORBIDDEN;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
mCode = ResultCode.UNHANDLED_HTTP_CODE;
|
||||||
Log.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
|
Log.d(TAG, "RemoteOperationResult has processed UNHANDLED_HTTP_CODE: " + httpCode);
|
||||||
|
@ -142,6 +142,9 @@ public class CreateRemoteShareOperation extends RemoteOperation {
|
|||||||
} else if (xmlParser.isFileNotFound()){
|
} else if (xmlParser.isFileNotFound()){
|
||||||
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
|
result = new RemoteOperationResult(ResultCode.SHARE_NOT_FOUND);
|
||||||
|
|
||||||
|
} else if (xmlParser.isFailure()) {
|
||||||
|
result = new RemoteOperationResult(ResultCode.SHARE_FORBIDDEN);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(false, status, post.getResponseHeaders());
|
result = new RemoteOperationResult(false, status, post.getResponseHeaders());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user