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

Commit 5d1e6cc

Browse files
authored
Merge pull request #466 from marklogic-community/feature/173-saml
DEVEXP-173: Added support for SAML authentication
2 parents 03f9360 + 329068b commit 5d1e6cc

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class AppConfig {
9494
private String restCertFile;
9595
private String restCertPassword;
9696
private String restExternalName;
97+
private String restSamlToken;
9798
private X509TrustManager restTrustManager;
9899
private boolean restUseDefaultKeystore;
99100
private String restSslProtocol;
@@ -115,6 +116,7 @@ public class AppConfig {
115116
private String appServicesCertFile;
116117
private String appServicesCertPassword;
117118
private String appServicesExternalName;
119+
private String appServicesSamlToken;
118120
private X509TrustManager appServicesTrustManager;
119121
private boolean appServicesUseDefaultKeystore;
120122
private String appServicesSslProtocol;
@@ -384,6 +386,7 @@ public DatabaseClientConfig newRestDatabaseClientConfig(int port) {
384386
config.setCertPassword(restCertPassword);
385387
config.setConnectionType(restConnectionType);
386388
config.setExternalName(restExternalName);
389+
config.setSamlToken(restSamlToken);
387390
config.setSecurityContextType(restSecurityContextType);
388391
config.setCloudApiKey(cloudApiKey);
389392
config.setBasePath(restBasePath);
@@ -426,6 +429,7 @@ public DatabaseClient newAppServicesDatabaseClient(String databaseName) {
426429
config.setConnectionType(appServicesConnectionType);
427430
config.setDatabase(databaseName);
428431
config.setExternalName(appServicesExternalName);
432+
config.setSamlToken(appServicesSamlToken);
429433
config.setSecurityContextType(appServicesSecurityContextType);
430434
config.setCloudApiKey(cloudApiKey);
431435
config.setBasePath(appServicesBasePath);
@@ -1495,4 +1499,20 @@ public String getTestRestBasePath() {
14951499
public void setTestRestBasePath(String testRestBasePath) {
14961500
this.testRestBasePath = testRestBasePath;
14971501
}
1502+
1503+
public String getRestSamlToken() {
1504+
return restSamlToken;
1505+
}
1506+
1507+
public void setRestSamlToken(String restSamlToken) {
1508+
this.restSamlToken = restSamlToken;
1509+
}
1510+
1511+
public String getAppServicesSamlToken() {
1512+
return appServicesSamlToken;
1513+
}
1514+
1515+
public void setAppServicesSamlToken(String appServicesSamlToken) {
1516+
this.appServicesSamlToken = appServicesSamlToken;
1517+
}
14981518
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ public void initialize() {
227227
logger.info("App Services external name: " + prop);
228228
config.setAppServicesExternalName(prop);
229229
});
230+
propertyConsumerMap.put("mlAppServicesSamlToken", (config, prop) -> {
231+
logger.info("App Services SAML token: " + prop);
232+
config.setAppServicesSamlToken(prop);
233+
});
230234

231235
propertyConsumerMap.put("mlAppServicesSimpleSsl", (config, prop) -> {
232236
if (StringUtils.hasText(prop) && !"false".equalsIgnoreCase(prop)) {
@@ -314,6 +318,10 @@ public void initialize() {
314318
logger.info("REST external name: " + prop);
315319
config.setRestExternalName(prop);
316320
});
321+
propertyConsumerMap.put("mlRestSamlToken", (config, prop) -> {
322+
logger.info("REST SAML token: " + prop);
323+
config.setRestSamlToken(prop);
324+
});
317325
propertyConsumerMap.put("mlRestBasePath", (config, prop) -> {
318326
logger.info("REST base path: " + prop);
319327
config.setRestBasePath(prop);

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.marklogic.client.ext.SecurityContextType;
66
import com.marklogic.client.ext.modulesloader.impl.PropertiesModuleManager;
77
import com.marklogic.mgmt.util.SimplePropertySource;
8-
import static org.junit.jupiter.api.Assertions.*;
98
import org.junit.jupiter.api.Test;
109

1110
import java.io.File;
@@ -14,7 +13,14 @@
1413
import java.util.Properties;
1514
import java.util.Set;
1615

17-
public class DefaultAppConfigFactoryTest {
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertFalse;
18+
import static org.junit.jupiter.api.Assertions.assertNotNull;
19+
import static org.junit.jupiter.api.Assertions.assertNull;
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.fail;
22+
23+
public class DefaultAppConfigFactoryTest {
1824

1925
private DefaultAppConfigFactory sut;
2026

@@ -663,4 +669,29 @@ void cloudApiKeyAndBasePath() {
663669
assertEquals("/app/path", config.getAppServicesBasePath());
664670
assertEquals("/test/path", config.getTestRestBasePath());
665671
}
672+
673+
@Test
674+
void samlTokens() {
675+
AppConfig config = new DefaultAppConfigFactory(new SimplePropertySource(
676+
"mlRestAuthentication", "saml",
677+
"mlRestSamlToken", "my-rest-token",
678+
"mlAppServicesAuthentication", "saml",
679+
"mlAppServicesSamlToken", "my-app-token"
680+
)).newAppConfig();
681+
682+
assertEquals(SecurityContextType.SAML, config.getRestSecurityContextType());
683+
assertEquals("my-rest-token", config.getRestSamlToken());
684+
assertEquals(SecurityContextType.SAML, config.getAppServicesSecurityContextType());
685+
assertEquals("my-app-token", config.getAppServicesSamlToken());
686+
687+
// It's possible to create a client with a SAML token, as no attempt is made by the Java Client to verify or
688+
// use the token. So we can verify that the client is created correctly.
689+
DatabaseClientFactory.SecurityContext context = config.newDatabaseClient().getSecurityContext();
690+
assertTrue(context instanceof DatabaseClientFactory.SAMLAuthContext);
691+
assertEquals("my-rest-token", ((DatabaseClientFactory.SAMLAuthContext) context).getToken());
692+
693+
context = config.newAppServicesDatabaseClient("Documents").getSecurityContext();
694+
assertTrue(context instanceof DatabaseClientFactory.SAMLAuthContext);
695+
assertEquals("my-app-token", ((DatabaseClientFactory.SAMLAuthContext) context).getToken());
696+
}
666697
}

0 commit comments

Comments
 (0)