Exemple #1
0
        /// <summary>
        ///     Gets the name of the managed by.
        /// </summary>
        /// <param name="groupPrincipal">The group principal.</param>
        /// <returns>System.String.</returns>
        /// TODO Edit XML Comment Template for GetManagedByName
        public static string GetManagedByName(
            this GroupPrincipal groupPrincipal)
        {
            var managedByDistinguishedName =
                groupPrincipal.GetManagedByDistinguishedName();

            if (managedByDistinguishedName.IsNullOrWhiteSpace())
            {
                return(null);
            }

            using (var principalContext =
                       PrincipalContextExtensions.GetPrincipalContext())

                using (var managedByUserPrincipal =
                           UserPrincipalExtensions.FindByDistinguishedName(
                               principalContext,
                               managedByDistinguishedName))
                {
                    return(managedByUserPrincipal?.Name);
                }
        }
Exemple #2
0
        /// <summary>
        ///     Adds the group property.
        /// </summary>
        /// <param name="groupPrincipal">The group principal.</param>
        /// <param name="property">The property.</param>
        /// <param name="result">The result.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        /// TODO Edit XML Comment Template for AddGroupProperty
        private static bool AddGroupProperty(
            GroupPrincipal groupPrincipal,
            ActiveDirectoryProperty property,
            dynamic result)
        {
            var propertyMapping = new ActiveDirectoryPropertyMapping
            {
                [ActiveDirectoryProperty.GroupContext] = () =>
                {
                    result.GroupContext = groupPrincipal.Context;
                },
                [ActiveDirectoryProperty.GroupContextType] = () =>
                {
                    result.GroupContextType = groupPrincipal.ContextType;
                },
                [ActiveDirectoryProperty.GroupDescription] = () =>
                {
                    result.GroupDescription = groupPrincipal.Description;
                },
                [ActiveDirectoryProperty.GroupDisplayName] = () =>
                {
                    result.GroupDisplayName = groupPrincipal.DisplayName;
                },
                [ActiveDirectoryProperty.GroupDistinguishedName] = () =>
                {
                    result.GroupDistinguishedName =
                        groupPrincipal.DistinguishedName;
                },
                [ActiveDirectoryProperty.GroupGuid] = () =>
                {
                    result.GroupGuid = groupPrincipal.Guid;
                },
                [ActiveDirectoryProperty.GroupIsSecurityGroup] = () =>
                {
                    result.GroupIsSecurityGroup =
                        groupPrincipal.IsSecurityGroup;
                },
                [ActiveDirectoryProperty.GroupManagedByDistinguishedName] =
                    () =>
                {
                    result.GroupManagedByDistinguishedName = groupPrincipal
                                                             .GetManagedByDistinguishedName();
                },
                [ActiveDirectoryProperty.GroupManagedByName] = () =>
                {
                    result.GroupManagedByName =
                        groupPrincipal.GetManagedByName();
                },
                [ActiveDirectoryProperty.GroupName] = () =>
                {
                    result.GroupName = groupPrincipal.Name;
                },
                [ActiveDirectoryProperty.GroupSamAccountName] = () =>
                {
                    result.GroupSamAccountName = groupPrincipal.SamAccountName;
                },
                [ActiveDirectoryProperty.GroupScope] = () =>
                {
                    result.GroupScope = groupPrincipal.GroupScope;
                },
                [ActiveDirectoryProperty.GroupSid] = () =>
                {
                    result.GroupSid = groupPrincipal.Sid;
                },
                [ActiveDirectoryProperty.GroupStructuralObjectClass] = () =>
                {
                    result.GroupStructuralObjectClass =
                        groupPrincipal.StructuralObjectClass;
                },
                [ActiveDirectoryProperty.GroupUserPrincipalName] = () =>
                {
                    result.GroupUserPrincipalName =
                        groupPrincipal.UserPrincipalName;
                },
                [ActiveDirectoryProperty.GroupMembers] = () =>
                {
                    result.GroupMembers = groupPrincipal.Members;
                }
            };

            if (!propertyMapping.ContainsKey(property))
            {
                return(false);
            }

            propertyMapping[property]();
            return(true);
        }