Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit b2f6d7f

Browse files
committed
make initial check with apm work though connection validator
1 parent 7ccb86c commit b2f6d7f

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/ConnectionValidator.kt

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.lang.Exception
1414

1515
class ConnectionValidator (
1616
val clearCookiesOnValidation: Boolean
17-
){
17+
){
1818

1919
fun validate(baseClient: OwnCloudClient): Boolean {
2020
try {
@@ -28,6 +28,7 @@ class ConnectionValidator (
2828

2929
client.credentials = baseClient.credentials
3030
while (validationRetryCount < 5) {
31+
Timber.d("+++++++++++++++++++++++++++++++++++++ validationRetryCout %d", validationRetryCount)
3132
var successCounter = 0
3233
var failCounter = 0
3334

@@ -38,21 +39,24 @@ class ConnectionValidator (
3839
failCounter++
3940
}
4041

41-
client.setFollowRedirects(false)
42-
val contentReply = canAccessRootFolder(client)
43-
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
44-
if (contentReply.data == true) { //if data is true it means that the content reply was ok
45-
successCounter++
42+
// Skip the part where we try to check if we can access the parts where we have to be logged in... if we are not logged in
43+
if(baseClient.credentials !is OwnCloudCredentialsFactory.OwnCloudAnonymousCredentials) {
44+
client.setFollowRedirects(false)
45+
val contentReply = canAccessRootFolder(client)
46+
if (contentReply.httpCode == HttpConstants.HTTP_OK) {
47+
if (contentReply.data == true) { //if data is true it means that the content reply was ok
48+
successCounter++
49+
} else {
50+
failCounter++
51+
}
4652
} else {
4753
failCounter++
48-
}
49-
} else {
50-
failCounter++
51-
if (contentReply.hashCode() == HttpConstants.HTTP_UNAUTHORIZED) {
52-
triggerAuthRefresh()
54+
if (contentReply.hashCode() == HttpConstants.HTTP_UNAUTHORIZED) {
55+
triggerAuthRefresh()
56+
}
5357
}
5458
}
55-
if(successCounter >= failCounter) {
59+
if (successCounter >= failCounter) {
5660
//update credentials in client
5761
return true
5862
}
@@ -67,8 +71,10 @@ class ConnectionValidator (
6771

6872
private fun isOnwCloudStatusOk(client: OwnCloudClient): Boolean {
6973
val reply = getOwnCloudStatus(client)
70-
return reply.httpCode == HttpConstants.HTTP_OK &&
71-
!reply.isException &&
74+
// dont check status code. It currently relais on the broken redirect code of the owncloud client
75+
// TODO: Use okhttp redirect and add this check again
76+
// return reply.httpCode == HttpConstants.HTTP_OK &&
77+
return !reply.isException &&
7278
reply.data != null
7379
}
7480

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ private int saveExecuteHttpMethod(HttpBaseMethod method) throws Exception {
131131
}
132132

133133
status = method.execute();
134-
Timber.d("-------------------------------------");
135134
stacklog(status, method);
136135

137136
if (mConnectionValidator != null &&
@@ -163,7 +162,7 @@ private void stacklog(int status, HttpBaseMethod method) {
163162
"\nobject: " + this.toString() +
164163
"\nMethod: " + method.toString() +
165164
"\nUrl: " + method.getHttpUrl() +
166-
"\nCookeis: " + getCookiesString() +
165+
"\nCookeis: " + getCookiesForBaseUri().toString() +
167166
"\ntrace: " + ExceptionUtils.getStackTrace(e) +
168167
"---------------------------");
169168
}
@@ -329,19 +328,6 @@ public void setCredentials(OwnCloudCredentials credentials) {
329328
}
330329
}
331330

332-
public String getCookiesString() {
333-
StringBuilder cookiesString = new StringBuilder();
334-
List<Cookie> cookieList = getCookiesForBaseUri();
335-
336-
if (cookieList != null) {
337-
for (Cookie cookie : cookieList) {
338-
cookiesString.append(cookie.toString()).append(";");
339-
}
340-
}
341-
342-
return cookiesString.toString();
343-
}
344-
345331
public void setCookiesForBaseUri(List<Cookie> cookies) {
346332
getOkHttpClient().cookieJar().saveFromResponse(
347333
HttpUrl.parse(mBaseUri.toString()),

owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
public class HttpClient {
5858
private static OkHttpClient sOkHttpClient;
5959
private static Context sContext;
60+
private static HashMap<String, List<Cookie>> sCookieStore = new HashMap<>();
6061
private static LogInterceptor sLogInterceptor;
6162
private static Interceptor sDebugInterceptor;
6263

@@ -67,10 +68,11 @@ public static OkHttpClient getOkHttpClient() {
6768
NetworkUtils.getKnownServersStore(sContext));
6869
final SSLSocketFactory sslSocketFactory = getNewSslSocketFactory(trustManager);
6970
// Automatic cookie handling, NOT PERSISTENT
71+
final CookieJar cookieJar = new CookieJarImpl(sCookieStore);
7072

7173
// TODO: Not verifying the hostname against certificate. ask owncloud security human if this is ok.
7274
//.hostnameVerifier(new BrowserCompatHostnameVerifier());
73-
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager);
75+
sOkHttpClient = buildNewOkHttpClient(sslSocketFactory, trustManager, cookieJar);
7476

7577
} catch (Exception e) {
7678
Timber.e(e, "Could not setup SSL system.");
@@ -107,7 +109,8 @@ private static SSLSocketFactory getNewSslSocketFactory(X509TrustManager trustMan
107109
return sslContext.getSocketFactory();
108110
}
109111

110-
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager){
112+
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
113+
CookieJar cookieJar) {
111114
return new OkHttpClient.Builder()
112115
.addNetworkInterceptor(getLogInterceptor())
113116
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
@@ -118,6 +121,7 @@ private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFacto
118121
.followRedirects(false)
119122
.sslSocketFactory(sslSocketFactory, trustManager)
120123
.hostnameVerifier((asdf, usdf) -> true)
124+
.cookieJar(cookieJar)
121125
.build();
122126
}
123127

0 commit comments

Comments
 (0)