Try our conversational search powered by Generative AI!

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).

 

#74673
Sep 04, 2013 15:52
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.