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

Commit b7a77dc

Browse files
authored
Merge pull request #470 from marklogic-community/feature/189-mlAuth
DEVEXP-189: Added mlAuthentication and mlSslHostnameVerifier
2 parents a9ffe83 + acd60b7 commit b7a77dc

File tree

6 files changed

+157
-2
lines changed

6 files changed

+157
-2
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public void initialize() {
309309
config.setRestConnectionType(DatabaseClient.ConnectionType.valueOf(prop));
310310
});
311311
propertyConsumerMap.put("mlRestAuthentication", (config, prop) -> {
312-
logger.info("App REST authentication: " + prop);
312+
logger.info("REST authentication: " + prop);
313313
config.setRestSecurityContextType(SecurityContextType.valueOf(prop.toUpperCase()));
314314
});
315315
propertyConsumerMap.put("mlRestCertFile", (config, prop) -> {
@@ -335,6 +335,29 @@ public void initialize() {
335335
config.setTestRestBasePath(prop);
336336
});
337337

338+
// Need this to be after mlRestAuthentication and mlAppServicesAuthentication are processed so
339+
// that it doesn't override those values.
340+
propertyConsumerMap.put("mlAuthentication", (config, prop) -> {
341+
if (!propertyExists("mlAppServicesAuthentication")) {
342+
logger.info("App Services authentication: " + prop);
343+
config.setAppServicesSecurityContextType(SecurityContextType.valueOf(prop.toUpperCase()));
344+
}
345+
if (!propertyExists("mlRestAuthentication")) {
346+
logger.info("REST authentication: " + prop);
347+
config.setRestSecurityContextType(SecurityContextType.valueOf(prop.toUpperCase()));
348+
}
349+
});
350+
propertyConsumerMap.put("mlSslHostnameVerifier", (config, prop) -> {
351+
if (!propertyExists("mlAppServicesSslHostnameVerifier")) {
352+
logger.info("App-Services SSL hostname verifier: " + prop);
353+
config.setAppServicesSslHostnameVerifier(JavaClientUtil.toSSLHostnameVerifier(prop));
354+
}
355+
if (!propertyExists("mlRestSslHostnameVerifier")) {
356+
logger.info("REST SSL hostname verifier: " + prop);
357+
config.setRestSslHostnameVerifier(JavaClientUtil.toSSLHostnameVerifier(prop));
358+
}
359+
});
360+
338361
/**
339362
* When modules are loaded via the Client REST API, if the app server requires an SSL connection, then
340363
* setting this property will force the simplest SSL connection to be created.

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ public void initialize() {
4949
config.setSecurityContextType(prop);
5050
});
5151

52-
propertyConsumerMap.put("mlManageUsername", (config, prop) -> {
52+
propertyConsumerMap.put("mlAuthentication", (config, prop) -> {
53+
if (!propertyExists("mlManageAuthentication")) {
54+
logger.info("Manage authentication: " + prop);
55+
config.setSecurityContextType(prop);
56+
}
57+
});
58+
59+
propertyConsumerMap.put("mlManageUsername", (config, prop) -> {
5360
logger.info("Manage username: " + prop);
5461
config.setUsername(prop);
5562
});
@@ -117,6 +124,12 @@ public void initialize() {
117124
logger.info("Manage SSL hostname verifier: " + prop);
118125
config.setSslHostnameVerifier(JavaClientUtil.toSSLHostnameVerifier(prop));
119126
});
127+
propertyConsumerMap.put("mlSslHostnameVerifier", (config, prop) -> {
128+
if (!propertyExists("mlManageSslHostnameVerifier")) {
129+
logger.info("Manage SSL hostname verifier: " + prop);
130+
config.setSslHostnameVerifier(JavaClientUtil.toSSLHostnameVerifier(prop));
131+
}
132+
});
120133

121134
propertyConsumerMap.put("mlManageUseDefaultKeystore", (config, prop) -> {
122135
logger.info("Using default JVM keystore for SSL for Manage app server: " + prop);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ public void initialize() {
4848
config.setSecurityContextType(prop);
4949
});
5050

51+
propertyConsumerMap.put("mlAuthentication", (config, prop) -> {
52+
if (!propertyExists("mlAdminAuthentication")) {
53+
logger.info("Admin authentication: " + prop);
54+
config.setSecurityContextType(prop);
55+
}
56+
});
57+
5158
/**
5259
* The Manage API endpoints in the Admin interface still just require the manage-admin role, so the value of
5360
* mlManageUsername should work for these calls.
@@ -113,6 +120,12 @@ public void initialize() {
113120
logger.info("Admin SSL hostname verifier: " + prop);
114121
config.setSslHostnameVerifier(JavaClientUtil.toSSLHostnameVerifier(prop));
115122
});
123+
propertyConsumerMap.put("mlSslHostnameVerifier", (config, prop) -> {
124+
if (!propertyExists("mlAdminSslHostnameVerifier")) {
125+
logger.info("Admin SSL hostname verifier: " + prop);
126+
config.setSslHostnameVerifier(JavaClientUtil.toSSLHostnameVerifier(prop));
127+
}
128+
});
116129

117130
propertyConsumerMap.put("mlAdminUseDefaultKeystore", (config, prop) -> {
118131
logger.info("Using default JVM keystore for SSL for Admin app server: " + prop);

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,32 @@ void sslHostnameVerifier() {
696696
ex.getMessage());
697697
}
698698

699+
@Test
700+
void mlSslHostnameVerifier() {
701+
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
702+
"mlSslHostnameVerifier", "ANY"
703+
)).newAppConfig();
704+
705+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getRestSslHostnameVerifier());
706+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getAppServicesSslHostnameVerifier());
707+
708+
config = new DefaultAppConfigFactory(new SimplePropertySource(
709+
"mlSslHostnameVerifier", "ANY",
710+
"mlRestSslHostnameVerifier", "STRICT"
711+
)).newAppConfig();
712+
713+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.STRICT, config.getRestSslHostnameVerifier());
714+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getAppServicesSslHostnameVerifier());
715+
716+
config = new DefaultAppConfigFactory(new SimplePropertySource(
717+
"mlSslHostnameVerifier", "ANY",
718+
"mlAppServicesSslHostnameVerifier", "STRICT"
719+
)).newAppConfig();
720+
721+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getRestSslHostnameVerifier());
722+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.STRICT, config.getAppServicesSslHostnameVerifier());
723+
}
724+
699725
@Test
700726
void samlTokens() {
701727
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
@@ -720,4 +746,36 @@ void samlTokens() {
720746
assertTrue(context instanceof DatabaseClientFactory.SAMLAuthContext);
721747
assertEquals("my-app-token", ((DatabaseClientFactory.SAMLAuthContext) context).getToken());
722748
}
749+
750+
@Test
751+
void mlAuthentication() {
752+
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
753+
"mlAuthentication", "cloud"
754+
)).newAppConfig();
755+
756+
assertEquals(SecurityContextType.CLOUD, config.getRestSecurityContextType());
757+
assertEquals(SecurityContextType.CLOUD, config.getAppServicesSecurityContextType());
758+
}
759+
760+
@Test
761+
void mlAuthenticationAndRestOverridden() {
762+
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
763+
"mlAuthentication", "cloud",
764+
"mlRestAuthentication", "basic"
765+
)).newAppConfig();
766+
767+
assertEquals(SecurityContextType.BASIC, config.getRestSecurityContextType());
768+
assertEquals(SecurityContextType.CLOUD, config.getAppServicesSecurityContextType());
769+
}
770+
771+
@Test
772+
void mlAuthenticationAndAppServicesOverridden() {
773+
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
774+
"mlAuthentication", "cloud",
775+
"mlAppServicesAuthentication", "saml"
776+
)).newAppConfig();
777+
778+
assertEquals(SecurityContextType.CLOUD, config.getRestSecurityContextType());
779+
assertEquals(SecurityContextType.SAML, config.getAppServicesSecurityContextType());
780+
}
723781
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,30 @@ void sslHostnameVerifier() {
180180
assertThrows(IllegalArgumentException.class, () -> configure("mlManageSslHostnameVerifier", "bogus"));
181181
}
182182

183+
@Test
184+
void mlSslHostnameVerifier() {
185+
ManageConfig config = configure("mlSslHostnameVerifier", "any");
186+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getSslHostnameVerifier());
187+
188+
config = configure(
189+
"mlSslHostnameVerifier", "any",
190+
"mlManageSslHostnameVerifier", "strict"
191+
);
192+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.STRICT, config.getSslHostnameVerifier());
193+
}
194+
195+
@Test
196+
void mlAuthentication() {
197+
ManageConfig config = configure("mlAuthentication", "cloud");
198+
assertEquals("cloud", config.getSecurityContextType());
199+
200+
config = configure(
201+
"mlAuthentication", "cloud",
202+
"mlManageAuthentication", "basic"
203+
);
204+
assertEquals("basic", config.getSecurityContextType());
205+
}
206+
183207
private ManageConfig configure(String... properties) {
184208
return new DefaultManageConfigFactory(new SimplePropertySource(properties)).newManageConfig();
185209
}

src/test/java/com/marklogic/mgmt/admin/DefaultAdminConfigFactoryTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ void sslHostnameVerifier() {
139139
assertThrows(IllegalArgumentException.class, () -> configure("mlAdminSslHostnameVerifier", "bogus"));
140140
}
141141

142+
@Test
143+
void mlSslHostnameVerifier() {
144+
AdminConfig config = configure("mlSslHostnameVerifier", "any");
145+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.ANY, config.getSslHostnameVerifier());
146+
147+
config = configure(
148+
"mlSslHostnameVerifier", "any",
149+
"mlAdminSslHostnameVerifier", "strict"
150+
);
151+
assertEquals(DatabaseClientFactory.SSLHostnameVerifier.STRICT, config.getSslHostnameVerifier());
152+
}
153+
154+
@Test
155+
void mlAuthentication() {
156+
AdminConfig config = configure("mlAuthentication", "cloud");
157+
assertEquals("cloud", config.getSecurityContextType());
158+
159+
config = configure(
160+
"mlAuthentication", "cloud",
161+
"mlAdminAuthentication", "basic"
162+
);
163+
assertEquals("basic", config.getSecurityContextType());
164+
}
165+
142166
private AdminConfig configure(String... properties) {
143167
return new DefaultAdminConfigFactory(new SimplePropertySource(properties)).newAdminConfig();
144168
}

0 commit comments

Comments
 (0)