From c03f8a1acb29473e417ad5350ee91c00b0d96ef0 Mon Sep 17 00:00:00 2001 From: davidjumani Date: Wed, 24 Jun 2020 13:45:57 +0000 Subject: [PATCH] server: Adding listall to listLdapConfigurations (#4164) Adds the listall parameter to listLdapConfigurations. If set to true, and no domainid specified, list all LDAP configurations irrespective of the linked domain --- .../api/command/LdapListConfigurationCmd.java | 8 ++++++ .../cloudstack/ldap/LdapManagerImpl.java | 3 +- .../ldap/dao/LdapConfigurationDao.java | 4 +++ .../ldap/dao/LdapConfigurationDaoImpl.java | 28 +++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java index db6318e6b2c..d12ca4ab6c1 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LdapListConfigurationCmd.java @@ -55,6 +55,10 @@ public class LdapListConfigurationCmd extends BaseListCmd { @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = false, entityType = DomainResponse.class, description = "linked domain") private Long domainId; + @Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to true, " + + " and no domainid specified, list all LDAP configurations irrespective of the linked domain", since = "4.13.2") + private Boolean listAll; + public LdapListConfigurationCmd() { super(); } @@ -117,4 +121,8 @@ public class LdapListConfigurationCmd extends BaseListCmd { public void setDomainId(final Long domainId) { this.domainId = domainId; } + + public boolean listAll() { + return listAll != null && listAll; + } } diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java index 547c10b7b1d..7b1216dbbb6 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java @@ -291,7 +291,8 @@ public class LdapManagerImpl implements LdapManager, LdapValidator { final String hostname = cmd.getHostname(); final int port = cmd.getPort(); final Long domainId = cmd.getDomainId(); - final Pair, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId); + final boolean listAll = cmd.listAll(); + final Pair, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll); return new Pair, Integer>(result.first(), result.second()); } diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDao.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDao.java index e99c78be9b7..6e618ca97e2 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDao.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDao.java @@ -37,5 +37,9 @@ public interface LdapConfigurationDao extends GenericDao, Integer> searchConfigurations(String hostname, int port, Long domainId); + + Pair, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll); } \ No newline at end of file diff --git a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDaoImpl.java b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDaoImpl.java index fa4c0af236f..78c9bae4d0a 100644 --- a/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDaoImpl.java +++ b/plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/dao/LdapConfigurationDaoImpl.java @@ -46,6 +46,7 @@ public class LdapConfigurationDaoImpl extends GenericDaoBase sc = getSearchCriteria(hostname, port, domainId); + SearchCriteria sc = getSearchCriteria(hostname, port, domainId, false); + return findOneBy(sc); + } + + @Override + public LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll) { + SearchCriteria sc = getSearchCriteria(hostname, port, domainId, listAll); return findOneBy(sc); } @Override public Pair, Integer> searchConfigurations(final String hostname, final int port, final Long domainId) { - SearchCriteria sc = getSearchCriteria(hostname, port, domainId); + SearchCriteria sc = getSearchCriteria(hostname, port, domainId, false); return searchAndCount(sc, null); } - private SearchCriteria getSearchCriteria(String hostname, int port, Long domainId) { + @Override + public Pair, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, final boolean listAll) { + SearchCriteria sc = getSearchCriteria(hostname, port, domainId, listAll); + return searchAndCount(sc, null); + } + + private SearchCriteria getSearchCriteria(String hostname, int port, Long domainId,boolean listAll) { SearchCriteria sc; - if (domainId == null) { - sc = listDomainConfigurationsSearch.create(); - } else { + if (domainId != null) { + // If domainid is present, ignore listall sc = listDomainConfigurationsSearch.create(); sc.setParameters("domain_id", domainId); + } else if (listAll) { + sc = listDomainConfigurationsSearch.create(); + } else { + sc = listGlobalConfigurationsSearch.create(); } if (hostname != null) { sc.setParameters("hostname", hostname);