Пример #1
0
        private static void CreateAcmaSyncUsersGroup(Session session, string syncAccount)
        {
            PrincipalContext context  = new PrincipalContext(ContextType.Machine);
            GroupPrincipal   group    = GroupPrincipal.FindByIdentity(context, IdentityType.SamAccountName, CustomActions.GroupNameAcmaSyncUsers);
            bool             mustSave = false;

            if (group == null)
            {
                session.Log("Creating new group {0}", CustomActions.GroupNameAcmaSyncUsers);
                group      = new GroupPrincipal(context);
                group.Name = CustomActions.GroupNameAcmaSyncUsers;
                mustSave   = true;
            }

            UserPrincipal user = CustomActions.FindInDomainOrMachine(syncAccount);

            if (user == null)
            {
                session.Log("User not found {0}", syncAccount);
                throw new NoMatchingPrincipalException(string.Format("The user {0} could not be found", syncAccount));
            }

            if (!group.Members.Contains(user))
            {
                session.Log("Added user {0} to group {1}", syncAccount, CustomActions.GroupNameAcmaSyncUsers);

                group.Members.Add(user);
                mustSave = true;
            }

            if (mustSave)
            {
                group.Save();
            }
        }
Пример #2
0
        public static ActionResult CreateAcmaGroups(Session session)
        {
            CustomActions.CreateAcmaAdministratorsGroup(session);

            //string syncServiceAccount = session.CustomActionData["SyncServiceAccount"];

            //if (syncServiceAccount == null)
            //{
            //    session.Log("The sync service account parameter was not provided");
            //    throw new ArgumentException("The sync service account parameter was not provided");
            //}

            //CustomActions.CreateAcmaSyncUsersGroup(session, syncServiceAccount);

            return(ActionResult.Success);
        }