CLOUDSTACK-7073: Added domainId field to the user table in order to restrict duplicated users creation on the db level

This commit is contained in:
Alena Prokharchyk 2014-07-07 15:12:36 -07:00
parent b87a5ce5fe
commit 5a96d8ef5c
3 changed files with 25 additions and 0 deletions

View File

@ -97,6 +97,9 @@ public class UserVO implements User, Identity, InternalIdentity {
@Column(name = "default")
boolean isDefault;
@Column(name = "domain_id")
private long domainId;
public UserVO() {
this.uuid = UUID.randomUUID().toString();
}
@ -270,4 +273,7 @@ public class UserVO implements User, Identity, InternalIdentity {
return isDefault;
}
public void setDomainId(long domainId) {
this.domainId = domainId;
}
}

View File

@ -19,9 +19,11 @@ package com.cloud.user.dao;
import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import org.springframework.stereotype.Component;
import com.cloud.user.Account;
import com.cloud.user.UserVO;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@ -40,6 +42,9 @@ public class UserDaoImpl extends GenericDaoBase<UserVO, Long> implements UserDao
protected SearchBuilder<UserVO> SecretKeySearch;
protected SearchBuilder<UserVO> RegistrationTokenSearch;
@Inject
AccountDao _accountDao;
protected UserDaoImpl() {
UsernameSearch = createSearchBuilder();
UsernameSearch.and("username", UsernameSearch.entity().getUsername(), SearchCriteria.Op.EQ);
@ -128,4 +133,12 @@ public class UserDaoImpl extends GenericDaoBase<UserVO, Long> implements UserDao
return listBy(sc);
}
@Override
@DB
public UserVO persist(UserVO user) {
Account account = _accountDao.findById(user.getAccountId());
user.setDomainId(account.getDomainId());
return super.persist(user);
}
}

View File

@ -234,3 +234,9 @@ CREATE VIEW `cloud`.`volume_view` AS
/* As part of the separation of Xen and XenServer, update the column for the network labels */
ALTER TABLE `cloud`.`physical_network_traffic_types` CHANGE `xen_network_label` `xenserver_network_label` varchar(255) COMMENT 'The network name label of the physical device dedicated to this traffic on a XenServer host';
/*Adding domainId field to the user table in order to restrict duplicated users creation on the db level*/
ALTER TABLE `cloud`.`user` ADD COLUMN domain_id bigint(20) unsigned DEFAULT NULL;
ALTER TABLE `cloud`.`user` ADD CONSTRAINT `fk_user__domain_id` FOREIGN KEY `fk_user__domain_id`(`domain_id`) REFERENCES `domain`(`id`) ON DELETE CASCADE;
UPDATE `cloud`.`user` SET `cloud`.`user`.domain_id=(SELECT `cloud`.`account`.domain_id FROM `cloud`.`account` WHERE `cloud`.`account`.id=`cloud`.`user`.account_id) where id > 0;
ALTER TABLE `cloud`.`user` ADD UNIQUE KEY `username_domain_id` (`username`,`domain_id`);