469,291 Members | 1,788 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,291 developers. It's quick & easy.

WindowsPrincipal.IsInRole fails when there is Whitespace in role n

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(Princip alPolicy.WindowsPrincipal);
WindowsPrincipal principal =
(WindowsPrincipal)Thread.CurrentPrincipal;
return principal.IsInRole(role);
}
Jan 4 '08 #1
1 3378


"F5F5F5" wrote:
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.
Jan 7 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Mark | last post: by
5 posts views Thread by arjun | last post: by
2 posts views Thread by Dave | last post: by
8 posts views Thread by Oliver Rainer | last post: by
reply views Thread by wk6pack | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.