Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBL-1176: Add a param to indicate whether the password auth is required or not #11

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add a param to know if the password auth is required
Add requirePasswordAuth param to startHttp() and startTls() JNI functions to know whether the httpAuthCallback is required to set or not; Setting httpAuthCallback means that the password authentication is enabled.

CBL-1176
  • Loading branch information
pasin committed Aug 13, 2020
commit 4851e9e92d9a764fce0c9a1d203bae4bbe7c3996
19 changes: 13 additions & 6 deletions common/main/cpp/native_c4listener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -401,26 +401,29 @@ static C4Listener *startListener(
jboolean allowPush,
jboolean allowPull,
jboolean enableDeltaSync,
jboolean requirePasswordAuth,
C4TLSConfig *tlsConfig) {
jstringSlice iFace(env, networkInterface);
jstringSlice path(env, dbPath);

C4ListenerConfig config;
C4ListenerConfig config = {};
config.port = (uint16_t) port;
config.networkInterface = iFace;
config.apis = (unsigned) apis;
config.tlsConfig = tlsConfig;
config.httpAuthCallback = &httpAuthCallback;
config.callbackContext = (void *) context;
config.directory = path;
config.allowCreateDBs = allowCreateDBs;
config.allowDeleteDBs = allowDeleteDBs;
config.allowPush = allowPush;
config.allowPull = allowPull;
config.enableDeltaSync = enableDeltaSync;

C4Error error;
if (requirePasswordAuth) {
config.httpAuthCallback = &httpAuthCallback;
config.callbackContext = (void *) context;
}

C4Error error;
auto listener = c4listener_start(&config, &error);
if (!listener) {
throwError(env, error);
Expand Down Expand Up @@ -529,7 +532,8 @@ JNICALL Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_startHttp(
jboolean allowDeleteDBs,
jboolean allowPush,
jboolean allowPull,
jboolean enableDeltaSync) {
jboolean enableDeltaSync,
jboolean requirePasswordAuth) {

return reinterpret_cast<jlong>(startListener(
env,
Expand All @@ -543,6 +547,7 @@ JNICALL Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_startHttp(
allowPush,
allowPull,
enableDeltaSync,
requirePasswordAuth,
nullptr));
}

Expand All @@ -563,7 +568,8 @@ JNICALL Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_startTls(
jboolean allowDeleteDBs,
jboolean allowPush,
jboolean allowPull,
jboolean enableDeltaSync) {
jboolean enableDeltaSync,
jboolean requirePasswordAuth) {
C4TLSConfig tlsConfig = {};
tlsConfig.privateKeyRepresentation = kC4PrivateKeyFromKey;
tlsConfig.key = (C4KeyPair *) keyPair;
Expand Down Expand Up @@ -592,6 +598,7 @@ JNICALL Java_com_couchbase_lite_internal_core_impl_NativeC4Listener_startTls(
allowPush,
allowPull,
enableDeltaSync,
requirePasswordAuth,
&tlsConfig));
}

Expand Down