4

One of the fields on list is User Picker where often are place AD groups.

Authentication is set up with claims.

While presenting the item, users which are in this AD groups (and others mentioned in this field), need to see an button. Other (which have permission to see this item but were not mentioned) should not.

How can I get information, whether user is in this AD group?

  • Did you find any solution for this? – love thakker Feb 6 at 10:09
1

I use an extension method, like this:

 public static bool InGroup(this SPUser User, string GroupName)
    {
        return User.Groups.Cast<SPGroup>().Any(g => g.Name.ToLower() == GroupName.ToLower());
    }

Then call it like this:

bool inGroup = spuser.InGroup("GroupName");
  • This are not SPGroup, but AD Groups. Additional difficulty that they are claim based and SharePoint sees them as users. – Jacek Aug 17 '16 at 9:21
  • How can AD user come in claim based? Can you be more specific like you want to check this for the claim based users or for the AD users ? Because if your User is in AD group, you still will need to add him in any sharepoint group to give him access in sharepoint, untill and unless he don't have access. He will not be able to access SharePoint. Nd for the other case i.r claim based, the data for that is maintained in SQL database . So for which user you want to check ? – Muskan Aug 17 '16 at 9:25
-1

Steps to find User belongs to AD Group.

  • Create a SharePoint Group and add AD Group into SharePoint Group Use the below code to find user belongs to SharePoint Group or not

How to check if current user belongs to SharePoint group via CSOM (JavaScript):

function IsCurrentUserMemberOfGroup(groupName, OnComplete) {

    var currentContext = new SP.ClientContext.get_current();
    var currentWeb = currentContext.get_web();

    var currentUser = currentContext.get_web().get_currentUser();
    currentContext.load(currentUser);

    var allGroups = currentWeb.get_siteGroups();
    currentContext.load(allGroups);

    var group = allGroups.getByName(groupName);
    currentContext.load(group);

    var groupUsers = group.get_users();
    currentContext.load(groupUsers);

    currentContext.executeQueryAsync(OnSuccess,OnFailure);

    function OnSuccess(sender, args) {
        var userInGroup = false;
        var groupUserEnumerator = groupUsers.getEnumerator();
        while (groupUserEnumerator.moveNext()) {
            var groupUser = groupUserEnumerator.get_current();
            if (groupUser.get_id() == currentUser.get_id()) {
                userInGroup = true;
                break;
            }
        }  
        OnComplete(userInGroup);
    }

    function OnFailure(sender, args) {
        OnComplete(false);
    }    

}

Usage:

function IsCurrentUserHasContribPerms() 
{
  IsCurrentUserMemberOfGroup("Members", function (isCurrentUserInGroup) {
    if(isCurrentUserInGroup)
    {
        // The current user is in the [Members] group!
    }
  });

}
ExecuteOrDelayUntilScriptLoaded(IsCurrentUserHasContribPerms, 'SP.js');

Check if user is in a specified group

  • AD groups are not handled by this – JanErikGunnar Jan 19 '18 at 10:16
  • I didn't say this is only the way to find user belongs to AD group.. by using client context this would be the simplest way. – Nagaraju Pattem Jan 22 '18 at 0:33
  • @NagarajuPattem this does not work with AD groups, it doesn't appear in the list of groups of the user. – netadictos Oct 11 '18 at 7:57
  • @netadictos If you follow all the above steps you can identify AD Groups which we implemented long back and let me know where you have the issue. – Nagaraju Pattem Nov 1 '18 at 5:13
  • Nagaraju - can you provide any update for AD group scenario. Otherwise you can simply put the other link reference in comment – love thakker Feb 6 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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