use of org.ovirt.engine.core.common.businessentities.aaa.DbGroup in project ovirt-engine by oVirt.
the class GroupMapper method map.
@Mapping(from = Group.class, to = DbGroup.class)
public static DbGroup map(Group model, DbGroup template) {
DbGroup entity = template != null ? template : new DbGroup();
if (model.isSetName()) {
entity.setName(model.getName());
}
if (model.isSetId()) {
String id = model.getId();
entity.setId(GuidUtils.asGuid(id));
}
if (model.isSetDomain()) {
Domain domain = model.getDomain();
if (domain.isSetName()) {
entity.setDomain(domain.getName());
}
}
if (model.isSetDomainEntryId()) {
entity.setExternalId(DirectoryEntryIdUtils.decode(model.getDomainEntryId()));
}
if (model.isSetNamespace()) {
entity.setNamespace(model.getNamespace());
}
return entity;
}
use of org.ovirt.engine.core.common.businessentities.aaa.DbGroup in project ovirt-engine by oVirt.
the class CreateUserSessionCommand method buildUser.
private DbUser buildUser(T params, String authzName) {
DbUser dbUser = dbUserDao.getByExternalId(authzName, params.getPrincipalId());
DbUser user = new DbUser(dbUser);
user.setId(dbUser == null ? Guid.newGuid() : dbUser.getId());
user.setExternalId(params.getPrincipalId());
user.setDomain(authzName);
user.setEmail(params.getEmail());
user.setFirstName(params.getFirstName());
user.setLastName(params.getLastName());
user.setNamespace(params.getNamespace());
user.setLoginName(params.getPrincipalName());
List<Guid> groupIds = new ArrayList<>();
Map<String, ExtMap> groupRecords = new HashMap<>();
flatGroups((Collection<ExtMap>) params.getGroupIds(), groupRecords);
for (Map.Entry<String, ExtMap> group : groupRecords.entrySet()) {
DbGroup dbGroup = dbGroupDao.getByExternalId(authzName, group.getKey());
if (dbGroup != null) {
dbGroup.setName(group.getValue().get(Authz.GroupRecord.NAME));
dbGroupDao.update(dbGroup);
groupIds.add(dbGroup.getId());
}
}
user.setGroupIds(groupIds);
user.setAdmin(!roleDao.getAnyAdminRoleForUserAndGroups(user.getId(), StringUtils.join(user.getGroupIds(), ",")).isEmpty());
if (dbUser == null) {
dbUserDao.save(user);
} else if (!dbUser.equals(user)) {
dbUserDao.update(user);
}
return user;
}
use of org.ovirt.engine.core.common.businessentities.aaa.DbGroup in project ovirt-engine by oVirt.
the class AttachUserGroupToTagCommand method executeCommand.
@Override
protected void executeCommand() {
if (getTagId() != null) {
for (Guid groupGuid : getGroupList()) {
DbGroup group = dbGroupDao.get(groupGuid);
if (tagDao.getTagUserGroupByGroupIdAndByTagId(getTagId(), groupGuid) == null) {
TagsUserGroupMap map = new TagsUserGroupMap(groupGuid, getTagId());
tagDao.attachUserGroupToTag(map);
noActionDone = false;
if (group != null) {
appendCustomCommaSeparatedValue("AttachGroupsNames", group.getName());
}
} else {
if (group != null) {
appendCustomCommaSeparatedValue("AttachGroupsNamesExists", group.getName());
}
}
}
setSucceeded(true);
}
}
use of org.ovirt.engine.core.common.businessentities.aaa.DbGroup in project ovirt-engine by oVirt.
the class AddPermissionCommand method executeCommand.
@Override
protected void executeCommand() {
// Get the parameters:
T parameters = getParameters();
// The user or group given in the parameters may haven't been added to the database yet, if this is the case
// then they need to be added to the database now, before the permission:
DbUser user = parameters.getUser();
if (user != null) {
Guid id = user.getId();
String directory = user.getDomain();
String externalId = user.getExternalId();
DbUser existing = dbUserDao.getByIdOrExternalId(id, directory, externalId);
if (existing != null) {
user = existing;
} else {
user = addUser(user);
if (user == null) {
setSucceeded(false);
return;
}
}
}
DbGroup group = parameters.getGroup();
if (group != null) {
Guid id = group.getId();
String directory = group.getDomain();
String externalId = group.getExternalId();
DbGroup existing = dbGroupDao.getByIdOrExternalId(id, directory, externalId);
if (existing != null) {
group = existing;
} else {
group = addGroup(group);
if (group == null) {
setSucceeded(false);
return;
}
}
}
// The identifier of the principal of the permission can come from the parameters directly or from the
// user/group objects:
Guid principalId;
if (user != null) {
principalId = user.getId();
} else if (group != null) {
principalId = group.getId();
} else {
principalId = parameters.getPermission().getAdElementId();
}
final Permission paramPermission = parameters.getPermission();
Permission permission = permissionDao.getForRoleAndAdElementAndObject(paramPermission.getRoleId(), principalId, paramPermission.getObjectId());
if (permission == null) {
paramPermission.setAdElementId(principalId);
TransactionSupport.executeInNewTransaction(() -> {
permissionDao.save(paramPermission);
getCompensationContext().snapshotNewEntity(paramPermission);
getCompensationContext().stateChanged();
return null;
});
permission = paramPermission;
}
getReturnValue().setActionReturnValue(permission.getId());
if (user != null) {
updateAdminStatus(permission);
}
vmStaticDao.incrementDbGeneration(paramPermission.getObjectId());
setSucceeded(true);
}
Aggregations