1

I have the requirement to enumerate a list of users that are in an Active Directory group that has been granted rights to an SPWeb. If the site collection is using windows auth this is no problem and you can get user list via a simple call to SPUtility.GetPrincipalsInGroup. However when it's using claims this is where this method breaks. My question is, is it possible to utilize the SharePoint API to get user list from an Active Directory group when the site collection is configured with Claims auth?

2 Answers 2

1

Claims authentication combines different authentication methods like basic, active directory etc. This means that the group that has been granted rights to an SPWeb does not necessarily has to be an Active Directory group.

1

After a related Stack Overflow answer mentioned the System.DirectoryServices.AccountManagement namespace, I tried using it in my SharePoint site that includes Claims Authentication to determine if a username is a member of an Active Directory security group on the domain. It worked.

    public bool UserIsMemberOf(string userNameWithoutDomain, string domainName, string groupName) {
        var result = false;
        SPSecurity.RunWithElevatedPrivileges(() => {
            var context = new PrincipalContext(ContextType.Domain, domainName);
            using (var searcher = new PrincipalSearcher()) {
                searcher.QueryFilter = new GroupPrincipal(context, groupName);
                var group = searcher.FindOne() as GroupPrincipal;
                if (group != null) {
                    result = group.GetMembers().Any(x => string.Equals(userNameWithoutDomain, x.SamAccountName, StringComparison.InvariantCultureIgnoreCase));
                }
            }
        });
        return result;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.