0

I have written a logic to check if the current user belongs in a Specific SharePoint Group e.g. "Visitors". However this user is present in the DL and the DL is added in the SP group, e.g. DL-Org. The query returns null as the user is not present in the group directly.

Is there a way to get the SP groups the user is part of if the User is present in a DL group?

1 Answer 1

0

Just to clarify, I assume you mean security group, since Distribution Groups cannot be added to SharePoint groups.

Unfortunately, the answer to your question is no, there is no way to do what you're trying to do with client-side code. All of the methods for getting the SharePoint groups to which a user belongs on the client-side (REST, ASMX, CSOM, or JSOM), only return groups to which the user has been added directly.

It's a shame, because these days it's not that hard to do server-side. The following server-side code will get all the AD groups for a user:

// you have to do a little more work if SharePoint and the user are not
// in the same domain
using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain) {

    // user name does not include domain info
    UserPrincipal principal = (UserPrincipal)Principal.FindByIdentity(ctx, username);
    if(principal != null) {
        // this recursively returns all groups to which the user belongs, directly
        // or indirectly
        PrincipalSearchResult<Principal> groups = principal.GetAuthorizationGroups();
        IEnumerator<Principal> enumerator = groups.GetEnumerator();
        while(enumerator.moveNext) {
            // so something with enumerator.Current.SamAccountName
        }
    }
}

You didn't mention the SharePoint version, but this would require that SharePoint is running under at least .net 4.

So, if you have the luxury of deploying some server-side code, you could put this in a web service, deploy it to the server, and then call it from the client-side. Notes:

  • You would need to run this at elevated privileges.
  • You could then loop through all the SharePoint groups and check for if the user is a member, or if any of the groups returned from the PrincipalContext search is a member.
  • Return all SharePoint groups.

Your Answer

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

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