Skip to content

Commit 47ee509

Browse files
committed
SG Session token auth
1 parent fb9109a commit 47ee509

File tree

6 files changed

+143
-46
lines changed

6 files changed

+143
-46
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CouchbaseLiteTester
2-
###### version 1.8
2+
###### version 1.9
33
This app provides a UI to create a local Couchbase Lite DB and Sync Data to the DB from a Couchbase Sync Gateway. It provides features to search for documents in the CBLite DB, selectively sync certain channels and supports both Pull and Push replication.
44

55
## Getting Started
@@ -95,6 +95,10 @@ mvn compile package
9595
This will create a distributable JAR file in build folder. Package an appropriate defaults.xml file along with your jar file with appropriate environments setup.
9696

9797
## Features
98+
###### version 1.9
99+
* Support for Sync Gateway Session Token authentication
100+
* Bug fixes
101+
* Minor UI enhancement
98102
###### version 1.8
99103
* Bug fixes
100104
###### version 1.7
@@ -142,3 +146,4 @@ This will create a distributable JAR file in build folder. Package an appropriat
142146
* ~~Package app for distribution as JAR~~ (implemented in v1.1)
143147
* ~~Support for loading data from another CBLite DB~~ (implemented in v1.2)
144148
* ~~Support to create documents in CBLite from UI and sync up to the DB via Sync Gateway~~ (implemented in v1.3)
149+
* ~~Support for Sync Gateway Session Token Authentication~~ (implemented in v1.9)

