@@ -37,30 +37,49 @@ public ManageClient() {
3737 }
3838
3939 public ManageClient (ManageConfig config ) {
40- initialize (config );
40+ setManageConfig (config );
4141 }
4242
43- public void initialize (ManageConfig config ) {
44- this .manageConfig = config ;
45- if (logger .isInfoEnabled ()) {
46- logger .info ("Initializing ManageClient with manage config of: " + config );
47- }
48- this .restTemplate = RestTemplateUtil .newRestTemplate (config );
49-
50- if (!config .getUsername ().equals (config .getAdminUsername ())) {
51- if (logger .isInfoEnabled ()) {
52- logger .info ("Initializing ManageClient with admin config, admin user: " + config .getAdminUsername ());
53- }
54-
55- RestConfig rc = new RestConfig (config .getHost (), config .getPort (), config .getAdminUsername (), config .getAdminPassword ());
56- rc .setScheme (config .getScheme ());
57- rc .setConfigureSimpleSsl (config .isConfigureSimpleSsl ());
58- rc .setHostnameVerifier (config .getHostnameVerifier ());
59- rc .setSslContext (config .getSslContext ());
60- this .adminRestTemplate = RestTemplateUtil .newRestTemplate (rc );
61- } else {
62- this .adminRestTemplate = restTemplate ;
63- }
43+ /**
44+ * Use setManageConfig instead.
45+ *
46+ * @param config
47+ */
48+ @ Deprecated
49+ public void initialize (ManageConfig config ) {
50+ setManageConfig (config );
51+ }
52+
53+ /**
54+ * Uses the given ManageConfig instance to construct a Spring RestTemplate for communicating with the Manage API.
55+ * In addition, if adminUsername on the ManageConfig instance differs from username, then a separate RestTemplate is
56+ * constructed for making calls to the Manage API that need an admin user (as noted elsewhere, these are usually
57+ * calls for creating users/roles/privileges that only need "manage-admin" and "security", but that's typically
58+ * an admin user).
59+ *
60+ * @param config
61+ */
62+ public void setManageConfig (ManageConfig config ) {
63+ this .manageConfig = config ;
64+ if (logger .isInfoEnabled ()) {
65+ logger .info ("Initializing ManageClient with manage config of: " + config );
66+ }
67+ this .restTemplate = RestTemplateUtil .newRestTemplate (config );
68+
69+ if (!config .getUsername ().equals (config .getAdminUsername ())) {
70+ if (logger .isInfoEnabled ()) {
71+ logger .info ("Initializing ManageClient with admin config, admin user: " + config .getAdminUsername ());
72+ }
73+
74+ RestConfig rc = new RestConfig (config .getHost (), config .getPort (), config .getAdminUsername (), config .getAdminPassword ());
75+ rc .setScheme (config .getScheme ());
76+ rc .setConfigureSimpleSsl (config .isConfigureSimpleSsl ());
77+ rc .setHostnameVerifier (config .getHostnameVerifier ());
78+ rc .setSslContext (config .getSslContext ());
79+ this .adminRestTemplate = RestTemplateUtil .newRestTemplate (rc );
80+ } else {
81+ this .adminRestTemplate = restTemplate ;
82+ }
6483 }
6584
6685 /**
@@ -243,15 +262,16 @@ public HttpEntity<String> buildXmlEntity(String xml) {
243262
244263 protected void logRequest (String path , String contentType , String method ) {
245264 if (logger .isInfoEnabled ()) {
246- logger . info ( String . format ( "Sending %s %s request as user '%s' to path: %s" , contentType , method ,
247- manageConfig . getUsername () , path ));
265+ String username = manageConfig != null ? manageConfig . getUsername () : "(unknown)" ;
266+ logger . info ( String . format ( "Sending %s %s request as user '%s' to path: %s" , contentType , method , username , path ));
248267 }
249268 }
250269
251270 protected void logAdminRequest (String path , String contentType , String method ) {
252271 if (logger .isInfoEnabled ()) {
272+ String username = manageConfig != null ? manageConfig .getUsername () : "(unknown)" ;
253273 logger .info (String .format ("Sending %s %s request as user with admin role '%s' to path: %s" , contentType ,
254- method , manageConfig . getUsername () , path ));
274+ method , username , path ));
255275 }
256276 }
257277
0 commit comments