11package com .marklogic .mgmt ;
22
33import com .marklogic .client .ext .helper .LoggingObject ;
4- import com .marklogic .mgmt .ManageClient ;
5- import com .marklogic .mgmt .PayloadParser ;
64import org .springframework .http .ResponseEntity ;
75import 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}
0 commit comments