- Create a New Site or Site Collection.
- Create an AD Group that contains "Admin, User1" and "Admin, User2".
- Add this AD Group under Site Actions > Site Permissions and then Site Collection Administrators.
- Add "Owner, User1" and "Owner, User2" to your owners group, and "Member, User1" and "Member User2" in your members group.
using (SPSite siteCollection = new SPSite(SPContext.Current.Site.ID)) { int userCnt = 0; SPUserCollection userCollection = siteCollection.RootWeb.SiteUsers; foreach (SPUser user in userCollection) { string userSTR = user.Name; string userPERM = siteCollection.RootWeb.GetUserEffectivePermissions(user.LoginName).ToString(); if (userPERM.Equals("FullMask") && !user.IsSiteAdmin) { userCnt++; ownersOUTPUT.Text += userSTR + "</br>"; } } }When you run this you should only see "Owner, User1" and "Owner, User2", which would be what you would expect. Now add "Admin, User1" and "Members, User1" to your owners group and reload. As expected, you should now see "Admin, User1" and "Member, User1" listed as well. Finally, remove "Admin, User1" and "Member, User1" from your owners group and refresh. You should see what I am talking about.
"Member, User1" should disappear like you would expect, but "Admin, User1" is still listed and will not go away. Notice my code excludes users where IsSiteAdmin is true. Try adding "Admin, User1" directly to Site Collection Administrators and reload. Poof, he is gone.
This is because when a user is added directly to Site Collection Administrators IsSiteAdmin returns true; however, when the user has access via an AD Group in the same location IsSiteAdmin returns false. I assume that this works properly before "Admin, User1" is added directly because the users permissions do not exist via the sharepoint table. However, when you add the user to the site a record is create and is not properly cleaned up when removed due to them being referenced as Site Collection Administrator via the AD Group.
I have not been able to test removing a user from the AD Group as that is just not a simple job in my environment. I have contacted our Microsoft Rep for more information on this, and will provide more information once I recieve it.
No comments:
Post a Comment