mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 20:02:29 +01:00
CLOUDSTACK-1673: AWS Regions - Events - User disable / Domain Delete event does not
include the UUID of the user/domain that was disabled. - added enity type and enity UUID details to UserContext - publish the entity type and UUID details for the action events generated for accout/user/domain
This commit is contained in:
parent
5c3013a694
commit
7f2c659630
@ -29,6 +29,8 @@ public class UserContext {
|
||||
private long accountId;
|
||||
private String eventDetails;
|
||||
private boolean apiServer;
|
||||
private Class entityType;
|
||||
private String entityUUID;
|
||||
|
||||
@Inject private AccountService _accountMgr = null;
|
||||
|
||||
@ -137,4 +139,25 @@ public class UserContext {
|
||||
public String getEventDetails() {
|
||||
return eventDetails;
|
||||
}
|
||||
|
||||
public void setEntityDetails(Class entityType, String uuid) {
|
||||
this.entityType = entityType;
|
||||
this.entityUUID = uuid;
|
||||
}
|
||||
|
||||
public String getEntityType() {
|
||||
return (entityType != null) ? entityType.getName() : null;
|
||||
}
|
||||
|
||||
public void setEntityType(Class entityType) {
|
||||
this.entityType = entityType;
|
||||
}
|
||||
|
||||
public String getEntityUUID() {
|
||||
return entityUUID;
|
||||
}
|
||||
|
||||
public void setEntityUUID(String entityUUID) {
|
||||
this.entityUUID = entityUUID;
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ import com.cloud.user.AccountVO;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.dao.AccountDao;
|
||||
import com.cloud.user.dao.UserDao;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import org.apache.cloudstack.framework.events.EventBus;
|
||||
import org.apache.cloudstack.framework.events.EventBusException;
|
||||
@ -152,6 +153,15 @@ public class ActionEventUtils {
|
||||
return; // no provider is configured to provide events bus, so just return
|
||||
}
|
||||
|
||||
// get the entity details for which ActionEvent is generated
|
||||
String entityType = null;
|
||||
String entityUuid = null;
|
||||
UserContext context = UserContext.current();
|
||||
if (context != null) {
|
||||
entityType = context.getEntityType();
|
||||
entityUuid = context.getEntityUUID();
|
||||
}
|
||||
|
||||
org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(
|
||||
ManagementServer.Name,
|
||||
eventCategory,
|
||||
@ -170,6 +180,8 @@ public class ActionEventUtils {
|
||||
eventDescription.put("account", account.getUuid());
|
||||
eventDescription.put("event", eventType);
|
||||
eventDescription.put("status", state.toString());
|
||||
eventDescription.put("entity", entityType);
|
||||
eventDescription.put("entityuuid", entityUuid);
|
||||
event.setDescription(eventDescription);
|
||||
|
||||
try {
|
||||
|
||||
@ -910,6 +910,8 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
UserContext.current().setEntityDetails(Account.class, account.getUuid());
|
||||
|
||||
//check success
|
||||
return _userAccountDao.findById(user.getId());
|
||||
}
|
||||
@ -1070,6 +1072,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
s_logger.error("error updating user", th);
|
||||
throw new CloudRuntimeException("Unable to update user " + id);
|
||||
}
|
||||
|
||||
UserContext.current().setEntityDetails(User.class, user.getUuid());
|
||||
|
||||
return _userAccountDao.findById(id);
|
||||
}
|
||||
|
||||
@ -1100,6 +1105,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
|
||||
boolean success = doSetUserStatus(userId, State.disabled);
|
||||
if (success) {
|
||||
|
||||
UserContext.current().setEntityDetails(User.class, user.getUuid());
|
||||
|
||||
// user successfully disabled
|
||||
return _userAccountDao.findById(userId);
|
||||
} else {
|
||||
@ -1146,6 +1154,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
if (success) {
|
||||
// whenever the user is successfully enabled, reset the login attempts to zero
|
||||
updateLoginAttempts(userId, 0, false);
|
||||
|
||||
UserContext.current().setEntityDetails(User.class, user.getUuid());
|
||||
|
||||
return _userAccountDao.findById(userId);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to enable user " + userId);
|
||||
@ -1207,6 +1218,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
||||
UserContext.current().setEntityDetails(User.class, user.getUuid());
|
||||
|
||||
return _userAccountDao.findById(userId);
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to lock user " + userId);
|
||||
@ -1252,6 +1266,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
|
||||
throw new InvalidParameterValueException("The account id=" + accountId + " manages project(s) with ids " + projectIds + "and can't be removed");
|
||||
}
|
||||
|
||||
UserContext.current().setEntityDetails(Account.class, account.getUuid());
|
||||
|
||||
return deleteAccount(account, callerUserId, caller);
|
||||
}
|
||||
|
||||
@ -1281,6 +1298,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
|
||||
boolean success = enableAccount(account.getId());
|
||||
if (success) {
|
||||
|
||||
UserContext.current().setEntityDetails(Account.class, account.getUuid());
|
||||
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to enable account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
@ -1310,6 +1330,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
checkAccess(caller, null, true, account);
|
||||
|
||||
if (lockAccount(account.getId())) {
|
||||
UserContext.current().setEntityDetails(Account.class, account.getUuid());
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to lock account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
@ -1339,6 +1360,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
checkAccess(caller, null, true, account);
|
||||
|
||||
if (disableAccount(account.getId())) {
|
||||
UserContext.current().setEntityDetails(Account.class, account.getUuid());
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
@ -1421,6 +1443,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
txn.commit();
|
||||
|
||||
if (success) {
|
||||
UserContext.current().setEntityDetails(Account.class, account.getUuid());
|
||||
return _accountDao.findById(account.getId());
|
||||
} else {
|
||||
throw new CloudRuntimeException("Unable to update account by accountId: " + accountId + " OR by name: " + accountName + " in domain " + domainId);
|
||||
@ -1451,6 +1474,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
}
|
||||
|
||||
checkAccess(UserContext.current().getCaller(), null, true, account);
|
||||
UserContext.current().setEntityDetails(User.class, user.getUuid());
|
||||
return _userDao.remove(id);
|
||||
}
|
||||
|
||||
@ -1769,7 +1793,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
|
||||
userUUID = UUID.randomUUID().toString();
|
||||
}
|
||||
UserVO user = _userDao.persist(new UserVO(accountId, userName, encodedPassword, firstName, lastName, email, timezone, userUUID));
|
||||
|
||||
UserContext.current().setEntityDetails(User.class, user.getUuid());
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@ -184,6 +184,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
||||
DomainVO domain = _domainDao.create(new DomainVO(name, ownerId, parentId, networkDomain, domainUUID));
|
||||
_resourceCountDao.createResourceCounts(domain.getId(), ResourceLimit.ResourceOwnerType.Domain);
|
||||
txn.commit();
|
||||
UserContext.current().setEntityDetails(Domain.class, domain.getUuid());
|
||||
return domain;
|
||||
}
|
||||
|
||||
@ -280,6 +281,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
||||
}
|
||||
|
||||
cleanupDomainOfferings(domain.getId());
|
||||
UserContext.current().setEntityDetails(Domain.class, domain.getUuid());
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception deleting domain with id " + domain.getId(), ex);
|
||||
@ -604,7 +606,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
||||
}
|
||||
}
|
||||
_domainDao.update(domainId, domain);
|
||||
|
||||
UserContext.current().setEntityDetails(Domain.class, domain.getUuid());
|
||||
txn.commit();
|
||||
|
||||
return _domainDao.findById(domainId);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user