Skip to content

Commit c24d2b8

Browse files
authored
LDAP: honour nested groups for MSAD (#11696)
1 parent 96992d3 commit c24d2b8

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ protected boolean isUserDisabled(SearchResult result) throws NamingException {
9393
}
9494

9595
protected String getMemberOfAttribute(final Long domainId) {
96+
String rc;
9697
if(_ldapConfiguration.isNestedGroupsEnabled(domainId)) {
97-
return MICROSOFT_AD_NESTED_MEMBERS_FILTER;
98+
rc = MICROSOFT_AD_NESTED_MEMBERS_FILTER;
9899
} else {
99-
return MICROSOFT_AD_MEMBERS_FILTER;
100+
rc = MICROSOFT_AD_MEMBERS_FILTER;
100101
}
102+
logger.trace("using memberOf filter = {} for domain with id {}", rc, domainId);
103+
104+
return rc;
101105
}
102106
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727

2828
import com.cloud.utils.Pair;
2929
import org.apache.cloudstack.ldap.dao.LdapConfigurationDao;
30+
import org.apache.logging.log4j.LogManager;
31+
import org.apache.logging.log4j.Logger;
3032

3133
public class LdapConfiguration implements Configurable{
3234
private final static String factory = "com.sun.jndi.ldap.LdapCtxFactory";
35+
protected Logger logger = LogManager.getLogger(getClass());
3336

3437
private static final ConfigKey<Long> ldapReadTimeout = new ConfigKey<Long>(
3538
Long.class,
@@ -325,7 +328,7 @@ public LdapUserManager.Provider getLdapProvider(final Long domainId) {
325328
try {
326329
provider = LdapUserManager.Provider.valueOf(ldapProvider.valueIn(domainId).toUpperCase());
327330
} catch (IllegalArgumentException ex) {
328-
//openldap is the default
331+
logger.warn("no LDAP provider found for domain {}, using openldap as default", domainId);
329332
provider = LdapUserManager.Provider.OPENLDAP;
330333
}
331334
return provider;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected LdapUser createUser(final SearchResult result, Long domainId) throws N
6363
final String firstname = LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getFirstnameAttribute(domainId));
6464
final String lastname = LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getLastnameAttribute(domainId));
6565
final String principal = result.getNameInNamespace();
66-
final List<String> memberships = LdapUtils.getAttributeValues(attributes, _ldapConfiguration.getUserMemberOfAttribute(domainId));
66+
final List<String> memberships = LdapUtils.getAttributeValues(attributes, getMemberOfAttribute(domainId));
6767

6868
String domain = principal.replace("cn=" + LdapUtils.getAttributeValue(attributes, _ldapConfiguration.getCommonNameAttribute()) + ",", "");
6969
domain = domain.replace("," + _ldapConfiguration.getBaseDn(domainId), "");
@@ -87,7 +87,7 @@ private String generateSearchFilter(final String username, Long domainId) {
8787
usernameFilter.append((username == null ? "*" : LdapUtils.escapeLDAPSearchFilter(username)));
8888
usernameFilter.append(")");
8989

90-
String memberOfAttribute = _ldapConfiguration.getUserMemberOfAttribute(domainId);
90+
String memberOfAttribute = getMemberOfAttribute(domainId);
9191
StringBuilder ldapGroupsFilter = new StringBuilder();
9292
// this should get the trustmaps for this domain
9393
List<String> ldapGroups = getMappedLdapGroups(domainId);

0 commit comments

Comments
 (0)