Skip to content

Quick and Easy Security From Threads

January 21, 2009

Sometimes we can use Active Directory for our application security.  There are a number of ways to attack the problem including the oft painful LDAP.  If we need to check to see if the current user is a member of an AD group we can do it thus:

// We can start by making sure that our current principal is set correctly as it probably isn’t.

 Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());

// Then we can save some time with an obvious check 

if (Thread.CurrentPrincipal.Identity.IsAuthenticated)


// Now we have only to specify the name of the group in AD.  Here I have

// the name “XXX_Administrators” refrenced from the resource file.

if (Thread.CurrentPrincipal.IsInRole(Properties.Resources.AdminRole))


return SecurityGroup.Administrators;


No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: