Skip to content

Commit e06a66b

Browse files
DaanHooglandDaan Hoogland
andauthored
ldap: truststore per domain (#5816)
Co-authored-by: Daan Hoogland <dahn@onecht.net>
1 parent 4392cc4 commit e06a66b

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPConfigCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
189189
List<LDAPConfigResponse> responses = new ArrayList<LDAPConfigResponse>();
190190

191191
if (result.second() > 0) {
192-
boolean useSSlConfig = _ldapConfiguration.getSSLStatus();
192+
boolean useSSlConfig = _ldapConfiguration.getSSLStatus(null);
193193
String searchBaseConfig = _ldapConfiguration.getBaseDn(null);
194194
String bindDnConfig = _ldapConfiguration.getBindPrincipal(null);
195195
for (LdapConfigurationVO ldapConfigurationVO : result.first()) {

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapConfiguration.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public String getLastnameAttribute(final Long domainId) {
238238
}
239239

240240
public String getProviderUrl(final Long domainId) {
241-
final String protocol = getSSLStatus() == true ? "ldaps://" : "ldap://";
241+
final String protocol = getSSLStatus(domainId) == true ? "ldaps://" : "ldap://";
242242
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(null, 0, domainId);
243243
final StringBuilder providerUrls = new StringBuilder();
244244
String delim = "";
@@ -270,20 +270,20 @@ public String getSearchGroupPrinciple(final Long domainId) {
270270
return ldapSearchGroupPrinciple.valueIn(domainId);
271271
}
272272

273-
public boolean getSSLStatus() {
273+
public boolean getSSLStatus(Long domainId) {
274274
boolean sslStatus = false;
275-
if (getTrustStore() != null && getTrustStorePassword() != null) {
275+
if (getTrustStore(domainId) != null && getTrustStorePassword(domainId) != null) {
276276
sslStatus = true;
277277
}
278278
return sslStatus;
279279
}
280280

281-
public String getTrustStore() {
282-
return ldapTrustStore.value();
281+
public String getTrustStore(Long domainId) {
282+
return ldapTrustStore.valueIn(domainId);
283283
}
284284

285-
public String getTrustStorePassword() {
286-
return ldapTrustStorePassword.value();
285+
public String getTrustStorePassword(Long domainId) {
286+
return ldapTrustStorePassword.valueIn(domainId);
287287
}
288288

289289
public String getUsernameAttribute(final Long domainId) {

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ public LdapContext createUserContext(final String principal, final String passwo
6666
return createInitialDirContext(principal, password, false, domainId);
6767
}
6868

69-
private void enableSSL(final Hashtable<String, String> environment) {
70-
final boolean sslStatus = _ldapConfiguration.getSSLStatus();
69+
private void enableSSL(final Hashtable<String, String> environment, Long domainId) {
70+
final boolean sslStatus = _ldapConfiguration.getSSLStatus(domainId);
7171

7272
if (sslStatus) {
7373
s_logger.info("LDAP SSL enabled.");
7474
environment.put(Context.SECURITY_PROTOCOL, "ssl");
75-
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore());
76-
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword());
75+
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore(domainId));
76+
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword(domainId));
7777
}
7878
}
7979

@@ -92,7 +92,7 @@ private Hashtable<String, String> getEnvironment(final String principal, final S
9292
environment.put("com.sun.jndi.ldap.read.timeout", _ldapConfiguration.getReadTimeout(domainId).toString());
9393
environment.put("com.sun.jndi.ldap.connect.pool", "true");
9494

95-
enableSSL(environment);
95+
enableSSL(environment, domainId);
9696
setAuthentication(environment, isSystemContext, domainId);
9797

9898
if (principal != null) {

plugins/user-authenticators/ldap/src/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class LdapContextFactorySpec extends spock.lang.Specification {
4949
ldapConfiguration.getFirstnameAttribute() >> "givenname"
5050
ldapConfiguration.getLastnameAttribute() >> "sn"
5151
ldapConfiguration.getBaseDn(_) >> "dc=cloudstack,dc=org"
52-
ldapConfiguration.getSSLStatus() >> true
53-
ldapConfiguration.getTrustStore() >> "/tmp/ldap.ts"
54-
ldapConfiguration.getTrustStorePassword() >> "password"
52+
ldapConfiguration.getSSLStatus(domainId) >> true
53+
ldapConfiguration.getTrustStore(domainId) >> "/tmp/ldap.ts"
54+
ldapConfiguration.getTrustStorePassword(domainId) >> "password"
5555
ldapConfiguration.getReadTimeout(_) >> 1000
5656
ldapConfiguration.getLdapPageSize() >> 1
5757

plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void overrideConfigValue(LdapConfiguration ldapConfiguration, final Stri
7878
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStore", "/tmp/ldap.ts");
7979
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStorePassword", "password");
8080

81-
assertTrue("A request is made to get the status of SSL should result in true", ldapConfiguration.getSSLStatus());
81+
assertTrue("A request is made to get the status of SSL should result in true", ldapConfiguration.getSSLStatus(null));
8282
}
8383

8484
@Test public void getSearchGroupPrincipleReturnsSuccessfully() throws Exception {
@@ -93,7 +93,7 @@ private void overrideConfigValue(LdapConfiguration ldapConfiguration, final Stri
9393
// We have a ConfigDao with a value for truststore password
9494
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStorePassword", "password");
9595

96-
String result = ldapConfiguration.getTrustStorePassword();
96+
String result = ldapConfiguration.getTrustStorePassword(null);
9797

9898
assertEquals("The result is password", "password", result);
9999
}

0 commit comments

Comments
 (0)