Skip to content

Commit cd12fa5

Browse files
Add UUID field for LDAP configuration (#11462)
* Add UUID field for LDAP configuration * move db changes to the lastest schema file * Add ID param to list ldapConf API & delete ldapConf API * fix ui test * fix 1 ui test * fix test * fix api description --------- Co-authored-by: dahn <[email protected]>
1 parent 7dd0d6e commit cd12fa5

File tree

11 files changed

+89
-30
lines changed

11 files changed

+89
-30
lines changed

engine/schema/src/main/resources/META-INF/db/schema-42100to42200.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,11 @@ CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('router_health_check', 'check_result', '
2626
-- Increase length of scripts_version column to 128 due to md5sum to sha512sum change
2727
CALL `cloud`.`IDEMPOTENT_CHANGE_COLUMN`('cloud.domain_router', 'scripts_version', 'scripts_version', 'VARCHAR(128)');
2828

29+
-- Add uuid column to ldap_configuration table
30+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.ldap_configuration', 'uuid', 'VARCHAR(40) NOT NULL');
31+
32+
-- Populate uuid for existing rows where uuid is NULL or empty
33+
UPDATE `cloud`.`ldap_configuration` SET uuid = UUID() WHERE uuid IS NULL OR uuid = '';
34+
2935
-- Add the column cross_zone_instance_creation to cloud.backup_repository. if enabled it means that new Instance can be created on all Zones from Backups on this Repository.
3036
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backup_repository', 'cross_zone_instance_creation', 'TINYINT(1) DEFAULT NULL COMMENT ''Backup Repository can be used for disaster recovery on another zone''');

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; when passed, all other parameters are ignored")
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: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@
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 {
30+
@SerializedName("id")
31+
@Param(description = "the ID of the LDAP configuration")
32+
private String id;
33+
3034
@SerializedName(ApiConstants.HOST_NAME)
3135
@Param(description = "name of the host running the ldap server")
3236
private String hostname;
@@ -53,9 +57,18 @@ public LdapConfigurationResponse(final String hostname, final int port) {
5357
setPort(port);
5458
}
5559

56-
public LdapConfigurationResponse(final String hostname, final int port, final String domainId) {
60+
public LdapConfigurationResponse(final String hostname, final int port, final String domainId, final String id) {
5761
this(hostname, port);
5862
setDomainId(domainId);
63+
setId(id);
64+
}
65+
66+
public String getId() {
67+
return id;
68+
}
69+
70+
public void setId(String id) {
71+
this.id = id;
5972
}
6073

6174
public String getHostname() {

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,40 @@
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

29+
import java.util.UUID;
30+
2831
@Entity
2932
@Table(name = "ldap_configuration")
30-
public class LdapConfigurationVO implements InternalIdentity {
31-
@Column(name = "hostname")
32-
private String hostname;
33-
33+
public class LdapConfigurationVO implements Identity, InternalIdentity {
3434
@Id
3535
@GeneratedValue(strategy = GenerationType.IDENTITY)
3636
@Column(name = "id")
3737
private Long id;
3838

39+
@Column(name = "hostname")
40+
private String hostname;
41+
42+
@Column(name = "uuid")
43+
private String uuid;
44+
3945
@Column(name = "port")
4046
private int port;
4147

4248
@Column(name = "domain_id")
4349
private Long domainId;
4450

4551
public LdapConfigurationVO() {
52+
this.uuid = UUID.randomUUID().toString();
4653
}
4754

4855
public LdapConfigurationVO(final String hostname, final int port, final Long domainId) {
4956
this.hostname = hostname;
5057
this.port = port;
5158
this.domainId = domainId;
59+
this.uuid = UUID.randomUUID().toString();
5260
}
5361

5462
public String getHostname() {
@@ -60,6 +68,10 @@ public long getId() {
6068
return id;
6169
}
6270

71+
public String getUuid() {
72+
return uuid;
73+
}
74+
6375
public int getPort() {
6476
return port;
6577
}

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

Lines changed: 17 additions & 2 deletions
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;
@@ -240,7 +241,7 @@ public LdapConfigurationResponse createLdapConfigurationResponse(final LdapConfi
240241
domainUuid = domain.getUuid();
241242
}
242243
}
243-
return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort(), domainUuid);
244+
return new LdapConfigurationResponse(configuration.getHostname(), configuration.getPort(), domainUuid, configuration.getUuid());
244245
}
245246

246247
@Override
@@ -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)