Skip to content

Commit 4207b83

Browse files
Sync creds: remap SHARED_SECRET_SIPPED to SHARED_SECRET for server #202
1 parent cb1101b commit 4207b83

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

objectbox-java/src/main/java/io/objectbox/sync/Sync.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static SyncBuilder client(BoxStore boxStore, String url, SyncCredentials
3737
* Start building a sync server. Requires the BoxStore the server should use,
3838
* the URL and port the server should bind to and authenticator credentials to authenticate clients.
3939
* Additional authenticator credentials can be supplied using the builder.
40+
* <p>
41+
* For the embedded server, currently only {@link SyncCredentials#sharedSecret} and {@link SyncCredentials#none}
42+
* are supported.
4043
*/
4144
public static SyncServerBuilder server(BoxStore boxStore, String url, SyncCredentials authenticatorCredentials) {
4245
return new SyncServerBuilder(boxStore, url, authenticatorCredentials);

objectbox-java/src/main/java/io/objectbox/sync/SyncCredentials.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public enum CredentialsType {
6464
this.type = type;
6565
}
6666

67+
public CredentialsType getType() {
68+
return type;
69+
}
70+
6771
public long getTypeId() {
6872
return type.id;
6973
}

objectbox-java/src/main/java/io/objectbox/sync/server/SyncServerBuilder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public SyncServerBuilder certificatePath(String certificatePath) {
4646

4747
/**
4848
* Adds additional authenticator credentials to authenticate clients with.
49+
* <p>
50+
* For the embedded server, currently only {@link SyncCredentials#sharedSecret} and {@link SyncCredentials#none}
51+
* are supported.
4952
*/
5053
public SyncServerBuilder authenticatorCredentials(SyncCredentials authenticatorCredentials) {
5154
checkNotNull(authenticatorCredentials, "Authenticator credentials must not be null.");

objectbox-java/src/main/java/io/objectbox/sync/server/SyncServerImpl.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import io.objectbox.annotation.apihint.Internal;
66
import io.objectbox.sync.SyncCredentials;
7+
import io.objectbox.sync.SyncCredentials.CredentialsType;
78
import io.objectbox.sync.SyncCredentialsToken;
89
import io.objectbox.sync.listener.SyncChangeListener;
910

@@ -31,8 +32,16 @@ public class SyncServerImpl implements SyncServer {
3132
this.handle = handle;
3233

3334
for (SyncCredentials credentials : builder.credentials) {
35+
if (!(credentials instanceof SyncCredentialsToken)) {
36+
throw new IllegalArgumentException("Sync credentials of type " + credentials.getType() + " are not supported");
37+
}
3438
SyncCredentialsToken credentialsInternal = (SyncCredentialsToken) credentials;
35-
nativeSetAuthenticator(handle, credentialsInternal.getTypeId(), credentialsInternal.getTokenBytes());
39+
// The core API used by nativeSetAuthenticator only supports the NONE and SHARED_SECRET types
40+
// (however, protocol v3 versions do also add SHARED_SECRET_SIPPED if SHARED_SECRET is given).
41+
final CredentialsType type = credentialsInternal.getType() == CredentialsType.SHARED_SECRET_SIPPED
42+
? CredentialsType.SHARED_SECRET
43+
: credentialsInternal.getType();
44+
nativeSetAuthenticator(handle, type.id, credentialsInternal.getTokenBytes());
3645
credentialsInternal.clear(); // Clear immediately, not needed anymore.
3746
}
3847

0 commit comments

Comments
 (0)