Skip to content

Commit 5558fe0

Browse files
committed
Add ID param to list ldapConf API & delete ldapConf API
1 parent 5f59a02 commit 5558fe0

File tree

9 files changed

+51
-22
lines changed

9 files changed

+51
-22
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public class LdapDeleteConfigurationCmd extends BaseCmd {
4040
@Inject
4141
private LdapManager _ldapManager;
4242

43+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = false, entityType = LdapConfigurationResponse.class, description = "ID of the LDAP configuration")
44+
private Long id;
4345

44-
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, required = true, description = "Hostname")
46+
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, description = "Hostname")
4547
private String hostname;
4648

4749
@Parameter(name = ApiConstants.PORT, type = CommandType.INTEGER, required = false, description = "port")
@@ -71,6 +73,10 @@ public Long getDomainId() {
7173
return domainId;
7274
}
7375

76+
public Long getId() {
77+
return id;
78+
}
79+
7480
@Override
7581
public void execute() throws ServerApiException {
7682
try {

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

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

56+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = LdapConfigurationResponse.class, description = "list ldap configuration by ID")
57+
private Long id;
58+
5659
@Parameter(name = ApiConstants.LIST_ALL, type = CommandType.BOOLEAN, description = "If set to true, "
5760
+ " and no domainid specified, list all LDAP configurations irrespective of the linked domain", since = "4.13.2")
5861
private Boolean listAll;
@@ -120,6 +123,10 @@ public void setDomainId(final Long domainId) {
120123
this.domainId = domainId;
121124
}
122125

126+
public Long getId() {
127+
return id;
128+
}
129+
123130
public boolean listAll() {
124131
return listAll != null && listAll;
125132
}

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/response/LdapConfigurationResponse.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323

2424
import com.cloud.serializer.Param;
2525
import org.apache.cloudstack.api.EntityReference;
26-
import org.apache.cloudstack.ldap.LdapConfiguration;
26+
import org.apache.cloudstack.ldap.LdapConfigurationVO;
2727

28-
@EntityReference(value = LdapConfiguration.class)
28+
@EntityReference(value = LdapConfigurationVO.class)
2929
public class LdapConfigurationResponse extends BaseResponse {
3030
@SerializedName("id")
3131
@Param(description = "the ID of the LDAP configuration")

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@
2323
import javax.persistence.Id;
2424
import javax.persistence.Table;
2525

26+
import org.apache.cloudstack.api.Identity;
2627
import org.apache.cloudstack.api.InternalIdentity;
2728

2829
import java.util.UUID;
2930

3031
@Entity
3132
@Table(name = "ldap_configuration")
32-
public class LdapConfigurationVO implements InternalIdentity {
33-
@Column(name = "hostname")
34-
private String hostname;
35-
33+
public class LdapConfigurationVO implements Identity, InternalIdentity {
3634
@Id
3735
@GeneratedValue(strategy = GenerationType.IDENTITY)
3836
@Column(name = "id")
3937
private Long id;
4038

39+
@Column(name = "hostname")
40+
private String hostname;
41+
4142
@Column(name = "uuid")
4243
private String uuid;
4344

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.apache.cloudstack.ldap.dao.LdapConfigurationDao;
5353
import org.apache.cloudstack.ldap.dao.LdapTrustMapDao;
5454
import org.apache.commons.lang.Validate;
55+
import org.apache.commons.lang3.StringUtils;
5556
import org.springframework.stereotype.Component;
5657

5758
import com.cloud.domain.DomainVO;
@@ -257,6 +258,19 @@ public LdapUserResponse createLdapUserResponse(final LdapUser user) {
257258

258259
@Override
259260
public LdapConfigurationResponse deleteConfiguration(final LdapDeleteConfigurationCmd cmd) throws InvalidParameterValueException {
261+
Long id = cmd.getId();
262+
String hostname = cmd.getHostname();
263+
if (id == null && StringUtils.isEmpty(hostname)) {
264+
throw new InvalidParameterValueException("Either id or hostname must be specified");
265+
}
266+
if (id != null) {
267+
final LdapConfigurationVO config = _ldapConfigurationDao.findById(cmd.getId());
268+
if (config != null) {
269+
_ldapConfigurationDao.remove(config.getId());
270+
return createLdapConfigurationResponse(config);
271+
}
272+
throw new InvalidParameterValueException("Cannot find configuration with id " + id);
273+
}
260274
return deleteConfigurationInternal(cmd.getHostname(), cmd.getPort(), cmd.getDomainId());
261275
}
262276

@@ -377,7 +391,8 @@ public Pair<List<? extends LdapConfigurationVO>, Integer> listConfigurations(fin
377391
final int port = cmd.getPort();
378392
final Long domainId = cmd.getDomainId();
379393
final boolean listAll = cmd.listAll();
380-
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(hostname, port, domainId, listAll);
394+
final Long id = cmd.getId();
395+
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(id, hostname, port, domainId, listAll);
381396
return new Pair<List<? extends LdapConfigurationVO>, Integer>(result.first(), result.second());
382397
}
383398

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ public interface LdapConfigurationDao extends GenericDao<LdapConfigurationVO, Lo
4141

4242
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId);
4343

44-
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(String hostname, int port, Long domainId, boolean listAll);
44+
Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(Long id, String hostname, int port, Long domainId, boolean listAll);
4545
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public LdapConfigurationDaoImpl() {
4848
listGlobalConfigurationsSearch.done();
4949

5050
listDomainConfigurationsSearch = createSearchBuilder();
51+
listDomainConfigurationsSearch.and("id", listDomainConfigurationsSearch.entity().getId(), SearchCriteria.Op.EQ);
5152
listDomainConfigurationsSearch.and("hostname", listDomainConfigurationsSearch.entity().getHostname(), Op.EQ);
5253
listDomainConfigurationsSearch.and("port", listDomainConfigurationsSearch.entity().getPort(), Op.EQ);
5354
listDomainConfigurationsSearch.and("domain_id", listDomainConfigurationsSearch.entity().getDomainId(), Op.EQ);
@@ -63,31 +64,35 @@ public LdapConfigurationVO findByHostname(final String hostname) {
6364

6465
@Override
6566
public LdapConfigurationVO find(String hostname, int port, Long domainId) {
66-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
67+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, false);
6768
return findOneBy(sc);
6869
}
6970

7071
@Override
7172
public LdapConfigurationVO find(String hostname, int port, Long domainId, boolean listAll) {
72-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, listAll);
73+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, listAll);
7374
return findOneBy(sc);
7475
}
7576

7677
@Override
7778
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final String hostname, final int port, final Long domainId) {
78-
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(hostname, port, domainId, false);
79+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(null, hostname, port, domainId, false);
7980
return searchAndCount(sc, null);
8081
}
8182

8283
@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);
84+
public Pair<List<LdapConfigurationVO>, Integer> searchConfigurations(final Long id, final String hostname, final int port, final Long domainId, final boolean listAll) {
85+
SearchCriteria<LdapConfigurationVO> sc = getSearchCriteria(id, hostname, port, domainId, listAll);
8586
return searchAndCount(sc, null);
8687
}
8788

88-
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(String hostname, int port, Long domainId,boolean listAll) {
89+
private SearchCriteria<LdapConfigurationVO> getSearchCriteria(Long id, String hostname, int port, Long domainId,boolean listAll) {
8990
SearchCriteria<LdapConfigurationVO> sc;
90-
if (domainId != null) {
91+
if (id != null) {
92+
// If id is present, ignore all other parameters
93+
sc = listDomainConfigurationsSearch.create();
94+
sc.setParameters("id", id);
95+
} else if (domainId != null) {
9196
// If domainid is present, ignore listall
9297
sc = listDomainConfigurationsSearch.create();
9398
sc.setParameters("domain_id", domainId);

ui/src/config/section/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default {
4141
permission: ['listLdapConfigurations'],
4242
searchFilters: ['domainid', 'hostname', 'port'],
4343
columns: ['hostname', 'port', 'domainid'],
44-
details: ['hostname', 'port', 'domainid'],
44+
details: ['id', 'hostname', 'port', 'domainid'],
4545
actions: [
4646
{
4747
api: 'addLdapConfiguration',

ui/src/views/AutogenView.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,6 @@ export default {
10781078
}
10791079
if (this.$route.path.startsWith('/vmsnapshot/')) {
10801080
params.vmsnapshotid = this.$route.params.id
1081-
} else if (this.$route.path.startsWith('/ldapsetting/')) {
1082-
params.hostname = this.$route.params.id
10831081
}
10841082
if (this.$route.path.startsWith('/tungstenpolicy/')) {
10851083
params.policyuuid = this.$route.params.id
@@ -1192,9 +1190,6 @@ export default {
11921190
this.items[idx][key] = func(this.items[idx])
11931191
}
11941192
}
1195-
if (this.$route.path.startsWith('/ldapsetting')) {
1196-
this.items[idx].id = this.items[idx].hostname
1197-
}
11981193
}
11991194
if (this.items.length > 0) {
12001195
if (!this.showAction || this.dataView) {

0 commit comments

Comments
 (0)