Bug in ActiveDirectoryRoleProvider::IsUserInRole()
Vote:
I had a problem with IsUserInRole() returning false, but the role was listed for the user when i called GetRolesForUser().
I reflected the ActiveDirectoryRoleProvider, and found this loop in IsUserInRoleRecursive():
while (i < array2.Length)
{
string text = array2[i];
bool result;
if (string.Compare(text, distinguishedUserName, System.StringComparison.OrdinalIgnoreCase) == 0)
{
result = true;
}
else
{
DirectoryData entry = this._factory.GetEntry(text);
if (entry == null || !(entry.SchemaClassName == "group"))
{
i++;
continue;
}
result = this.IsUserInRoleRecursive(distinguishedUserName, entry);
}
return result;
}
The problem is if array2 contains a group (if not only one group, and that group happens to be the last entry in array2). The loop will get a result from the recursive call, and return that value even if it's false, instead of keep searching the list (array2).
I had a problem with IsUserInRole() returning false, but the role was listed for the user when i called GetRolesForUser().
I reflected the ActiveDirectoryRoleProvider, and found this loop in IsUserInRoleRecursive():
The problem is if array2 contains a group (if not only one group, and that group happens to be the last entry in array2). The loop will get a result from the recursive call, and return that value even if it's false, instead of keep searching the list (array2).