Beispiel #1
0
        private static Dictionary <string, Models.UserModel> UpdateUsers(string dir)
        {
            var users    = Pre600Functions.LoadContent <Pre600UserModel>(dir);
            var domains  = new Dictionary <string, PrincipalContext>();
            var newUsers = new Dictionary <string, Models.UserModel>();

            foreach (var user in users)
            {
                var ou = user.Value;
                var u  = new Models.UserModel();
                u.Email     = ou.Email;
                u.GivenName = ou.GivenName;
                u.Surname   = ou.Surname;
                u.Username  = ou.Name;
                u.Id        = Guid.NewGuid();

                var domainuser = ADHelper.GetUserPrincipal(u.Username);
                if (domainuser != null && domainuser.Guid.HasValue)
                {
                    u.Id = domainuser.Guid.Value;
                }

                ADBackend.Instance.Users.Add(u);
                newUsers[u.Username] = u;
            }
            return(newUsers);
        }
Beispiel #2
0
        private static Dictionary <string, Models.UserModel> UpdateUsers(string dir)
        {
            var users    = Pre600Functions.LoadContent <Pre600UserModel>(dir);
            var domains  = new Dictionary <string, PrincipalContext>();
            var newUsers = new Dictionary <string, Models.UserModel>();

            foreach (var user in users)
            {
                var ou = user.Value;
                var u  = new Models.UserModel();
                u.Email     = ou.Email;
                u.GivenName = ou.GivenName;
                u.Surname   = ou.Surname;
                u.Username  = ou.Name;
                u.Id        = Guid.NewGuid();

                PrincipalContext dc;
                var domain = u.Username.GetDomain();
                if (!domains.TryGetValue(domain, out dc))
                {
                    dc = new PrincipalContext(ContextType.Domain, domain);
                    domains[domain] = dc;
                }

                var domainuser = UserPrincipal.FindByIdentity(dc, u.Username);
                if (domainuser != null && domainuser.Guid.HasValue)
                {
                    u.Id = domainuser.Guid.Value;
                }

                ADBackend.Instance.Users.Add(u);
                newUsers[u.Username] = u;
            }
            return(newUsers);
        }
Beispiel #3
0
        private static Dictionary <string, Models.TeamModel> UpdateTeams(string dir, Dictionary <string, Models.UserModel> users)
        {
            var teams    = Pre600Functions.LoadContent <Pre600TeamModel>(dir);
            var newTeams = new Dictionary <string, Models.TeamModel>();

            foreach (var teamitem in teams)
            {
                var team    = teamitem.Value;
                var newteam = new Models.TeamModel();
                newteam.Name        = team.Name;
                newteam.Description = team.Description;

                newteam.Id = Guid.NewGuid();
                var members = new List <Models.UserModel>();
                foreach (var member in team.Members)
                {
                    members.Add(users[member]);
                }
                newteam.Members = members.ToArray();

                ADBackend.Instance.Teams.Add(newteam);
                newTeams[team.Name] = newteam;
            }
            return(newTeams);
        }
Beispiel #4
0
        private static void UpdateRepos(string dir, Dictionary <string, Models.UserModel> users, Dictionary <string, Models.TeamModel> teams)
        {
            var repos = Pre600Functions.LoadContent <Pre600RepositoryModel>(dir);

            foreach (var repoitem in repos)
            {
                var repo    = repoitem.Value;
                var newrepo = new Models.RepositoryModel();
                newrepo.Id              = Guid.NewGuid();
                newrepo.Name            = repo.Name;
                newrepo.Group           = repo.Group;
                newrepo.Description     = repo.Description;
                newrepo.AnonymousAccess = repo.AnonymousAccess;
                newrepo.AuditPushUser   = repo.AuditPushUser;
                newrepo.Logo            = repo.Logo;
                newrepo.RemoveLogo      = repo.RemoveLogo;

                var list = new List <Models.UserModel>();
                foreach (var user in repo.Users)
                {
                    list.Add(users[user]);
                }
                newrepo.Users = list.ToArray();

                list.Clear();
                foreach (var admins in repo.Administrators)
                {
                    list.Add(users[admins]);
                }
                newrepo.Administrators = list.ToArray();

                var newteams = new List <Models.TeamModel>();
                foreach (var team in repo.Teams)
                {
                    newteams.Add(teams[team]);
                }
                newrepo.Teams = newteams.ToArray();

                ADBackend.Instance.Repositories.Add(newrepo);
            }
        }
Beispiel #5
0
        private static Dictionary <string, Models.TeamModel> UpdateTeams(string dir, Dictionary <string, Models.UserModel> users)
        {
            var teams    = Pre600Functions.LoadContent <Pre600TeamModel>(dir);
            var newTeams = new Dictionary <string, Models.TeamModel>();

            foreach (var teamitem in teams)
            {
                var team    = teamitem.Value;
                var newteam = new Models.TeamModel();
                newteam.Name        = team.Name;
                newteam.Description = team.Description;
                newteam.Id          = Guid.NewGuid();

                try
                {
                    GroupPrincipal group;
                    using (var pc = ADHelper.GetPrincipalGroup(ActiveDirectorySettings.TeamNameToGroupNameMapping[team.Name], out group))
                    {
                        newteam.Id = group.Guid.Value;
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError("Failed to acquire group GUID - adding new.");
                    Trace.TraceError(ex.Message);
                }


                var members = new List <Models.UserModel>();
                foreach (var member in team.Members)
                {
                    members.Add(users[member]);
                }
                newteam.Members = members.ToArray();

                ADBackend.Instance.Teams.Add(newteam);
                newTeams[team.Name] = newteam;
            }
            return(newTeams);
        }
Beispiel #6
0
        private static void UpdateRoles(string dir, Dictionary <string, Models.UserModel> users)
        {
            var roles = Pre600Functions.LoadContent <Pre600RoleModel>(dir);

            foreach (var roleitem in roles)
            {
                var role    = roleitem.Value;
                var newrole = new Models.RoleModel();
                newrole.Name = role.Name;

                newrole.Id = Guid.NewGuid();
                var members = new List <Guid>();
                foreach (var memberName in role.Members)
                {
                    Models.UserModel user;
                    if (users.TryGetValue(memberName, out user))
                    {
                        members.Add(user.Id);
                    }
                }
                newrole.Members = members.ToArray();
            }
        }