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

Commit c2ab40e

Browse files
committed
Correctly perform cookie authentication
Correctly generate the URI for the cookie interceptor so it can perform authentication. This is done by removing the last whole path component, which is the database name that the replication is replicating with. Fixes #415
1 parent 436d30a commit c2ab40e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased
2+
- [FIXED] Issue performing cookie authentication in version 1.1.3.
3+
14
# 1.1.3 (2016-11-22)
25
- [FIXED] Incorrect message output from parameter `null` or empty checks.
36
- [FIXED] Issue where replications would error if the server returned missing revisions.

cloudant-sync-datastore-core/src/main/java/com/cloudant/sync/replication/ReplicatorBuilder.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,27 @@ private URI addCookieInterceptorIfRequired(URI uri) {
7070
if (uri.getUserInfo() != null) {
7171
String[] parts = uri.getUserInfo().split(":");
7272
if (parts.length == 2) {
73-
CookieInterceptor ci = new CookieInterceptor(parts[0], parts[1], uri.toString());
73+
74+
String path = uri.getRawPath();
75+
int index = path.lastIndexOf("/");
76+
if (index == path.length() - 1) {
77+
// we need to go back one
78+
path = path.substring(0, index);
79+
index = path.lastIndexOf("/");
80+
}
81+
82+
path = path.substring(0, index);
83+
84+
URI baseURI;
85+
86+
try {
87+
baseURI = new URI(uriProtocol, null, uriHost, uriPort, path, null, null);
88+
} catch (URISyntaxException e) {
89+
throw new RuntimeException(e);
90+
}
91+
92+
93+
CookieInterceptor ci = new CookieInterceptor(parts[0], parts[1], baseURI.toString());
7494
requestInterceptors.add(ci);
7595
responseInterceptors.add(ci);
7696
}

0 commit comments

Comments
 (0)