This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.13
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.13 by this push:
new c03f8a1 server: Adding listall to listLdapConfigurations (#4164)
c03f8a1 is described below
commit c03f8a1acb29473e417ad5350ee91c00b0d96ef0
Author: davidjumani <[email protected]>
AuthorDate: Wed Jun 24 13:45:57 2020 +0000
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 +++++++
.../apache/cloudstack/ldap/LdapManagerImpl.java | 3 ++-
.../cloudstack/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 db6318e..d12ca4a 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 547c10b..7b1216d 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<List<LdapConfigurationVO>, Integer> result =
_ldapConfigurationDao.searchConfigurations(hostname, port, domainId);
+ final boolean listAll = cmd.listAll();
+ final Pair<List<LdapConfigurationVO>, Integer> result =
_ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll);
return new Pair<List<? extends LdapConfigurationVO>,
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 e99c78b..6e618ca 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<LdapConfigurationVO, Lo
LdapConfigurationVO find(String hostname, int port, Long domainId);
+ LdapConfigurationVO find(String hostname, int port, Long domainId, boolean
listAll);
+
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String
hostname, int port, Long domainId);
+
+ Pair<List<LdapConfigurationVO>, 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 fa4c0af..78c9bae 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<LdapConfigurationVO
listGlobalConfigurationsSearch.and("port",
listGlobalConfigurationsSearch.entity().getPort(), Op.EQ);
listGlobalConfigurationsSearch.and("domain_id",
listGlobalConfigurationsSearch.entity().getDomainId(),SearchCriteria.Op.NULL);
listGlobalConfigurationsSearch.done();
+
listDomainConfigurationsSearch = createSearchBuilder();
listDomainConfigurationsSearch.and("hostname",
listDomainConfigurationsSearch.entity().getHostname(), Op.EQ);
listDomainConfigurationsSearch.and("port",
listDomainConfigurationsSearch.entity().getPort(), Op.EQ);
@@ -62,23 +63,38 @@ public class LdapConfigurationDaoImpl extends
GenericDaoBase<LdapConfigurationVO
@Override
public LdapConfigurationVO find(String hostname, int port, Long domainId) {
- SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname,
port, domainId);
+ SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname,
port, domainId, false);
+ return findOneBy(sc);
+ }
+
+ @Override
+ public LdapConfigurationVO find(String hostname, int port, Long domainId,
boolean listAll) {
+ SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname,
port, domainId, listAll);
return findOneBy(sc);
}
@Override
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final
String hostname, final int port, final Long domainId) {
- SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname,
port, domainId);
+ SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname,
port, domainId, false);
return searchAndCount(sc, null);
}
- private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String
hostname, int port, Long domainId) {
+ @Override
+ public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final
String hostname, final int port, final Long domainId, final boolean listAll) {
+ SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname,
port, domainId, listAll);
+ return searchAndCount(sc, null);
+ }
+
+ private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String
hostname, int port, Long domainId,boolean listAll) {
SearchCriteria<LdapConfigurationVO> 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);