4
4
import com .marklogic .client .DatabaseClientFactory ;
5
5
import com .marklogic .client .DatabaseClientFactory .Authentication ;
6
6
import com .marklogic .client .DatabaseClientFactory .SSLHostnameVerifier ;
7
- import com .marklogic .client .ext .tokenreplacer .PropertiesSource ;
7
+ import com .marklogic .client .ext .ConfiguredDatabaseClientFactory ;
8
+ import com .marklogic .client .ext .DatabaseClientConfig ;
9
+ import com .marklogic .client .ext .DefaultConfiguredDatabaseClientFactory ;
10
+ import com .marklogic .client .ext .SecurityContextType ;
8
11
import com .marklogic .client .ext .modulesloader .impl .PropertiesModuleManager ;
9
12
import com .marklogic .client .ext .modulesloader .ssl .SimpleX509TrustManager ;
13
+ import com .marklogic .client .ext .tokenreplacer .PropertiesSource ;
10
14
11
15
import javax .net .ssl .SSLContext ;
12
16
import java .io .FileFilter ;
29
33
*/
30
34
public class AppConfig {
31
35
32
- /**
36
+ /**
33
37
* This is set purely for development purposes so that an app can be created without specifying an app name.
34
38
*/
35
39
public static final String DEFAULT_APP_NAME = "my-app" ;
@@ -60,24 +64,35 @@ public class AppConfig {
60
64
private String name = DEFAULT_APP_NAME ;
61
65
private String host = DEFAULT_HOST ;
62
66
67
+ // Used to construct DatabaseClient instances based on inputs defined in this class
68
+ private ConfiguredDatabaseClientFactory configuredDatabaseClientFactory = new DefaultConfiguredDatabaseClientFactory ();
69
+
63
70
// Username/password combo for using the client REST API - e.g. to load modules
71
+ private SecurityContextType restSecurityContextType = SecurityContextType .DIGEST ;
64
72
private String restAdminUsername = DEFAULT_USERNAME ;
65
73
private String restAdminPassword = DEFAULT_PASSWORD ;
66
74
private SSLContext restSslContext ;
67
75
private SSLHostnameVerifier restSslHostnameVerifier ;
68
- private Authentication restAuthentication = Authentication .DIGEST ;
69
-
70
- private SSLContext appServicesSslContext ;
71
- private SSLHostnameVerifier appServicesSslHostnameVerifier ;
72
- private Authentication appServicesAuthentication = Authentication .DIGEST ;
73
-
76
+ private String restCertFile ;
77
+ private String restCertPassword ;
78
+ private String restExternalName ;
79
+ @ Deprecated
80
+ private Authentication restAuthentication ;
74
81
private Integer restPort = DEFAULT_PORT ;
75
82
private Integer testRestPort ;
76
83
77
84
// Username/password combo for using the App Services client REST API - e.g. to load non-REST API modules
85
+ private SecurityContextType appServicesSecurityContextType = SecurityContextType .DIGEST ;
78
86
private String appServicesUsername = DEFAULT_USERNAME ;
79
87
private String appServicesPassword = DEFAULT_PASSWORD ;
80
88
private Integer appServicesPort = 8000 ;
89
+ private SSLContext appServicesSslContext ;
90
+ private SSLHostnameVerifier appServicesSslHostnameVerifier ;
91
+ private String appServicesCertFile ;
92
+ private String appServicesCertPassword ;
93
+ private String appServicesExternalName ;
94
+ @ Deprecated
95
+ private Authentication appServicesAuthentication ;
81
96
82
97
// These can all be set to override the default names that are generated off of the "name" attribute.
83
98
private String groupName = DEFAULT_GROUP ;
@@ -176,19 +191,23 @@ public AppConfig(String defaultModulePath, String defaultSchemasPath) {
176
191
}
177
192
178
193
public void setSimpleSslConfig () {
179
- setRestSslContext (SimpleX509TrustManager .newSSLContext ());
180
- setRestSslHostnameVerifier (DatabaseClientFactory .SSLHostnameVerifier .ANY );
194
+ setRestSslContext (SimpleX509TrustManager .newSSLContext ());
195
+ setRestSslHostnameVerifier (DatabaseClientFactory .SSLHostnameVerifier .ANY );
196
+ }
197
+
198
+ public void setAppServicesSimpleSslConfig () {
199
+ setAppServicesSslContext (SimpleX509TrustManager .newSSLContext ());
200
+ setAppServicesSslHostnameVerifier (DatabaseClientFactory .SSLHostnameVerifier .ANY );
181
201
}
182
202
183
203
/**
184
- * Convenience method for constructing a MarkLogic Java API DatabaseClient based on the host, restPort,
185
- * restAdminUsername, restAdminPassword, restAuthentication, restSslContext, and restSslHostnameVerifier properties .
204
+ * Convenience method for constructing a MarkLogic Java API DatabaseClient based on the the host and rest*
205
+ * properties defined on this class .
186
206
*
187
207
* @return
188
208
*/
189
209
public DatabaseClient newDatabaseClient () {
190
- return DatabaseClientFactory .newClient (getHost (), getRestPort (), getRestAdminUsername (), getRestAdminPassword (),
191
- getRestAuthentication (), getRestSslContext (), getRestSslHostnameVerifier ());
210
+ return configuredDatabaseClientFactory .newDatabaseClient (newRestDatabaseClientConfig (getRestPort ()));
192
211
}
193
212
194
213
/**
@@ -197,25 +216,49 @@ public DatabaseClient newDatabaseClient() {
197
216
* @return
198
217
*/
199
218
public DatabaseClient newTestDatabaseClient () {
200
- return DatabaseClientFactory .newClient (getHost (), getTestRestPort (), getRestAdminUsername (),
201
- getRestAdminPassword (), getRestAuthentication (), getRestSslContext (), getRestSslHostnameVerifier ());
219
+ return configuredDatabaseClientFactory .newDatabaseClient (newRestDatabaseClientConfig (getTestRestPort ()));
220
+ }
221
+
222
+ public DatabaseClientConfig newRestDatabaseClientConfig (int port ) {
223
+ DatabaseClientConfig config = new DatabaseClientConfig (getHost (), port , getRestAdminUsername (), getRestAdminPassword ());
224
+ config .setAuthentication (getRestAuthentication ());
225
+ config .setSecurityContextType (restSecurityContextType );
226
+ config .setSslHostnameVerifier (getRestSslHostnameVerifier ());
227
+ config .setSslContext (getRestSslContext ());
228
+ config .setCertFile (getRestCertFile ());
229
+ config .setCertPassword (getRestCertPassword ());
230
+ config .setExternalName (getRestExternalName ());
231
+ return config ;
202
232
}
203
233
204
- public DatabaseClient newModulesDatabaseClient () {
205
- return DatabaseClientFactory .newClient (getHost (), getAppServicesPort (), getModulesDatabaseName (),
206
- getAppServicesUsername (), getAppServicesPassword (), getAppServicesAuthentication (), getAppServicesSslContext (),
207
- getAppServicesSslHostnameVerifier ());
234
+ /**
235
+ * Constructs a DatabaseClient based on host, the appServices* properties, and the modules database name.
236
+ * @return
237
+ */
238
+ public DatabaseClient newModulesDatabaseClient () {
239
+ return newAppServicesDatabaseClient (getModulesDatabaseName ());
208
240
}
209
241
210
242
/**
211
- * Like newDatabaseClient , but connects to schemas database.
243
+ * Like newModulesDatabaseClient , but connects to schemas database.
212
244
*
213
245
* @return
214
246
*/
215
247
public DatabaseClient newSchemasDatabaseClient () {
216
- return DatabaseClientFactory .newClient (getHost (), getAppServicesPort (), getSchemasDatabaseName (),
217
- getAppServicesUsername (), getAppServicesPassword (), getAppServicesAuthentication (), getAppServicesSslContext (),
218
- getAppServicesSslHostnameVerifier ());
248
+ return newAppServicesDatabaseClient (getSchemasDatabaseName ());
249
+ }
250
+
251
+ public DatabaseClient newAppServicesDatabaseClient (String databaseName ) {
252
+ DatabaseClientConfig config = new DatabaseClientConfig (getHost (), getAppServicesPort (), getAppServicesUsername (), getAppServicesPassword ());
253
+ config .setDatabase (databaseName );
254
+ config .setAuthentication (getAppServicesAuthentication ());
255
+ config .setSecurityContextType (appServicesSecurityContextType );
256
+ config .setSslHostnameVerifier (getAppServicesSslHostnameVerifier ());
257
+ config .setSslContext (getAppServicesSslContext ());
258
+ config .setCertFile (getAppServicesCertFile ());
259
+ config .setCertPassword (getAppServicesCertPassword ());
260
+ config .setExternalName (getAppServicesExternalName ());
261
+ return configuredDatabaseClientFactory .newDatabaseClient (config );
219
262
}
220
263
221
264
/**
@@ -410,10 +453,12 @@ public void setGroupName(String groupName) {
410
453
* @return the MarkLogic Java Client {@code Authentication} object that is used for authenticating with a REST API
411
454
* server for loading modules
412
455
*/
456
+ @ Deprecated
413
457
public Authentication getRestAuthentication () {
414
458
return restAuthentication ;
415
459
}
416
460
461
+ @ Deprecated
417
462
public void setRestAuthentication (Authentication authentication ) {
418
463
this .restAuthentication = authentication ;
419
464
}
@@ -705,10 +750,12 @@ public void setAppServicesSslHostnameVerifier(SSLHostnameVerifier appServicesSsl
705
750
this .appServicesSslHostnameVerifier = appServicesSslHostnameVerifier ;
706
751
}
707
752
753
+ @ Deprecated
708
754
public Authentication getAppServicesAuthentication () {
709
755
return appServicesAuthentication ;
710
756
}
711
757
758
+ @ Deprecated
712
759
public void setAppServicesAuthentication (Authentication appServicesAuthentication ) {
713
760
this .appServicesAuthentication = appServicesAuthentication ;
714
761
}
@@ -784,4 +831,76 @@ public String getDeleteTestModulesPattern() {
784
831
public void setDeleteTestModulesPattern (String deleteTestModulesPattern ) {
785
832
this .deleteTestModulesPattern = deleteTestModulesPattern ;
786
833
}
834
+
835
+ public SecurityContextType getRestSecurityContextType () {
836
+ return restSecurityContextType ;
837
+ }
838
+
839
+ public void setRestSecurityContextType (SecurityContextType restSecurityContextType ) {
840
+ this .restSecurityContextType = restSecurityContextType ;
841
+ }
842
+
843
+ public SecurityContextType getAppServicesSecurityContextType () {
844
+ return appServicesSecurityContextType ;
845
+ }
846
+
847
+ public void setAppServicesSecurityContextType (SecurityContextType appServicesSecurityContextType ) {
848
+ this .appServicesSecurityContextType = appServicesSecurityContextType ;
849
+ }
850
+
851
+ public String getRestCertFile () {
852
+ return restCertFile ;
853
+ }
854
+
855
+ public void setRestCertFile (String restCertFile ) {
856
+ this .restCertFile = restCertFile ;
857
+ }
858
+
859
+ public String getRestCertPassword () {
860
+ return restCertPassword ;
861
+ }
862
+
863
+ public void setRestCertPassword (String restCertPassword ) {
864
+ this .restCertPassword = restCertPassword ;
865
+ }
866
+
867
+ public String getAppServicesCertFile () {
868
+ return appServicesCertFile ;
869
+ }
870
+
871
+ public void setAppServicesCertFile (String appServicesCertFile ) {
872
+ this .appServicesCertFile = appServicesCertFile ;
873
+ }
874
+
875
+ public String getAppServicesCertPassword () {
876
+ return appServicesCertPassword ;
877
+ }
878
+
879
+ public void setAppServicesCertPassword (String appServicesCertPassword ) {
880
+ this .appServicesCertPassword = appServicesCertPassword ;
881
+ }
882
+
883
+ public String getRestExternalName () {
884
+ return restExternalName ;
885
+ }
886
+
887
+ public void setRestExternalName (String restExternalName ) {
888
+ this .restExternalName = restExternalName ;
889
+ }
890
+
891
+ public String getAppServicesExternalName () {
892
+ return appServicesExternalName ;
893
+ }
894
+
895
+ public void setAppServicesExternalName (String appServicesExternalName ) {
896
+ this .appServicesExternalName = appServicesExternalName ;
897
+ }
898
+
899
+ public ConfiguredDatabaseClientFactory getConfiguredDatabaseClientFactory () {
900
+ return configuredDatabaseClientFactory ;
901
+ }
902
+
903
+ public void setConfiguredDatabaseClientFactory (ConfiguredDatabaseClientFactory configuredDatabaseClientFactory ) {
904
+ this .configuredDatabaseClientFactory = configuredDatabaseClientFactory ;
905
+ }
787
906
}
0 commit comments