Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 745
  • Last Modified:

Difficulty Quering Active Directory on MemberOf

I 'm working on adding security to an internal web app.  I'm trying to program it to check the groups the logged in user belongs to.  If they belong to the required group(s) then the program will give the user access.

I'm making it so members of TELMIS will have admin access.  When I try to login it queries for my groups but it returns everything except TELMIS.  I figured it may be because TELMIS is set as my primary group in AD.  So I changed my primary group to another group.  Then, TELMIS is returned but the one I set to primary isn't.  I don't understand why it won't return the primary group in the list of groups.  Can someone explain and help me modify my code to get this to work.

        Using de As New DirectoryEntry("LDAP://" + MyDomain)

            Using deSearch As New DirectorySearcher()
                deSearch.PageSize = 8000
                deSearch.SearchRoot = de
                deSearch.Asynchronous = True
                deSearch.Filter = "(&(objectClass=user)(userprincipalname=" + Username() + "))"

                Dim result As SearchResult = deSearch.FindOne()
                If result Is Nothing Then
                    Return False
                End If

                If result.Properties.Contains("memberof") Then
                    For Each item In result.Properties("memberof") ' collection

                        Dim value As String = item.ToString()
                        If value.Contains("CN=TELMIS") Then
                            Return True
                        End If
                    Next

                End If

            End Using

        End Using


Thanks
0
ScottMacMaster
Asked:
ScottMacMaster
  • 2
1 Solution
 
ColosseoCommented:
Hi Scott

Basically the primary group doesnt appear in the memberof collection it is accessed sperately:

Have a look at this, http://support.microsoft.com/kb/321360

Am looking just now at how you can implement this

Regards

Scott
0
 
ScottMacMasterAuthor Commented:
Well, I can understand not storing the primary group in the list of groups to save space.  However, why force end users to query 2 different things to find out if if a user if a member of a group.  AD could at least return the primary group amoung the list of members.  Well, I guess I just need to add code to get the primary group.  Any chance you know of a reference that shows how to do that in VB.NET not ADSI?

Thanks
0
 
ScottMacMasterAuthor Commented:
Oh, I can just use the global variable 'User'.  I've always used it to get the name of the logged in user.  I can use User.IsInRole("TELMIS") to check the users membership.  And it works whether the group is primary or not.


Thanks,
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now