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

Commit 2b1476d

Browse files
committed
#386 Fixed logging for security requests
1 parent 9a471a0 commit 2b1476d

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.http.*;
1111
import org.springframework.util.LinkedMultiValueMap;
1212
import org.springframework.util.MultiValueMap;
13+
import org.springframework.util.StringUtils;
1314
import org.springframework.web.client.RestTemplate;
1415

1516
import java.io.IOException;
@@ -367,12 +368,22 @@ protected void logRequest(String path, String contentType, String method) {
367368

368369
protected void logSecurityUserRequest(String path, String contentType, String method) {
369370
if (logger.isInfoEnabled()) {
370-
String username = manageConfig != null ? manageConfig.getUsername() : "(unknown)";
371371
logger.info(String.format("Sending %s %s request as user '%s' (who must have the 'manage-admin' and 'security' roles) to path: %s",
372-
contentType, method, username, path));
372+
contentType, method, determineUsernameForSecurityUserRequest(), path));
373373
}
374374
}
375375

376+
protected String determineUsernameForSecurityUserRequest() {
377+
String username = "(unknown)";
378+
if (manageConfig != null) {
379+
username = manageConfig.getSecurityUsername();
380+
if (StringUtils.isEmpty(username)) {
381+
username = manageConfig.getUsername();
382+
}
383+
}
384+
return username;
385+
}
386+
376387
public URI buildUri(String path) {
377388
return manageConfig.buildUri(path);
378389
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.marklogic.mgmt;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class ManageClientTest extends Assert {
7+
8+
@Test
9+
public void determineUsernameForSecurityUserRequest() {
10+
ManageConfig config = new ManageConfig();
11+
config.setSecurityUsername("admin");
12+
config.setUsername("someone");
13+
14+
ManageClient client = new ManageClient(config);
15+
assertEquals("admin", client.determineUsernameForSecurityUserRequest());
16+
17+
config.setSecurityUsername(null);
18+
assertEquals("someone", client.determineUsernameForSecurityUserRequest());
19+
}
20+
}

0 commit comments

Comments
 (0)