X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/52bd01bcedf1b8f13c49b67ee40a848bae1a9d40..b6213a0d5fbc40568c32b36fa12ce24c1780c58b:/src/eu/alefzero/webdav/WebdavClient.java?ds=inline diff --git a/src/eu/alefzero/webdav/WebdavClient.java b/src/eu/alefzero/webdav/WebdavClient.java index fdabebee..570ebb85 100644 --- a/src/eu/alefzero/webdav/WebdavClient.java +++ b/src/eu/alefzero/webdav/WebdavClient.java @@ -18,34 +18,26 @@ package eu.alefzero.webdav; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import org.apache.commons.httpclient.Credentials; -import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpConnectionManager; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpMethodBase; -import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.HttpVersion; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthPolicy; import org.apache.commons.httpclient.auth.AuthScope; -import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.cookie.CookiePolicy; import org.apache.commons.httpclient.methods.HeadMethod; -import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.http.HttpStatus; import org.apache.http.params.CoreProtocolPNames; -import org.apache.jackrabbit.webdav.client.methods.DavMethod; -import org.apache.jackrabbit.webdav.client.methods.DeleteMethod; import com.owncloud.android.Log_OC; @@ -57,10 +49,11 @@ import android.net.Uri; public class WebdavClient extends HttpClient { private Uri mUri; private Credentials mCredentials; + private boolean mFollowRedirects; + private String mSsoSessionCookie; final private static String TAG = "WebdavClient"; - private static final String USER_AGENT = "Android-ownCloud"; + public static final String USER_AGENT = "Android-ownCloud"; - private OnDatatransferProgressListener mDataTransferListener; static private byte[] sExhaustBuffer = new byte[1024]; /** @@ -71,6 +64,8 @@ public class WebdavClient extends HttpClient { Log_OC.d(TAG, "Creating WebdavClient"); getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT); getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); + mFollowRedirects = true; + mSsoSessionCookie = null; } public void setBearerCredentials(String accessToken) { @@ -82,6 +77,7 @@ public class WebdavClient extends HttpClient { mCredentials = new BearerCredentials(accessToken); getState().setCredentials(AuthScope.ANY, mCredentials); + mSsoSessionCookie = null; } public void setBasicCredentials(String username, String password) { @@ -92,8 +88,17 @@ public class WebdavClient extends HttpClient { getParams().setAuthenticationPreemptive(true); mCredentials = new UsernamePasswordCredentials(username, password); getState().setCredentials(AuthScope.ANY, mCredentials); + mSsoSessionCookie = null; } + public void setSsoSessionCookie(String accessToken) { + getParams().setAuthenticationPreemptive(false); + getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); + mSsoSessionCookie = accessToken; + mCredentials = null; + } + + /** * Check if a file exists in the OC server * @@ -145,6 +150,21 @@ public class WebdavClient extends HttpClient { getHttpConnectionManager().getParams().setConnectionTimeout(oldConnectionTimeout); } } + + + @Override + public int executeMethod(HttpMethod method) throws IOException, HttpException { + try { + method.setFollowRedirects(mFollowRedirects); + } catch (Exception e) { + + } + if (mSsoSessionCookie != null && mSsoSessionCookie.length() > 0) { + method.setRequestHeader("Cookie", mSsoSessionCookie); + } + return super.executeMethod(method); + } + /** * Exhausts a not interesting HTTP response. Encouraged by HttpClient documentation. @@ -185,6 +205,10 @@ public class WebdavClient extends HttpClient { public final Credentials getCredentials() { return mCredentials; - } - + } + + public void setFollowRedirects(boolean followRedirects) { + mFollowRedirects = followRedirects; + } + }