473,413 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

LDAP - User's Group Lookup

My problem is that I can find the user using the CN='Full Name'
I only have User.Identity.Name ='username\domain'

I need find out what groups the user is in.

Using:
ISS 6 on Windows 2003
VB.NET

Expand|Select|Wrap|Line Numbers
  1.         'domain\username
  2.         Dim _authenUser As String = HttpContext.Current.User.Identity.Name.ToString
  3.  
  4.  
  5.         Dim _path As String = "LDAP://CN=Users,DC=Domain,DC=com"
  6.         Dim _filterAttribute As String = "My Full Name"
  7.         Dim _SearchGroup As String = "CN=GroupName,OU=Goups,DC=Domain,DC=com"
  8.         Dim search As DirectoryServices.DirectorySearcher = New DirectoryServices.DirectorySearcher(_path)
  9.         search.Filter = "(cn=" + _filterAttribute + ")"
  10.         search.PropertiesToLoad.Add("memberOf")
  11.         Dim strcol As New System.Collections.Specialized.StringCollection
  12.  
  13.         ' search.PropertiesToLoad.Add()
  14.         Dim myresult As DirectoryServices.SearchResult = search.FindOne
  15.  
  16.         Dim mygroup As DirectoryServices.ResultPropertyValueCollection = myresult.Properties.Item("MemberOf")
  17.         For i As Int16 = 0 To mygroup.Count - 1
  18.             If mygroup.Item(i).ToString = _SearchGroup Then
  19.                 Return True
  20.             Else
  21.                 Return False
  22.             End If
  23.         Next
  24.  
Oct 12 '06 #1
1 11574
Found it:


Instead of checking cn use SAMAccountName
Expand|Select|Wrap|Line Numbers
  1. search.Filter = "(cn=" + _filterAttribute + ")"
  2.  
Use This:
Expand|Select|Wrap|Line Numbers
  1. 'Authenication is working!
  2. if (HttpContext.Current.User.Identity.IsAuthenticated)
  3.   Dim _authenUser As String = HttpContext.Current.User.Identity.Name.ToString
  4.   Dim _filterAttribute As String = Split(_authenUser, "\")(1) ' Remove domain
  5. else
  6.   return false
  7. end if
  8.  
  9. search.Filter = "(SAMAccountName=" + _filterAttribute + ")"
  10.  
Complete Code:
Expand|Select|Wrap|Line Numbers
  1. 'domain\username
  2. if (HttpContext.Current.User.Identity.IsAuthenticated)
  3.   Dim _authenUser As String = HttpContext.Current.User.Identity.Name.ToString
  4.   Dim _filterAttribute As String = Split(_authenUser, "\")(1) ' Remove domain
  5. else
  6.   return false
  7. end if
  8.  
  9.   Dim _path As String = "LDAP://CN=Users,DC=Domain,DC=com"
  10.   Dim _SearchGroup As String = "CN=GroupName,OU=Goups,DC=Domain,DC=com"
  11.   Dim search As DirectoryServices.DirectorySearcher = New DirectoryServices.DirectorySearcher(_path)
  12.   search.Filter = "(SAMAccountName=" + _filterAttribute + ")"
  13.   search.PropertiesToLoad.Add("memberOf")
  14.   Dim strcol As New System.Collections.Specialized.StringCollection
  15.  
  16.   ' search.PropertiesToLoad.Add()
  17.   Dim myresult As DirectoryServices.SearchResult = search.FindOne
  18.  
  19.   Dim mygroup As DirectoryServices.ResultPropertyValueCollection = myresult.Properties.Item("MemberOf")
  20.   For i As Int16 = 0 To mygroup.Count - 1
  21.      If mygroup.Item(i).ToString = _SearchGroup Then
  22.         Return True
  23.      Else
  24.         Return False
  25.     End If
  26.   Next
  27.  
Oct 12 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: dmcconkey | last post by:
Hi folks, I've been searching for a while and haven't found my specific question anywhere else. If this has already been asked, please accept my appologies and point me to the appropriate...
0
by: Mike | last post by:
I'm using ASP and CDO to lookup free busy time on an e2k server. The E2K is locally installed on the IIS server and I'm having no problems accessing resources like public folders, mailboxes, etc....
2
by: CodeRazor | last post by:
I am trying to create an LDAP connection. I have managed to connect to "LDAP://myServerName" I now want to connect further down the directory tree, to a particular user group. I have tried...
3
by: mrwoopey | last post by:
Hi, I am using the example "Authenticate against the Active Directory by Using Forms Authentication and Visual Basic .NET": http://support.microsoft.com/default.aspx?scid=KB;EN-US;326340 ...
3
by: Jay | last post by:
I have a simple LDAP query (grabs all users from a particular AD group and populates a checkboxlist) that works perfectly fine on the development machine logged on locally as any user. When I...
3
by: Chad Beckner | last post by:
I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't...
4
by: Terry Miller | last post by:
I have DB2 V8.2 loaded on a Redhat Enterprise Linux version 3 (RHEL 3) box. RHEL is configured to talk to LDAP for authenticaton besides the local passwd file. I can verify this by executing an su...
2
by: duncan beaumont | last post by:
Hi, - SQLserver 2000 - Yellowfin 2.4 - Windows 2003 server I have been asked to investigate seting up LDAP authentication to access our Yellowfin reporting.
0
williak
by: williak | last post by:
Hi I am new to this forum so if I make a mistake in protocol let me know. OK I have been asked to convert my existing ASP application to make users authenticate with our LDAP servers before...
0
by: rbukkara | last post by:
Hi, I have got the following error while trying to add a user in the LDAP Directory. javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu' I have...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.