Juan Hernandez has uploaded a new change for review. Change subject: core, restapi: Don't store domain suffix in user name ......................................................................
core, restapi: Don't store domain suffix in user name Currently when we save the information about an user to the "users" table we store the user name followed by the at sign and the domain name in the "username" column. This duplicates information as the domain name is already stored in the "domain" column of the same table. This patch removes that domain name suffix from the database and changes the LDAP implementations so that the domain name will not be added again when refreshing the users. The RESTAPI user mapper also needs to be changed in order to preserve the previous behaviour: showing the user name follwed by the at sign and the domain name. The view used to populate the "permissions" entity also needs to be changed so that the domain name will be presented in the GUI as it used to be. Note that both in the RESTAPI and in the GUI the domain name will appear with the same case that it has in the database, which is lower case by default. This is different than it used to be, as it used to be upper case. Is this relevant? Change-Id: Iaa6788600e0a68696f1d358a99223ecc1c75382c Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com> --- M backend/manager/dbscripts/create_functions.sql A backend/manager/dbscripts/upgrade/03_03_0100_remove_domain_from_username.sql M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/ADUserContextMapper.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserAttributes.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserContextMapper.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerCommandBase.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DbUser.java M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/UserMapper.java 8 files changed, 39 insertions(+), 40 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/14255/1 diff --git a/backend/manager/dbscripts/create_functions.sql b/backend/manager/dbscripts/create_functions.sql index 8ed564e..cac0782 100644 --- a/backend/manager/dbscripts/create_functions.sql +++ b/backend/manager/dbscripts/create_functions.sql @@ -387,7 +387,7 @@ if (v_ad_element_id = getGlobalIds('everyone')) then result := 'Everyone'; else - select(COALESCE(name,'') || ' ' || COALESCE(surname,'') || ' (' || COALESCE(username,'') || ')') INTO result from users where user_id = v_ad_element_id; + select(COALESCE(name,'') || ' ' || COALESCE(surname,'') || ' (' || username || '@' || domain || ')') INTO result from users where user_id = v_ad_element_id; if (result is null) then select name INTO result from ad_groups where ID = v_ad_element_id; end if; diff --git a/backend/manager/dbscripts/upgrade/03_03_0100_remove_domain_from_username.sql b/backend/manager/dbscripts/upgrade/03_03_0100_remove_domain_from_username.sql new file mode 100644 index 0000000..9738f6e --- /dev/null +++ b/backend/manager/dbscripts/upgrade/03_03_0100_remove_domain_from_username.sql @@ -0,0 +1,5 @@ +-- +-- Remove the domain suffix from the username column of the +-- user table: +-- +update users set username = regexp_replace(username, '@.*', ''); diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/ADUserContextMapper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/ADUserContextMapper.java index 3d96806..65af2af 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/ADUserContextMapper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/ADUserContextMapper.java @@ -1,13 +1,6 @@ package org.ovirt.engine.core.bll.adbroker; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.department; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.givenname; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.mail; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.memberof; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.objectguid; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.sn; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.title; -import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.userprincipalname; +import static org.ovirt.engine.core.bll.adbroker.ADUserAttributes.*; import java.util.ArrayList; import java.util.List; @@ -29,9 +22,16 @@ private static Log log = LogFactory.getLog(LdapBrokerImpl.class); - public final static String[] USERS_ATTRIBUTE_FILTER = { objectguid.name(), userprincipalname.name(), - givenname.name(), department.name(), title.name(), mail.name(), memberof.name(), - sn.name() }; + public final static String[] USERS_ATTRIBUTE_FILTER = { + objectguid.name(), + userprincipalname.name(), + givenname.name(), + department.name(), + title.name(), + mail.name(), + memberof.name(), + sn.name(), + }; @Override public Object mapFromContext(Object ctx) { @@ -59,7 +59,12 @@ // Getting other string properties Attribute att = attributes.get(userprincipalname.name()); if (att != null) { - user.setUserName((String) att.get(0)); + String name = (String) att.get(0); + int index = name.indexOf("@"); + if (index != -1) { + name = name.substring(0, index); + } + user.setUserName(name); } else { return null; } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserAttributes.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserAttributes.java index 9bc035d..58fd453 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserAttributes.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserAttributes.java @@ -2,11 +2,11 @@ public enum IPAUserAttributes { ipaUniqueId, - krbPrincipalname, givenname, department, title, mail, memberof, - sn + sn, + uid } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserContextMapper.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserContextMapper.java index 42ff031..d554561 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserContextMapper.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/IPAUserContextMapper.java @@ -1,13 +1,6 @@ package org.ovirt.engine.core.bll.adbroker; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.department; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.givenname; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.ipaUniqueId; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.krbPrincipalname; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.mail; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.memberof; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.sn; -import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.title; +import static org.ovirt.engine.core.bll.adbroker.IPAUserAttributes.*; import java.util.ArrayList; import java.util.List; @@ -29,9 +22,16 @@ private static Log log = LogFactory.getLog(LdapBrokerImpl.class); - public final static String[] USERS_ATTRIBUTE_FILTER = { ipaUniqueId.name(), krbPrincipalname.name(), - givenname.name(), department.name(), title.name(), mail.name(), memberof.name(), - sn.name() }; + public final static String[] USERS_ATTRIBUTE_FILTER = { + ipaUniqueId.name(), + givenname.name(), + department.name(), + title.name(), + mail.name(), + memberof.name(), + sn.name(), + uid.name(), + }; @Override public Object mapFromContext(Object ctx) { @@ -57,7 +57,7 @@ user.setUserId(Guid.createGuidFromString(objectGuid)); // Getting other string properties - Attribute att = attributes.get(krbPrincipalname.name()); + Attribute att = attributes.get(uid.name()); if (att != null) { user.setUserName((String) att.get(0)); } else { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerCommandBase.java index 3797e7c..36bb541 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/adbroker/LdapBrokerCommandBase.java @@ -96,9 +96,6 @@ proceedGroupsSearchResult(user.getMemberof(), groupsDict, generator); user.setGroups(groupsDict); - if (user.getUserName() != null && !user.getUserName().contains("@")) { - user.setUserName(user.getUserName() + "@" + user.getDomainControler()); - } return user; } diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DbUser.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DbUser.java index ec0452b..46a86e2 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DbUser.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/DbUser.java @@ -190,7 +190,7 @@ public DbUser(LdapUser ldapUser) { setuser_id(ldapUser.getUserId()); - setusername(getFullUserName(ldapUser)); + setusername(ldapUser.getUserName()); setname(ldapUser.getName()); setsurname(ldapUser.getSurName()); setdepartment(ldapUser.getDepartment()); @@ -199,14 +199,6 @@ setgroups(ldapUser.getGroup()); setstatus(LdapRefStatus.Active.getValue()); setGroupIds(ldapUser.getGroupIds()); - } - - private String getFullUserName(LdapUser ldapUser) { - String userName = ldapUser.getUserName(); - if (userName.indexOf("@") == -1) { - userName = userName +"@"+ ldapUser.getDomainControler(); - } - return userName; } public LdapRefStatus getAdStatus() { diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/UserMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/UserMapper.java index 09063b0..fb139a1 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/UserMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/UserMapper.java @@ -17,7 +17,7 @@ public static User map(DbUser entity, User template) { User model = template != null ? template : new User(); model.setName(entity.getname()); - model.setUserName(entity.getusername()); + model.setUserName(entity.getusername() + "@" + entity.getdomain()); model.setId(entity.getuser_id().toString()); model.setLastName(entity.getsurname()); model.setEmail(entity.getemail()); -- To view, visit http://gerrit.ovirt.org/14255 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iaa6788600e0a68696f1d358a99223ecc1c75382c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches