@@ -72,18 +72,17 @@ private static void checkFeatureSyncServerAvailable() {
7272 * Use {@link Sync#server(BoxStore, String, SyncCredentials)} instead.
7373 */
7474 @ Internal
75- public SyncServerBuilder (BoxStore boxStore , String url , SyncCredentials authenticatorCredentials ) {
75+ public SyncServerBuilder (BoxStore boxStore , String url , @ Nullable SyncCredentials authenticatorCredentials ) {
7676 checkNotNull (boxStore , "BoxStore is required." );
7777 checkNotNull (url , "Sync server URL is required." );
78- checkNotNull (authenticatorCredentials , "Authenticator credentials are required." );
7978 checkFeatureSyncServerAvailable ();
8079 this .boxStore = boxStore ;
8180 try {
8281 this .url = new URI (url );
8382 } catch (URISyntaxException e ) {
8483 throw new IllegalArgumentException ("Sync server URL is invalid: " + url , e );
8584 }
86- authenticatorCredentials (authenticatorCredentials );
85+ authenticatorCredentialsOrNull (authenticatorCredentials );
8786 }
8887
8988 /**
@@ -116,6 +115,18 @@ public SyncServerBuilder certificatePath(String certificatePath) {
116115 return this ;
117116 }
118117
118+ private SyncServerBuilder authenticatorCredentialsOrNull (@ Nullable SyncCredentials authenticatorCredentials ) {
119+ if (authenticatorCredentials == null ) {
120+ return this ; // Do nothing
121+ }
122+ if (!(authenticatorCredentials instanceof SyncCredentialsToken )) {
123+ throw new IllegalArgumentException ("Sync credentials of type " + authenticatorCredentials .getType ()
124+ + " are not supported" );
125+ }
126+ credentials .add ((SyncCredentialsToken ) authenticatorCredentials );
127+ return this ;
128+ }
129+
119130 /**
120131 * Adds additional authenticator credentials to authenticate clients or peers with.
121132 * <p>
@@ -124,12 +135,7 @@ public SyncServerBuilder certificatePath(String certificatePath) {
124135 */
125136 public SyncServerBuilder authenticatorCredentials (SyncCredentials authenticatorCredentials ) {
126137 checkNotNull (authenticatorCredentials , "Authenticator credentials must not be null." );
127- if (!(authenticatorCredentials instanceof SyncCredentialsToken )) {
128- throw new IllegalArgumentException ("Sync credentials of type " + authenticatorCredentials .getType ()
129- + " are not supported" );
130- }
131- credentials .add ((SyncCredentialsToken ) authenticatorCredentials );
132- return this ;
138+ return authenticatorCredentialsOrNull (authenticatorCredentials );
133139 }
134140
135141 /**
@@ -316,7 +322,7 @@ private boolean hasJwtConfig() {
316322 * Note: this clears all previously set authenticator credentials.
317323 */
318324 public SyncServer build () {
319- if (credentials .isEmpty ()) {
325+ if (! hasJwtConfig () && credentials .isEmpty ()) {
320326 throw new IllegalStateException ("At least one authenticator is required." );
321327 }
322328 if (hasJwtConfig ()) {
@@ -368,7 +374,10 @@ byte[] buildSyncServerOptions() {
368374 if (clusterId != null ) {
369375 clusterIdOffset = fbb .createString (clusterId );
370376 }
371- int authenticationMethodsOffset = buildAuthenticationMethods (fbb );
377+ int authenticationMethodsOffset = 0 ;
378+ if (!credentials .isEmpty ()) {
379+ authenticationMethodsOffset = buildAuthenticationMethods (fbb );
380+ }
372381 int clusterPeersVectorOffset = buildClusterPeers (fbb );
373382 int jwtConfigOffset = 0 ;
374383 if (hasJwtConfig ()) {
@@ -387,7 +396,9 @@ byte[] buildSyncServerOptions() {
387396 // After collecting all offsets, create options
388397 SyncServerOptions .startSyncServerOptions (fbb );
389398 SyncServerOptions .addUrl (fbb , urlOffset );
390- SyncServerOptions .addAuthenticationMethods (fbb , authenticationMethodsOffset );
399+ if (authenticationMethodsOffset != 0 ) {
400+ SyncServerOptions .addAuthenticationMethods (fbb , authenticationMethodsOffset );
401+ }
391402 if (syncFlags != 0 ) {
392403 SyncServerOptions .addSyncFlags (fbb , syncFlags );
393404 }
0 commit comments