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

Commit 94fd276

Browse files
committed
#232 Renamed mlAdminUsername to mlSecurityUsername
And lots of related renames to go with it. And AdminManager now uses mlManageUsername too, which should suffice.
1 parent c9c7892 commit 94fd276

18 files changed

+303
-112
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.marklogic.mgmt;
22

33
import com.marklogic.client.ext.helper.LoggingObject;
4-
import com.marklogic.mgmt.ManageClient;
5-
import com.marklogic.mgmt.PayloadParser;
64
import org.springframework.http.ResponseEntity;
75
import org.springframework.util.ClassUtils;
86

@@ -11,16 +9,16 @@ public class AbstractManager extends LoggingObject {
119
protected PayloadParser payloadParser = new PayloadParser();
1210

1311
/**
14-
* Manager classes that need to connect to ML as a user with the admin role should override this to return true.
12+
* Manager classes that need to connect to ML as a user with the manage-admin and security roles (e.g. all the
13+
* classes for Security resources) should override this to return true.
14+
*
1515
* The main use case for this is while an application may define a user with the manage-admin role that can be used
1616
* for deploying most resources, that user must first be created. And thus, some user with at least the manage-admin
17-
* and security roles must already exist and must be used to create that user. And while only the manage-admin and
18-
* security roles are needed, in practice it's likely that this is an admin user. Finally, since that user may
19-
* depend on app-specific roles and privileges, then those resources must be created first by the admin user too.
17+
* and security roles must already exist and must be used to create that user.
2018
*
2119
* @return
2220
*/
23-
protected boolean useAdminUser() {
21+
protected boolean useSecurityUser() {
2422
return false;
2523
}
2624

@@ -50,18 +48,18 @@ protected String getResourceId(String payload) {
5048
}
5149

5250
protected ResponseEntity<String> putPayload(ManageClient client, String path, String payload) {
53-
boolean useAdmin = useAdminUser();
51+
boolean requiresSecurityUser = useSecurityUser();
5452
if (payloadParser.isJsonPayload(payload)) {
55-
return useAdmin ? client.putJsonAsAdmin(path, payload) : client.putJson(path, payload);
53+
return requiresSecurityUser ? client.putJsonAsSecurityUser(path, payload) : client.putJson(path, payload);
5654
}
57-
return useAdmin ? client.putXmlAsAdmin(path, payload) : client.putXml(path, payload);
55+
return requiresSecurityUser ? client.putXmlAsSecurityUser(path, payload) : client.putXml(path, payload);
5856
}
5957

6058
protected ResponseEntity<String> postPayload(ManageClient client, String path, String payload) {
61-
boolean useAdmin = useAdminUser();
59+
boolean requiresSecurityUser = useSecurityUser();
6260
if (payloadParser.isJsonPayload(payload)) {
63-
return useAdmin ? client.postJsonAsAdmin(path, payload) : client.postJson(path, payload);
61+
return requiresSecurityUser ? client.postJsonAsSecurityUser(path, payload) : client.postJson(path, payload);
6462
}
65-
return useAdmin ? client.postXmlAsAdmin(path, payload) : client.postXml(path, payload);
63+
return requiresSecurityUser ? client.postXmlAsSecurityUser(path, payload) : client.postXml(path, payload);
6664
}
6765
}

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

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,37 @@ public ManageConfig newManageConfig() {
7272
c.setCleanJsonPayloads(Boolean.parseBoolean(prop));
7373
}
7474

75-
prop = getProperty("mlAdminUsername");
75+
prop = getProperty("mlSecurityUsername");
7676
if (prop != null) {
77-
logger.info("Manage admin username: " + prop);
78-
c.setAdminUsername(prop);
79-
} else if (mlUsername != null) {
80-
logger.info("Manage admin username: " + mlUsername);
81-
c.setAdminUsername(mlUsername);
82-
} else {
83-
c.setAdminUsername(c.getUsername());
77+
logger.info("Manage user with security role: " + prop);
78+
c.setSecurityUsername(prop);
79+
}
80+
else {
81+
prop = getProperty("mlAdminUsername");
82+
if (prop != null) {
83+
logger.info("DEPRECATED; please use mlSecurityUsername; Manage user with security role: " + prop);
84+
c.setSecurityUsername(prop);
85+
} else if (mlUsername != null) {
86+
logger.info("Manage user with security role: " + mlUsername);
87+
c.setSecurityUsername(mlUsername);
88+
} else {
89+
c.setSecurityUsername(c.getUsername());
90+
}
8491
}
8592

86-
prop = getProperty("mlAdminPassword");
93+
prop = getProperty("mlSecurityPassword");
8794
if (prop != null) {
88-
c.setAdminPassword(prop);
89-
} else if (mlPassword != null) {
90-
c.setAdminPassword(mlPassword);
95+
c.setSecurityPassword(prop);
9196
} else {
92-
c.setAdminPassword(c.getPassword());
97+
prop = getProperty("mlAdminPassword");
98+
if (prop != null) {
99+
logger.info("DEPRECATED; please use mlSecurityPassword instead of mlAdminPassword");
100+
c.setSecurityPassword(prop);
101+
} else if (mlPassword != null) {
102+
c.setSecurityPassword(mlPassword);
103+
} else {
104+
c.setSecurityPassword(c.getPassword());
105+
}
93106
}
94107

95108
return c;

0 commit comments

Comments
 (0)