WindowsPrincipal.IsInRole fails when there is Whitespace in role n

  • Thread starter Thread starter F5F5F5
  • Start date Start date
F

F5F5F5

I use the following function to ascertain if the current user is in ann AD
security group. It appears to work, except if the group contains any space
characters, it always returns false.

For example I am a member of groups "NWDeveloper" and "IT Development"
if I call the function CurrentUserInRole(@"DOMAIN\NWDeveloper"); it returns
true, however CurrentUserInRole(@"DOMAIN\IT Development"); it returns false.

I need to be able to implement role-based security in a WinForm application,
unfortunately I am not in a position to change the security group names.

Thanks in advance.

Alan

----------------------------------------------------------------------------------------------
public static bool CurrentUserInRole(string role)
{

AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal principal =
(WindowsPrincipal)Thread.CurrentPrincipal;
return principal.IsInRole(role);
}
 
F5F5F5 said:
if I call the function CurrentUserInRole(@"DOMAIN\NWDeveloper"); it returns
true, however CurrentUserInRole(@"DOMAIN\IT Development"); it returns false.

In answer to my own problem, the answer appears to be me not quite knowing
what I was doing and being slightly hampered by coincidence.

It appears that I should use the group's Logon Name (pre-Windows 2000)
rather than Name (RDN). In the ones I tried, these had been set-up with to be
the same except the ones I tried with space characters. Although a space
character seems to be perfectly acceptable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top