Skip to content

Commit d3b90bb

Browse files
committed
Adding listall to listLdapConfigurations
1 parent 8010718 commit d3b90bb

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public class LdapListConfigurationCmd extends BaseListCmd {
5555
@Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.UUID, required = false, entityType = DomainResponse.class, description = "linked domain")
5656
private Long domainId;
5757

58+
@Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to true, "
59+
+ " and no domainid specified, list all LDAP configurations irrespective of the linked domain", since = "4.13.2")
60+
private Boolean listAll;
61+
5862
public LdapListConfigurationCmd() {
5963
super();
6064
}
@@ -117,4 +121,8 @@ public void setPort(final int port) {
117121
public void setDomainId(final Long domainId) {
118122
this.domainId = domainId;
119123
}
124+
125+
public boolean listAll() {
126+
return listAll != null && listAll;
127+
}
120128
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(fin
291291
final String hostname = cmd.getHostname();
292292
final int port = cmd.getPort();
293293
final Long domainId = cmd.getDomainId();
294-
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId);
294+
final boolean listAll = cmd.listAll();
295+
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll);
295296
return new Pair<List<? extends LdapConfigurationVO>, Integer>(result.first(), result.second());
296297
}
297298

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@ public interface LdapConfigurationDao extends GenericDao<LdapConfigurationVO, Lo
3737

3838
LdapConfigurationVO find(String hostname, int port, Long domainId);
3939

40+
LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll);
41+
4042
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId);
43+
44+
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll);
4145
}

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public LdapConfigurationDaoImpl() {
4646
listGlobalConfigurationsSearch.and("port", listGlobalConfigurationsSearch.entity().getPort(), Op.EQ);
4747
listGlobalConfigurationsSearch.and("domain_id", listGlobalConfigurationsSearch.entity().getDomainId(),SearchCriteria.Op.NULL);
4848
listGlobalConfigurationsSearch.done();
49+
4950
listDomainConfigurationsSearch = createSearchBuilder();
5051
listDomainConfigurationsSearch.and("hostname", listDomainConfigurationsSearch.entity().getHostname(), Op.EQ);
5152
listDomainConfigurationsSearch.and("port", listDomainConfigurationsSearch.entity().getPort(), Op.EQ);
@@ -62,23 +63,44 @@ public LdapConfigurationVO findByHostname(final String hostname) {
6263

6364
@Override
6465
public LdapConfigurationVO find(String hostname, int port, Long domainId) {
65-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId);
66+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
67+
return findOneBy(sc);
68+
}
69+
70+
@Override
71+
public LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll) {
72+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
6673
return findOneBy(sc);
6774
}
6875

6976
@Override
7077
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId) {
71-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId);
78+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
7279
return searchAndCount(sc, null);
7380
}
7481

75-
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId) {
82+
@Override
83+
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId, final boolean listAll) {
84+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
85+
return searchAndCount(sc, null);
86+
}
87+
88+
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId,boolean listAll) {
7689
SearchCriteria<LdapConfigurationVO> sc;
90+
<<<<<<< HEAD
7791
if (domainId == null) {
7892
sc = listDomainConfigurationsSearch.create();
7993
} else {
94+
=======
95+
if (domainId != null) {
96+
// If domainid is present, ignore listall
97+
>>>>>>> 1422ef8cf8... Adding listall to listLdapConfigurations
8098
sc = listDomainConfigurationsSearch.create();
8199
sc.setParameters("domain_id", domainId);
100+
} else if (listAll) {
101+
sc = listDomainConfigurationsSearch.create();
102+
} else {
103+
sc = listGlobalConfigurationsSearch.create();
82104
}
83105
if (hostname != null) {
84106
sc.setParameters("hostname", hostname);

0 commit comments

Comments
 (0)