src/main/java/io/amrishraje/cblitetester/MainController.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public class MainController implements Initializable {
9393
public AnchorPane progressAnchorPane;
9494
public Label docCountLabel;
9595
public AnchorPane docCountAnchorPane;
96+
public PasswordField sessionTokenText;
9697
Properties properties = new Properties();
9798
Properties defaults = new Properties();
9899
@FXML
@@ -102,10 +103,12 @@ public class MainController implements Initializable {
102103
private Map<String, String> cbLiteDataMap;
103104
private String user = "";
104105
private String pwd;
106+
@FXML
107+
private String sessionToken = null;
105108
private boolean channelsSet;
106109
private String currentEnvironment = "";
107110
private ObservableList<Map.Entry<String, String>> items;
108-
private String version = "v1.6";
111+
private String version = "v1.9";
109112

110113

111114
private FilteredList<Map.Entry<String, String>> filteredData;
@@ -163,9 +166,17 @@ void startSync(ActionEvent event) {
163166
logger.info("Starting sync");
164167
String localUser = userText.getText();
165168
pwd = pwdText.getText();
166-
if (localUser.isBlank() || pwd.isBlank()) {
167-
statusLabel.setText("Username and password cannot be blank!");
168-
return;
169+
sessionToken = sessionTokenText.getText();
170+
if (sessionToken.isBlank()) {
171+
if (localUser.isBlank() || pwd.isBlank()) {
172+
statusLabel.setText("Enter username and password or SG Session token");
173+
return;
174+
}
175+
} else {
176+
if (!pwd.isBlank()) {
177+
statusLabel.setText("Use either SG Session token or Username/ Password");
178+
return;
179+
}
169180
}
170181
if (!localUser.equals(user) && !user.equals("")) {
171182
statusLabel.setText("User changed. Initialize DB first and then Sync");
@@ -176,7 +187,7 @@ void startSync(ActionEvent event) {
176187
String replMode = replicationMode.getValue() == null ? "Pull" : replicationMode.getValue().toString();
177188
if (!SyncController.isReplicatorStarted) {
178189
logger.debug("Starting Sync for the first time using startReplicator");
179-
SyncController.startReplicator(localUser, pwd, continuousToggle.isSelected(), channels, replMode, this);
190+
SyncController.startReplicator(localUser, pwd, sessionToken, continuousToggle.isSelected(), channels, replMode, this);
180191
} else {
181192
logger.debug("On demand sync requested");
182193
SyncController.onDemandSync(continuousToggle.isSelected(), channels, replMode);
@@ -188,7 +199,7 @@ void startSync(ActionEvent event) {
188199
@Override
189200
public void initialize(URL url, ResourceBundle resourceBundle) {
190201
readProperties();
191-
version = properties.getProperty("version", "v1.7+");
202+
version = properties.getProperty("version", "v1.9+");
192203
readDefaults();
193204
SyncController.createLocalCBLiteFile();
194205
populateTable(false);

src/main/java/io/amrishraje/cblitetester/SyncController.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import javafx.application.Platform;
2222
import javafx.beans.property.ReadOnlyDoubleProperty;
2323
import javafx.beans.property.ReadOnlyDoubleWrapper;
24-
import javafx.concurrent.Task;
2524
import org.apache.commons.io.IOUtils;
2625
import org.slf4j.Logger;
2726
import org.slf4j.LoggerFactory;
@@ -89,7 +88,7 @@ public static void createLocalCBLiteFile() {
8988
logger.debug("CbLite file has been created and database has been initialized");
9089
}
9190

92-
public static void startReplicator(String user, String pwd, boolean isContinuous, List<String> channels, String replicationMode, MainController controller) {
91+
public static void startReplicator(String user, String pwd, String sessionToken, boolean isContinuous, List<String> channels, String replicationMode, MainController controller) {
9392
logger.debug("calling startReplicator");
9493
logger.debug("syncing channels: " + channels);
9594
mainController = controller;
@@ -148,9 +147,15 @@ public static void startReplicator(String user, String pwd, boolean isContinuous
148147
}
149148
//end cert pinning
150149
// Add authentication.
151-
replicatorConfig.setAuthenticator(new BasicAuthenticator(user, pwd));
152-
// TODO support session based auth in future
153-
// replicatorConfig.setAuthenticator(new SessionAuthenticator("00ee4a2fca27d65061f509f89c758e00a4ca83cf"));
150+
if (sessionToken.isBlank()) {
151+
logger.info("Password is: {}", pwd);
152+
replicatorConfig.setAuthenticator(new BasicAuthenticator(user, pwd));
153+
}
154+
else {
155+
logger.info("Session Token is: {}", sessionToken);
156+
replicatorConfig.setAuthenticator(new SessionAuthenticator(sessionToken));
157+
}
158+
154159
replicator = new Replicator(replicatorConfig);
155160
//Add Change listener to check for errors
156161
replicator.addChangeListener(change -> {

src/main/resources/io/amrishraje/cblitetester/CBLiteScreen.fxml

Lines changed: 108 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3+
<?import javafx.geometry.Insets?>
34
<?import javafx.scene.control.Button?>
45
<?import javafx.scene.control.ComboBox?>
56
<?import javafx.scene.control.Hyperlink?>
@@ -9,11 +10,14 @@
910
<?import javafx.scene.control.MenuItem?>
1011
<?import javafx.scene.control.PasswordField?>
1112
<?import javafx.scene.control.ProgressBar?>
13+
<?import javafx.scene.control.Separator?>
1214
<?import javafx.scene.control.TableColumn?>
1315
<?import javafx.scene.control.TableView?>
1416
<?import javafx.scene.control.TextField?>
1517
<?import javafx.scene.control.Tooltip?>
1618
<?import javafx.scene.layout.AnchorPane?>
19+
<?import javafx.scene.layout.HBox?>
20+
<?import javafx.scene.layout.Region?>
1721
<?import javafx.scene.layout.VBox?>
1822
<?import org.controlsfx.control.CheckComboBox?>
1923
<?import org.controlsfx.control.ToggleSwitch?>
@@ -39,40 +43,112 @@
3943
<children>
4044
<AnchorPane prefHeight="575.0" prefWidth="250.0" style="-fx-background-color: #555555; -fx-border-color: #333333;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
4145
<children>
42-
<TextField fx:id="userText" layoutX="39.0" layoutY="53.0" onAction="#startSync" onMouseClicked="#resetChannels" prefHeight="25.0" prefWidth="200.0" promptText="User" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="10.0" />
43-
<PasswordField fx:id="pwdText" layoutX="38.0" layoutY="106.0" onAction="#startSync" prefWidth="200.0" promptText="Password" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="50.0" />
44-
<Button fx:id="syncButton" layoutX="50.0" layoutY="152.0" mnemonicParsing="false" onAction="#startSync" prefWidth="100.0" text="Sync" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="195.0">
45-
<tooltip>
46-
<Tooltip text="Sync with Sync Gateway" />
47-
</tooltip>
48-
</Button>
49-
<Button fx:id="stopSync" disable="true" layoutX="134.0" layoutY="150.0" mnemonicParsing="false" onAction="#stopContinuousSync" prefWidth="100.0" text="Stop Sync" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="195.0">
50-
<tooltip>
51-
<Tooltip text="Stop sync if continuous sync is running" />
52-
</tooltip>
53-
</Button>
54-
<Button fx:id="initSync" layoutX="22.0" layoutY="236.0" mnemonicParsing="false" onAction="#initSync" prefHeight="25.0" prefWidth="100.0" text="Initialize" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="230.0">
55-
<tooltip>
56-
<Tooltip text="Initialize DB and sync" />
57-
</tooltip>
58-
</Button>
59-
<Button fx:id="deleteSync" layoutX="129.0" layoutY="236.0" mnemonicParsing="false" onAction="#deleteDB" prefHeight="25.0" prefWidth="100.0" text="Delete" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="230.0">
60-
<tooltip>
61-
<Tooltip text="Delete local CBLite DB file" />
62-
</tooltip>
63-
</Button>
64-
<Button fx:id="reloadTable" layoutX="4.0" layoutY="494.0" mnemonicParsing="false" onAction="#reloadTable" text="Reload Table" AnchorPane.bottomAnchor="50.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
65-
<Button fx:id="settingsButton" layoutX="84.0" layoutY="536.0" mnemonicParsing="false" onAction="#openSettings" text="Settings" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
66-
<Label fx:id="statusLabel" layoutX="20.0" layoutY="281.0" maxWidth="300.0" prefHeight="100.0" prefWidth="200.0" textFill="WHITE" wrapText="true" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="270.0" />
67-
<Label fx:id="tableStatusLabel" maxWidth="300.0" prefHeight="30.0" prefWidth="200.0" textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="380.0" />
68-
<Label layoutX="21.0" layoutY="211.0" text="Continuous Sync" textFill="WHITE" AnchorPane.leftAnchor="20.0" AnchorPane.topAnchor="165.0" />
69-
<ToggleSwitch fx:id="continuousToggle" layoutX="99.0" layoutY="211.0" onMouseClicked="#toggleContinuousMode" textFill="WHITE" AnchorPane.leftAnchor="110.0" AnchorPane.topAnchor="165.0" />
70-
<CheckComboBox fx:id="channelsComboBoxList" layoutX="21.0" layoutY="131.0" onMouseEntered="#setUpChannels" title="Sync Channels | Default: All" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="90.0" />
71-
<Hyperlink fx:id="about" layoutX="22.0" layoutY="490.0" onAction="#openAboutPage" textFill="WHITE" AnchorPane.bottomAnchor="90.0" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" />
72-
<ComboBox fx:id="replicationMode" layoutX="23.0" layoutY="132.0" prefWidth="150.0" promptText="Replication Mode | Default: Pull" visibleRowCount="3" AnchorPane.leftAnchor="20.0" AnchorPane.rightAnchor="20.0" AnchorPane.topAnchor="130.0" />
46+
<VBox spacing="8.0">
47+
<children>
48+
<AnchorPane>
49+
<children>
50+
<VBox prefWidth="210.0" spacing="8.0">
51+
<children>
52+
<TextField fx:id="userText" onAction="#startSync" onMouseClicked="#resetChannels" promptText="User" />
53+
<PasswordField fx:id="pwdText" onAction="#startSync" promptText="Password" />
54+
<Label alignment="CENTER" contentDisplay="CENTER" text="OR" textAlignment="CENTER" textFill="WHITE" />
55+
<PasswordField fx:id="sessionTokenText" promptText="SG Session Token">
56+
<VBox.margin>
57+
<Insets />
58+
</VBox.margin>
59+
</PasswordField>
60+
</children>
61+
<padding>
62+
<Insets top="5.0" />
63+
</padding>
64+
</VBox>
65+
</children>
66+
<VBox.margin>
67+
<Insets />
68+
</VBox.margin>
69+
</AnchorPane>
70+
<Separator>
71+
<VBox.margin>
72+
<Insets bottom="5.0" top="5.0" />
73+
</VBox.margin>
74+
</Separator>
75+
<CheckComboBox fx:id="channelsComboBoxList" maxWidth="1.7976931348623157E308" onMouseEntered="#setUpChannels" title="Sync Channels | Default: All" />
76+
<ComboBox fx:id="replicationMode" promptText="Replication Mode | Default: Pull" visibleRowCount="3" />
77+
<HBox>
78+
<children>
79+
<Label text="Continuous Sync" textFill="WHITE" />
80+
<ToggleSwitch fx:id="continuousToggle" onMouseClicked="#toggleContinuousMode" textFill="WHITE" />
81+
</children>
82+
<VBox.margin>
83+
<Insets />
84+
</VBox.margin>
85+
<padding>
86+
<Insets top="5.0" />
87+
</padding>
88+
</HBox>
89+
<HBox spacing="10.0">
90+
<children>
91+
<Button fx:id="syncButton" mnemonicParsing="false" onAction="#startSync" prefWidth="100.0" text="Sync">
92+
<tooltip>
93+
<Tooltip text="Sync with Sync Gateway" />
94+
</tooltip>
95+
</Button>
96+
<Button fx:id="stopSync" disable="true" mnemonicParsing="false" onAction="#stopContinuousSync" prefWidth="100.0" text="Stop Sync">
97+
<tooltip>
98+
<Tooltip text="Stop sync if continuous sync is running" />
99+
</tooltip>
100+
</Button>
101+
</children>
102+
<padding>
103+
<Insets top="5.0" />
104+
</padding>
105+
</HBox>
106+
<HBox spacing="10.0">
107+
<children>
108+
<Button fx:id="initSync" mnemonicParsing="false" onAction="#initSync" prefHeight="25.0" prefWidth="100.0" text="Initialize">
109+
<tooltip>
110+
<Tooltip text="Initialize DB and sync" />
111+
</tooltip>
112+
</Button>
113+
<Button fx:id="deleteSync" mnemonicParsing="false" onAction="#deleteDB" prefHeight="25.0" prefWidth="100.0" text="Delete">
114+
<tooltip>
115+
<Tooltip text="Delete local CBLite DB file" />
116+
</tooltip>
117+
</Button>
118+
</children>
119+
<padding>
120+
<Insets top="5.0" />
121+
</padding>
122+
</HBox>
123+
<Label fx:id="statusLabel" prefHeight="100.0" prefWidth="200.0" textFill="WHITE" wrapText="true">
124+
<VBox.margin>
125+
<Insets top="5.0" />
126+
</VBox.margin>
127+
</Label>
128+
<Label fx:id="tableStatusLabel" prefWidth="200.0" textFill="WHITE" wrapText="true" />
129+
<Region VBox.vgrow="ALWAYS">
130+
<VBox.margin>
131+
<Insets top="20.0" />
132+
</VBox.margin>
133+
</Region>
134+
<Hyperlink fx:id="about" onAction="#openAboutPage" textFill="WHITE" />
135+
<HBox spacing="10.0">
136+
<children>
137+
<Button fx:id="reloadTable" mnemonicParsing="false" onAction="#reloadTable" prefWidth="100.0" text="Reload Table" />
138+
<Button fx:id="settingsButton" mnemonicParsing="false" onAction="#openSettings" prefWidth="100.0" text="Settings" />
139+
</children>
140+
<padding>
141+
<Insets top="5.0" />
142+
</padding>
143+
</HBox>
144+
</children>
145+
<padding>
146+
<Insets left="20.0" top="10.0" />
147+
</padding>
148+
</VBox>
73149
</children>
74150
</AnchorPane>
75-
<TableView fx:id="dataTable" layoutX="251.0" layoutY="82.0" prefHeight="560.0" prefWidth="650.0" style="-fx-border-color: #777777;" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="250.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
151+
<TableView fx:id="dataTable" layoutX="251.0" layoutY="82.0" style="-fx-border-color: #777777;" tableMenuButtonVisible="true" AnchorPane.bottomAnchor="40.0" AnchorPane.leftAnchor="250.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
76152
<columns>
77153
<TableColumn fx:id="docId" maxWidth="500.0" prefWidth="250.0" text="Doc Id" />
78154
<TableColumn fx:id="docValue" text="Document Value" />

src/main/resources/io/amrishraje/cblitetester/NewDocumentEditor.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<Font name="System Italic" size="12.0" />
5959
</font>
6060
</Label>
61-
<TextField fx:id="docIdText" layoutX="102.0" layoutY="11.0" promptText="Document ID" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="10.0" />
61+
<TextField fx:id="docIdText" layoutX="102.0" layoutY="11.0" maxWidth="1.7976931348623157E308" prefWidth="300.0" promptText="Document ID" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="10.0" />
6262
</children>
6363
</AnchorPane>
6464
</children>

src/main/resources/io/amrishraje/cblitetester/tableDataPopup.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</AnchorPane>
5757
<AnchorPane prefHeight="45.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
5858
<children>
59-
<TextField fx:id="docIdLabel" editable="false" focusTraversable="false" layoutX="14.0" layoutY="10.0" prefHeight="26.0" prefWidth="175.0" style="-fx-background-color: transparent; -fx-background-insets: 0px;" AnchorPane.leftAnchor="0.0">
59+
<TextField fx:id="docIdLabel" editable="false" focusTraversable="false" layoutX="14.0" layoutY="10.0" maxWidth="1.7976931348623157E308" prefWidth="350.0" style="-fx-background-color: transparent; -fx-background-insets: 0px;" AnchorPane.leftAnchor="0.0">
6060
<font>
6161
<Font name="System Bold" size="14.0" />
6262
</font>

0 commit comments

Comments
 (0)