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

Commit e878ad3

Browse files
committed
make oidc discovery work again
1 parent 8d09a5c commit e878ad3

File tree

6 files changed

+11
-23
lines changed

6 files changed

+11
-23
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ class ConnectionValidator (
2020
var validationRetryCount = 0
2121
val client = OwnCloudClient(baseClient.baseUri, null, false)
2222
if (clearCookiesOnValidation) {
23-
client.cookiesForBaseUri = emptyList()
23+
client.clearCookies()
2424
} else {
2525
client.cookiesForBaseUri = baseClient.cookiesForBaseUri
2626
}
27-
//TODO: Also handle cookies
2827

2928
client.credentials = baseClient.credentials
3029
client.setFollowRedirects(true)

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public class OwnCloudClient extends HttpClient {
6262
private static final int MAX_REDIRECTIONS_COUNT = 5;
6363
private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;
6464

65-
private static byte[] sExhaustBuffer = new byte[1024];
6665
private static int sIntanceCounter = 0;
6766
private OwnCloudCredentials mCredentials = null;
6867
private int mInstanceNumber;
@@ -80,7 +79,7 @@ public class OwnCloudClient extends HttpClient {
8079

8180
private SingleSessionManager mSingleSessionManager = null;
8281

83-
private boolean mFollowRedirects;
82+
private boolean mFollowRedirects = false;
8483

8584
public OwnCloudClient(Uri baseUri, ConnectionValidator connectionValidator, boolean synchronizeRequests) {
8685
if (baseUri == null) {
@@ -357,6 +356,10 @@ public List<Cookie> getCookiesForBaseUri() {
357356
HttpUrl.parse(mBaseUri.toString()));
358357
}
359358

359+
public void clearCookies() {
360+
setCookiesForBaseUri(new ArrayList<>());
361+
}
362+
360363
public OwnCloudVersion getOwnCloudVersion() {
361364
return mVersion;
362365
}
@@ -453,7 +456,7 @@ private void invalidateAccountCredentials() {
453456
am.clearPassword(mAccount.getSavedAccount()); // being strict, only needed for Basic Auth credentials
454457
}
455458

456-
public boolean followRedirects() {
459+
public boolean getFollowRedirects() {
457460
return mFollowRedirects;
458461
}
459462

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

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

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

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

7775
} catch (Exception e) {
7876
Timber.e(e, "Could not setup SSL system.");
@@ -109,8 +107,7 @@ private static SSLSocketFactory getNewSslSocketFactory(X509TrustManager trustMan
109107
return sslContext.getSocketFactory();
110108
}
111109

112-
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager,
113-
CookieJar cookieJar) {
110+
private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager){
114111
return new OkHttpClient.Builder()
115112
.addNetworkInterceptor(getLogInterceptor())
116113
.addNetworkInterceptor(DebugInterceptorFactory.INSTANCE.getInterceptor())
@@ -121,7 +118,6 @@ private static OkHttpClient buildNewOkHttpClient(SSLSocketFactory sslSocketFacto
121118
.followRedirects(false)
122119
.sslSocketFactory(sslSocketFactory, trustManager)
123120
.hostnameVerifier((asdf, usdf) -> true)
124-
.cookieJar(cookieJar)
125121
.build();
126122
}
127123

@@ -132,19 +128,11 @@ public static LogInterceptor getLogInterceptor() {
132128
return sLogInterceptor;
133129
}
134130

135-
public static List<Cookie> getCookiesFromUrl(HttpUrl httpUrl) {
136-
return sCookieStore.get(httpUrl.host());
137-
}
138-
139131
public Context getContext() {
140132
return sContext;
141133
}
142134

143135
public static void setContext(Context context) {
144136
sContext = context;
145137
}
146-
147-
public void clearCookies() {
148-
sCookieStore.clear();
149-
}
150138
}

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/CheckPathExistenceRemoteOperation.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CheckPathExistenceRemoteOperation(
6060
private set
6161

6262
override fun run(client: OwnCloudClient): RemoteOperationResult<Boolean> {
63-
val previousFollowRedirects = client.followRedirects()
63+
val previousFollowRedirects = client.getFollowRedirects()
6464
return try {
6565
val stringUrl =
6666
if (isUserLogged) client.baseFilesWebDavUri.toString()
@@ -71,7 +71,6 @@ class CheckPathExistenceRemoteOperation(
7171
setConnectionTimeout(TIMEOUT.toLong(), TimeUnit.SECONDS)
7272
}
7373

74-
client.setFollowRedirects(false)
7574
var status = client.executeHttpMethod(propFindMethod)
7675
if (previousFollowRedirects) {
7776
redirectionPath = client.followRedirection(propFindMethod)

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/ReadRemoteFolderOperation.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ protected RemoteOperationResult<ArrayList<RemoteFile>> run(OwnCloudClient client
7777
DavConstants.DEPTH_1,
7878
DavUtils.getAllPropset());
7979

80-
client.setFollowRedirects(true);
81-
8280
int status = client.executeHttpMethod(propfindMethod);
8381

8482
if (isSuccess(status)) {

owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/oauth/GetOIDCDiscoveryRemoteOperation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class GetOIDCDiscoveryRemoteOperation : RemoteOperation<OIDCDiscoveryResponse>()
5555
addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
5656
}
5757

58+
getMethod.setFollowRedirects(true)
5859
val status = client.executeHttpMethod(getMethod)
5960

6061
val responseBody = getMethod.getResponseBodyAsString()

0 commit comments

Comments
 (0)