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

Commit 46734b6

Browse files
authored
Merge pull request #468 from marklogic-community/feature/remove-admin-admin
Removed default "admin" usage
2 parents 1c4bc02 + 207ba08 commit 46734b6

File tree

11 files changed

+79
-33
lines changed

11 files changed

+79
-33
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ public class AppConfig {
6464
private String name = DEFAULT_APP_NAME;
6565

6666
/**
67-
* These are assumed as sensible defaults in a development environment, where teams often use admin/admin for the
68-
* admin login. They are of course expected to change in a real environment.
67+
* @deprecated since 4.5.0; will be removed in 5.0.0
6968
*/
69+
@Deprecated
7070
public static final String DEFAULT_USERNAME = "admin";
71+
72+
/**
73+
* @deprecated since 4.5.0; will be removed in 5.0.0
74+
*/
75+
@Deprecated
7176
public static final String DEFAULT_PASSWORD = "admin";
7277

7378
private String host = DEFAULT_HOST;
@@ -87,8 +92,8 @@ public class AppConfig {
8792
// Connection info for using the client REST API - e.g. to load modules
8893
private DatabaseClient.ConnectionType restConnectionType;
8994
private SecurityContextType restSecurityContextType = SecurityContextType.DIGEST;
90-
private String restAdminUsername = DEFAULT_USERNAME;
91-
private String restAdminPassword = DEFAULT_PASSWORD;
95+
private String restAdminUsername;
96+
private String restAdminPassword;
9297
private SSLContext restSslContext;
9398
private SSLHostnameVerifier restSslHostnameVerifier;
9499
private String restCertFile;
@@ -108,8 +113,8 @@ public class AppConfig {
108113
// Connection info for using the App Services client REST API - e.g. to load non-REST API modules
109114
private DatabaseClient.ConnectionType appServicesConnectionType;
110115
private SecurityContextType appServicesSecurityContextType = SecurityContextType.DIGEST;
111-
private String appServicesUsername = DEFAULT_USERNAME;
112-
private String appServicesPassword = DEFAULT_PASSWORD;
116+
private String appServicesUsername;
117+
private String appServicesPassword;
113118
private Integer appServicesPort = 8000;
114119
private SSLContext appServicesSslContext;
115120
private SSLHostnameVerifier appServicesSslHostnameVerifier;

src/main/java/com/marklogic/appdeployer/impl/AbstractAppDeployer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public abstract class AbstractAppDeployer extends LoggingObject implements AppDe
2626
private List<DeployerListener> deployerListeners;
2727

2828
/**
29-
* Can use this constructor when the default config used by ManageClient and AdminManager will work.
29+
* @deprecated since 4.5.0; avoid using since it assumes the use of default passwords
3030
*/
31+
@Deprecated
3132
public AbstractAppDeployer() {
3233
this(new ManageClient(), new AdminManager());
3334
}

src/main/java/com/marklogic/appdeployer/impl/SimpleAppDeployer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ public class SimpleAppDeployer extends AbstractAppDeployer {
1515

1616
private List<Command> commands;
1717

18+
/**
19+
* @param commandArray
20+
* @deprecated since 4.5.0; avoid using since it assumes the use of default passwords
21+
*/
22+
@Deprecated
1823
public SimpleAppDeployer(Command... commandArray) {
1924
super();
2025
buildModifiableCommandList(commandArray);
2126
}
2227

28+
/**
29+
* @param commands
30+
* @deprecated since 4.5.0; avoid using since it assumes the use of default passwords
31+
*/
32+
@Deprecated
2333
public SimpleAppDeployer(List<Command> commands) {
2434
this.commands = commands;
2535
}

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ public class ManageClient extends LoggingObject {
3030
private RestTemplate securityUserRestTemplate;
3131
private PayloadParser payloadParser;
3232

33-
/**
34-
* Can use this constructor when the default values in ManageConfig will work.
35-
*/
33+
/**
34+
* Creates an uninitialized instance that requires a {@code ManageConfig} to be provided in order to be operable.
35+
*
36+
* @deprecated since 4.5.0; will be removed in 5.0.0
37+
*/
3638
public ManageClient() {
37-
this(new ManageConfig());
3839
}
3940

4041
public ManageClient(ManageConfig config) {
@@ -266,23 +267,27 @@ public HttpEntity<String> buildXmlEntity(String xml) {
266267

267268
protected void logRequest(String path, String contentType, String method) {
268269
if (logger.isInfoEnabled()) {
269-
String username = manageConfig != null ? manageConfig.getUsername() : "(unknown)";
270-
logger.info(String.format("Sending %s %s request as user '%s' to path: %s", contentType, method, username, buildUri(path)));
270+
String username = manageConfig != null ?
271+
String.format("as user '%s' ", manageConfig.getUsername()) : "";
272+
logger.info("Sending {} {} request {}to path: {}", contentType, method, username, buildUri(path));
271273
}
272274
}
273275

274276
protected void logSecurityUserRequest(String path, String contentType, String method) {
275277
if (logger.isInfoEnabled()) {
276-
logger.info(String.format("Sending %s %s request as user '%s' (who should have the 'manage-admin' and 'security' roles) to path: %s",
277-
contentType, method, determineUsernameForSecurityUserRequest(), buildUri(path)));
278+
String username = determineUsernameForSecurityUserRequest();
279+
if (!"".equals(username)) {
280+
username = String.format("as user '%s' (who should have the 'manage-admin' and 'security' roles) ", username);
281+
}
282+
logger.info("Sending {} {} request {}to path: {}", contentType, method, username, buildUri(path));
278283
}
279284
}
280285

281286
protected String determineUsernameForSecurityUserRequest() {
282-
String username = "(unknown)";
287+
String username = "";
283288
if (manageConfig != null) {
284289
username = manageConfig.getSecurityUsername();
285-
if (StringUtils.isEmpty(username)) {
290+
if (!StringUtils.hasText(username)) {
286291
username = manageConfig.getUsername();
287292
}
288293
}

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,37 @@
1616
public class ManageConfig extends RestConfig {
1717

1818
/**
19-
* These are assumed as sensible defaults in a development environment, where teams often use admin/admin for the
20-
* admin login. They are of course expected to change in a real environment.
19+
* @deprecated since 4.5.0; will be removed in 5.0.0
2120
*/
21+
@Deprecated
2222
public static final String DEFAULT_USERNAME = "admin";
23+
24+
/**
25+
* @deprecated since 4.5.0; will be removed in 5.0.0
26+
*/
27+
@Deprecated
2328
public static final String DEFAULT_PASSWORD = "admin";
2429

2530
private String securityUsername;
2631
private String securityPassword;
2732
private SSLContext securitySslContext;
2833
private boolean cleanJsonPayloads = false;
2934

35+
/**
36+
* Assumes the use of "localhost" and 8002 as the host and port.
37+
*/
3038
public ManageConfig() {
31-
this("localhost", DEFAULT_PASSWORD);
39+
this("localhost", null);
3240
}
3341

42+
/**
43+
* Assumes the use of 8002 as the port.
44+
*
45+
* @param host
46+
* @param password
47+
*/
3448
public ManageConfig(String host, String password) {
35-
super(host, 8002, DEFAULT_USERNAME, password);
49+
super(host, 8002, null, password);
3650
}
3751

3852
public ManageConfig(String host, int port, String username, String password) {

src/main/java/com/marklogic/mgmt/admin/AdminConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88
*/
99
public class AdminConfig extends RestConfig {
1010

11+
/**
12+
* Assumes the usage of "localhost" and 8001 as the host and port.
13+
*/
1114
public AdminConfig() {
12-
super("localhost", 8001, "admin", "admin");
15+
super("localhost", 8001, null, null);
1316
}
1417

1518
public AdminConfig(String host, String password) {
16-
super(host, 8001, "admin", password);
19+
super(host, 8001, null, password);
1720
}
1821

1922
public AdminConfig(String host, int port, String username, String password) {

src/main/java/com/marklogic/mgmt/admin/AdminManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public class AdminManager extends AbstractManager {
2121
private RestTemplate restTemplate;
2222
private AdminConfig adminConfig;
2323

24-
/**
25-
* Can use this constructor when the default values in AdminConfig will work.
26-
*/
24+
/**
25+
* Creates an uninitialized instance that requires a {@code AdminConfig} to be provided in order to be operable.
26+
*
27+
* @deprecated since 4.5.0; will be removed in 5.0.0
28+
*/
2729
public AdminManager() {
28-
this(new AdminConfig());
2930
}
3031

3132
public AdminManager(AdminConfig adminConfig) {

src/test/java/com/marklogic/appdeployer/DefaultAppConfigFactoryTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ public void unrecognizedProperties() {
137137
sut = new DefaultAppConfigFactory(new SimplePropertySource("foo.mlHost", "host", "foo.mlUsername", "user"));
138138
AppConfig config = sut.newAppConfig();
139139
assertEquals("localhost", config.getHost(), "Should use default");
140-
assertEquals(AppConfig.DEFAULT_USERNAME, config.getRestAdminUsername(), "Should use default");
141140
}
142141

143142
@Test

src/test/java/com/marklogic/appdeployer/impl/SimpleAppDeployerTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;
55
import com.marklogic.appdeployer.command.security.DeployUsersCommand;
66
import static org.junit.jupiter.api.Assertions.*;
7+
8+
import com.marklogic.mgmt.AbstractMgmtTest;
79
import org.junit.jupiter.api.BeforeEach;
810
import org.junit.jupiter.api.Test;
911

1012
import java.util.Arrays;
1113

12-
public class SimpleAppDeployerTest {
14+
public class SimpleAppDeployerTest extends AbstractMgmtTest {
1315

1416
private SimpleAppDeployer deployer;
1517
private DeployRestApiServersCommand restApiCommand;
@@ -19,7 +21,7 @@ public class SimpleAppDeployerTest {
1921
public void setup() {
2022
restApiCommand = new DeployRestApiServersCommand();
2123
dbCommand = new DeployOtherDatabasesCommand();
22-
deployer = new SimpleAppDeployer(restApiCommand, dbCommand);
24+
deployer = new SimpleAppDeployer(manageClient, null, restApiCommand, dbCommand);
2325
}
2426

2527
@Test
@@ -52,7 +54,7 @@ void constructWithList() {
5254

5355
@Test
5456
void constructWithArray() {
55-
deployer = new SimpleAppDeployer(new DeployOtherDatabasesCommand());
57+
deployer = new SimpleAppDeployer(manageClient, null, new DeployOtherDatabasesCommand());
5658
assertEquals(1, deployer.getCommands().size());
5759
}
5860
}

src/test/java/com/marklogic/mgmt/ManageClientTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ public class ManageClientTest {
77

88
@Test
99
public void determineUsernameForSecurityUserRequest() {
10-
ManageConfig config = new ManageConfig();
10+
ManageConfig config = new ManageConfig("localhost", 8002, "someone", "someword");
1111
config.setSecurityUsername("admin");
1212
config.setSecurityPassword("admin");
13-
config.setUsername("someone");
1413

1514
ManageClient client = new ManageClient(config);
1615
assertEquals("admin", client.determineUsernameForSecurityUserRequest());

0 commit comments

Comments
 (0)