From 02e77edb65f780fac62f5920d778a233bfcba3e3 Mon Sep 17 00:00:00 2001 From: Christian Baerike <7BN0xX3n1c9Ne20rZdHJ> Date: Sat, 24 Mar 2018 21:31:47 -0700 Subject: [PATCH] Store the actual username in the user model - the UserPrincipalName may include a different domain name. --- Bonobo.Git.Server/Data/ADBackend.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Bonobo.Git.Server/Data/ADBackend.cs b/Bonobo.Git.Server/Data/ADBackend.cs index 74ac59e57..66f5c6e98 100644 --- a/Bonobo.Git.Server/Data/ADBackend.cs +++ b/Bonobo.Git.Server/Data/ADBackend.cs @@ -129,7 +129,7 @@ private UserModel GetUserModelFromPrincipal(UserPrincipal user) result = new UserModel { Id = user.Guid.Value, - Username = user.UserPrincipalName, + Username = user.SamAccountName + "@" + user.Context.Name, GivenName = user.GivenName ?? String.Empty, Surname = user.Surname ?? String.Empty, Email = user.EmailAddress ?? String.Empty, @@ -170,15 +170,12 @@ private void UpdateUsers() { Users.Remove(Id); } - foreach (string username in group.GetMembers(true).OfType().Select(x => x.UserPrincipalName).Where(x => x != null)) + foreach (UserPrincipal principal in group.GetMembers(true).OfType()) { - using (var principal = ADHelper.GetUserPrincipal(username)) + UserModel user = GetUserModelFromPrincipal(principal); + if (user != null) { - UserModel user = GetUserModelFromPrincipal(principal); - if (user != null) - { - Users.AddOrUpdate(user); - } + Users.AddOrUpdate(user); } } } @@ -232,7 +229,7 @@ private void UpdateRoles() { Roles.Remove(role.Id); } - + foreach (string roleName in ActiveDirectorySettings.RoleNameToGroupNameMapping.Keys) { string groupName = ActiveDirectorySettings.RoleNameToGroupNameMapping[roleName];