Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit a18424d

Browse files
authored
Merge branch 'dev' into dev
2 parents e1cba3d + cad9145 commit a18424d

File tree

14 files changed

+207
-25
lines changed

14 files changed

+207
-25
lines changed

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group=com.marklogic
22
javadocsDir=../gh-pages-marklogic-java/javadocs
3-
version=3.8.1
4-
mlJavaclientUtilVersion=3.8.0
3+
version=3.8.4
4+
mlJavaclientUtilVersion=3.8.1
55
mlJunitVersion=3.1.0
66

src/main/java/com/marklogic/appdeployer/AppConfig.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.marklogic.client.ext.tokenreplacer.PropertiesSource;
1414

1515
import javax.net.ssl.SSLContext;
16+
import javax.net.ssl.X509TrustManager;
1617
import java.io.FileFilter;
1718
import java.util.*;
1819
import java.util.regex.Pattern;
@@ -83,6 +84,7 @@ public class AppConfig {
8384
private String restCertFile;
8485
private String restCertPassword;
8586
private String restExternalName;
87+
private X509TrustManager restTrustManager;
8688
private Integer restPort = DEFAULT_PORT;
8789
private Integer testRestPort;
8890

@@ -96,6 +98,7 @@ public class AppConfig {
9698
private String appServicesCertFile;
9799
private String appServicesCertPassword;
98100
private String appServicesExternalName;
101+
private X509TrustManager appServicesTrustManager;
99102

100103
// These can all be set to override the default names that are generated off of the "name" attribute.
101104
private String groupName = DEFAULT_GROUP;
@@ -300,12 +303,13 @@ public DatabaseClient newTestDatabaseClient() {
300303

301304
public DatabaseClientConfig newRestDatabaseClientConfig(int port) {
302305
DatabaseClientConfig config = new DatabaseClientConfig(getHost(), port, getRestAdminUsername(), getRestAdminPassword());
303-
config.setSecurityContextType(restSecurityContextType);
304-
config.setSslHostnameVerifier(getRestSslHostnameVerifier());
305-
config.setSslContext(getRestSslContext());
306306
config.setCertFile(getRestCertFile());
307307
config.setCertPassword(getRestCertPassword());
308308
config.setExternalName(getRestExternalName());
309+
config.setSecurityContextType(restSecurityContextType);
310+
config.setSslContext(getRestSslContext());
311+
config.setSslHostnameVerifier(getRestSslHostnameVerifier());
312+
config.setTrustManager(restTrustManager);
309313
return config;
310314
}
311315

@@ -328,13 +332,14 @@ public DatabaseClient newSchemasDatabaseClient() {
328332

329333
public DatabaseClient newAppServicesDatabaseClient(String databaseName) {
330334
DatabaseClientConfig config = new DatabaseClientConfig(getHost(), getAppServicesPort(), getAppServicesUsername(), getAppServicesPassword());
331-
config.setDatabase(databaseName);
332-
config.setSecurityContextType(appServicesSecurityContextType);
333-
config.setSslHostnameVerifier(getAppServicesSslHostnameVerifier());
334-
config.setSslContext(getAppServicesSslContext());
335335
config.setCertFile(getAppServicesCertFile());
336336
config.setCertPassword(getAppServicesCertPassword());
337+
config.setDatabase(databaseName);
337338
config.setExternalName(getAppServicesExternalName());
339+
config.setSecurityContextType(appServicesSecurityContextType);
340+
config.setSslContext(getAppServicesSslContext());
341+
config.setSslHostnameVerifier(getAppServicesSslHostnameVerifier());
342+
config.setTrustManager(appServicesTrustManager);
338343
return configuredDatabaseClientFactory.newDatabaseClient(config);
339344
}
340345

@@ -1226,4 +1231,20 @@ public boolean isUpdateMimetypeWhenPropertiesAreEqual() {
12261231
public void setUpdateMimetypeWhenPropertiesAreEqual(boolean updateMimetypeWhenPropertiesAreEqual) {
12271232
this.updateMimetypeWhenPropertiesAreEqual = updateMimetypeWhenPropertiesAreEqual;
12281233
}
1234+
1235+
public X509TrustManager getRestTrustManager() {
1236+
return restTrustManager;
1237+
}
1238+
1239+
public void setRestTrustManager(X509TrustManager restTrustManager) {
1240+
this.restTrustManager = restTrustManager;
1241+
}
1242+
1243+
public X509TrustManager getAppServicesTrustManager() {
1244+
return appServicesTrustManager;
1245+
}
1246+
1247+
public void setAppServicesTrustManager(X509TrustManager appServicesTrustManager) {
1248+
this.appServicesTrustManager = appServicesTrustManager;
1249+
}
12291250
}

src/main/java/com/marklogic/appdeployer/command/forests/DeployForestsCommand.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,35 @@
3131
*/
3232
public class DeployForestsCommand extends AbstractCommand {
3333

34+
/**
35+
* This was added back in 3.8.2 to preserve backwards compatibility, as it was removed in 3.7.0.
36+
*/
37+
public static final String DEFAULT_FOREST_PAYLOAD = "{\"forest-name\": \"%%FOREST_NAME%%\", \"host\": \"%%FOREST_HOST%%\", "
38+
+ "\"database\": \"%%FOREST_DATABASE%%\"}";
39+
3440
private int forestsPerHost = 1;
3541
private String databaseName;
3642
private String forestFilename;
3743
private String forestPayload;
3844
private boolean createForestsOnEachHost = true;
3945
private HostCalculator hostCalculator;
4046

41-
public DeployForestsCommand(String databaseName) {
47+
/**
48+
* This was added back in 3.8.2 to preserve backwards compatibility, as it was removed in 3.7.0. If you use this
49+
* constructor, be sure to call setDatabaseName.
50+
*/
51+
public DeployForestsCommand() {
4252
setExecuteSortOrder(SortOrderConstants.DEPLOY_FORESTS);
53+
}
54+
55+
/**
56+
* This is the preferred constructor to use for this class, as it requires a database name, which is required for
57+
* this command to execute correctly.
58+
*
59+
* @param databaseName
60+
*/
61+
public DeployForestsCommand(String databaseName) {
62+
this();
4363
this.databaseName = databaseName;
4464
}
4565

@@ -217,4 +237,13 @@ public void setCreateForestsOnEachHost(boolean createForestsOnEachHost) {
217237
public void setHostCalculator(HostCalculator hostCalculator) {
218238
this.hostCalculator = hostCalculator;
219239
}
240+
241+
/**
242+
* This was added back in 3.8.2 to preserve backwards compatibility, as it was removed in 3.7.0.
243+
*
244+
* @param databaseName
245+
*/
246+
public void setDatabaseName(String databaseName) {
247+
this.databaseName = databaseName;
248+
}
220249
}

src/main/java/com/marklogic/appdeployer/command/restapis/DeployRestApiServersCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public Integer getUndoSortOrder() {
6060
public void execute(CommandContext context) {
6161
String payload = getRestApiPayload(context);
6262
if (payload != null) {
63-
RestApiManager mgr = new RestApiManager(context.getManageClient());
6463
AppConfig appConfig = context.getAppConfig();
64+
RestApiManager mgr = new RestApiManager(context.getManageClient(), appConfig.getGroupName());
6565

6666
mgr.createRestApi(payloadTokenReplacer.replaceTokens(payload, appConfig, false));
6767

@@ -194,7 +194,7 @@ protected boolean deleteRestApi(String serverName, String groupName, ManageClien
194194
request.setIncludeModules(includeModules);
195195
request.setDeleteContentReplicaForests(isDeleteContentReplicaForests());
196196
request.setDeleteModulesReplicaForests(isDeleteModulesReplicaForests());
197-
return new RestApiManager(manageClient).deleteRestApi(request);
197+
return new RestApiManager(manageClient, groupName).deleteRestApi(request);
198198
}
199199

200200
public boolean isDeleteModulesDatabase() {

src/main/java/com/marklogic/mgmt/AbstractManager.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,27 @@ protected String getResourceId(String payload) {
6060

6161
protected ResponseEntity<String> putPayload(ManageClient client, String path, String payload) {
6262
boolean requiresSecurityUser = useSecurityUser(payload);
63-
if (payloadParser.isJsonPayload(payload)) {
64-
return requiresSecurityUser ? client.putJsonAsSecurityUser(path, payload) : client.putJson(path, payload);
63+
try {
64+
if (payloadParser.isJsonPayload(payload)) {
65+
return requiresSecurityUser ? client.putJsonAsSecurityUser(path, payload) : client.putJson(path, payload);
66+
}
67+
return requiresSecurityUser ? client.putXmlAsSecurityUser(path, payload) : client.putXml(path, payload);
68+
} catch (RuntimeException ex) {
69+
logger.error(format("Error occurred while sending PUT request to %s; logging request body to assist with debugging: %s", path, payload));
70+
throw ex;
6571
}
66-
return requiresSecurityUser ? client.putXmlAsSecurityUser(path, payload) : client.putXml(path, payload);
6772
}
6873

6974
protected ResponseEntity<String> postPayload(ManageClient client, String path, String payload) {
7075
boolean requiresSecurityUser = useSecurityUser(payload);
71-
if (payloadParser.isJsonPayload(payload)) {
72-
return requiresSecurityUser ? client.postJsonAsSecurityUser(path, payload) : client.postJson(path, payload);
76+
try {
77+
if (payloadParser.isJsonPayload(payload)) {
78+
return requiresSecurityUser ? client.postJsonAsSecurityUser(path, payload) : client.postJson(path, payload);
79+
}
80+
return requiresSecurityUser ? client.postXmlAsSecurityUser(path, payload) : client.postXml(path, payload);
81+
} catch (RuntimeException ex) {
82+
logger.error(format("Error occurred while sending POST request to %s; logging request body to assist with debugging: %s", path, payload));
83+
throw ex;
7384
}
74-
return requiresSecurityUser ? client.postXmlAsSecurityUser(path, payload) : client.postXml(path, payload);
7585
}
7686
}

src/main/java/com/marklogic/mgmt/ManageClient.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ public void setManageConfig(ManageConfig config) {
7575
rc.setScheme(config.getScheme());
7676
rc.setConfigureSimpleSsl(config.isConfigureSimpleSsl());
7777
rc.setHostnameVerifier(config.getHostnameVerifier());
78-
rc.setSslContext(config.getSslContext());
78+
79+
if (config.getSecuritySslContext() != null) {
80+
rc.setSslContext(config.getSecuritySslContext());
81+
} else {
82+
rc.setSslContext(config.getSslContext());
83+
}
84+
7985
this.securityUserRestTemplate = RestTemplateUtil.newRestTemplate(rc);
8086
} else {
8187
this.securityUserRestTemplate = restTemplate;

src/main/java/com/marklogic/mgmt/ManageConfig.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
import com.marklogic.rest.util.RestConfig;
44

5+
import javax.net.ssl.SSLContext;
6+
57
/**
68
* Defines the configuration data for talking to the Mgmt REST API. Also includes properties for the security user, as this
79
* user is typically needed for creating an app-specific user (which may depend on app-specific roles and privileges)
8-
* which is then used for deploying every other resources. If securityUsername and securityPassword are not set, they default
9-
* to the username/password attribute values.
10+
* which is then used for deploying every other resources.
11+
*
12+
* If securityUsername and securityPassword are not set, they default to the username/password attribute values.
13+
* Additionally, as of version 3.8.3, setSecuritySslContext can be called to provide an SSLContext for the connection
14+
* made using securityUsername and securityPassword.
1015
*/
1116
public class ManageConfig extends RestConfig {
1217

@@ -19,6 +24,7 @@ public class ManageConfig extends RestConfig {
1924

2025
private String securityUsername;
2126
private String securityPassword;
27+
private SSLContext securitySslContext;
2228

2329
private boolean cleanJsonPayloads = false;
2430

@@ -105,4 +111,12 @@ public String getSecurityPassword() {
105111
public void setSecurityPassword(String securityPassword) {
106112
this.securityPassword = securityPassword;
107113
}
114+
115+
public SSLContext getSecuritySslContext() {
116+
return securitySslContext;
117+
}
118+
119+
public void setSecuritySslContext(SSLContext securitySslContext) {
120+
this.securitySslContext = securitySslContext;
121+
}
108122
}

src/main/java/com/marklogic/mgmt/api/restapi/RestApi.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public String getJson() {
2929
}
3030

3131
public String save() {
32-
ResponseEntity<String> re = new RestApiManager(api.getManageClient()).createRestApi(name, getJson());
32+
ResponseEntity<String> re = new RestApiManager(api.getManageClient(), this.group).createRestApi(name, getJson());
3333
if (re == null) {
3434
return String.format("REST API with name %s already exists", name);
3535
} else {

src/main/java/com/marklogic/mgmt/resource/restapis/RestApiManager.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ public class RestApiManager extends LoggingObject {
1616

1717
private PayloadParser payloadParser = new PayloadParser();
1818
private ManageClient client;
19+
private String groupName;
1920

2021
public RestApiManager(ManageClient client) {
22+
this(client, ServerManager.DEFAULT_GROUP);
23+
}
24+
25+
public RestApiManager(ManageClient client, String groupName) {
2126
this.client = client;
27+
this.groupName = groupName;
2228
}
2329

2430
public ResponseEntity<String> createRestApi(String json) {
@@ -48,15 +54,20 @@ public String extractNameFromJson(String json) {
4854
* somewhere in it. With 9.0-4, the url-rewriter must match the pattern:
4955
* <p>
5056
* ^/MarkLogic/rest-api/(8000-rewriter|rewriter|rewriter-noxdbc)\.xml$
57+
* </p>
5158
* <p>
5259
* It's not likely that a user's custom rewriter will fit that pattern, so this method no longer uses /v1/rest-apis,
5360
* opting to use ServerManager instead.
54-
*
61+
* </p>
62+
* <p>
63+
* As of ml-app-deployer version 3.8.4, this now properly accounts for a group name.
64+
* </p>
5565
* @param name
5666
* @return
5767
*/
5868
public boolean restApiServerExists(String name) {
59-
return new ServerManager(client).exists(name);
69+
final String group = this.groupName != null ? this.groupName : ServerManager.DEFAULT_GROUP;
70+
return new ServerManager(this.client, group).exists(name);
6071
}
6172

6273
/**

src/main/java/com/marklogic/rest/util/configurer/SslConfigurer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void verify(String host, String[] cns, String[] subjectAlts) {
6969

7070
@Override
7171
public boolean verify(String s, SSLSession sslSession) {
72-
return false;
72+
return true;
7373
}
7474
});
7575
}

0 commit comments

Comments
 (0)