473,402 Members | 2,050 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,402 software developers and data experts.

Checking the AUTH_USER against AD (and looking to see which group they're in)

I've been searching a lot for a simple example to search for a single
account name in active directory but have been unable to find what I'm
looking for. I did find an exmple (that worked) that pulls out all names in
the AD but that isn't what I need.

My goal is to check the AD for a username that matches
Request.ServerVariables("AUTH_USER"). That would be the first step. The next
step would be to see what security or distribution group they're in (in AD)
and redirect them based on that information.

This is the code that searches the entire directory and returns EVERYONE. I
suppose this would be useful only if I knew how to search the list for a
single name.

================================================== ====

Dim oroot As DirectoryEntry = New
DirectoryEntry("LDAP://corp.commspeed.net")
Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
Dim oresult As SearchResultCollection
Dim result As SearchResult

osearcher.Filter = "(&(objectCategory=person))" ' search filter
osearcher.PropertiesToLoad.Add("cn") ' username
'osearcher.PropertiesToLoad.Add("name") ' full name
'osearcher.PropertiesToLoad.Add("givenname") ' firstname
'osearcher.PropertiesToLoad.Add("sn") ' lastname
'osearcher.PropertiesToLoad.Add("mail") ' mail
'osearcher.PropertiesToLoad.Add("initials") ' initials
'osearcher.PropertiesToLoad.Add("ou") ' organizational unit
'osearcher.PropertiesToLoad.Add("userPrincipalName ") ' login name
'osearcher.PropertiesToLoad.Add("distinguishedName ") ' distinguised
name
oresult = osearcher.FindAll

For Each result In oresult
If Not result.GetDirectoryEntry.Properties("sn").Value Is
Nothing Then
' writes specific values retrieved from above - this is just
a sample.
Response.Write(result.GetDirectoryEntry.Properties ("cn").Value
& "<br />")
End If
Next

================================================== ====

Is there a way to rework that code above for my specific usage or is there
another route I need to take?

TIA,
Jim

Mar 6 '08 #1
1 1747
On Mar 6, 6:51*pm, "Jim in Arizona" <tiltow...@hotmail.comwrote:
I've been searching a lot for a simple example to search for a single
account name in active directory but have been unable to find what I'm
looking for. I did find an exmple (that worked) that pulls out all names in
the AD but that isn't what I need.

My goal is to check the AD for a username that matches
Request.ServerVariables("AUTH_USER"). That would be the first step. The next
step would be to see what security or distribution group they're in (in AD)
and redirect them based on that information.

This is the code that searches the entire directory and returns EVERYONE. I
suppose this would be useful only if I knew how to search the list for a
single name.

================================================== ====

Dim oroot As DirectoryEntry = New
DirectoryEntry("LDAP://corp.commspeed.net")
* * * * Dim osearcher As DirectorySearcher = New DirectorySearcher(oroot)
* * * * Dim oresult As SearchResultCollection
* * * * Dim result As SearchResult

* * * * osearcher.Filter = "(&(objectCategory=person))" ' search filter
Use

(&(objectCategory=Person)(cn=user_name_here))

or

(&(objectCategory=Person)(sAMAccountName=user_name _here))

Hope this helps
Mar 6 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jane Austine | last post by:
Is turning both re.UNICODE _and_ re.LOCALE flags on valid in Python 2.3? Doesn't it conflict each other? What is the semantics? Playing with \w and \b with both the flags on, it seemed re.UNICODE...
8
by: Michael Winter | last post by:
In a recent post ("About C error" by Victor, 21 Sep 2003), comments were made about the poster's use of macros. What I would like to know is why they are considered bad? I'm not referring to...
1
by: Jeremy | last post by:
I am using regular expressions and I would like to use both re.IGNORECASE and re.VERBOSE options. I want to do something like the following (which doesn't work): matsearch = r'''^\ {0,4}(\d+)...
4
by: Tech Witch | last post by:
We have a cluster set up at my office ( Active/Active ) that has been pitched as some prime real-estate, apparently, as the best place in the office for a database. Now it looks like one of my...
0
by: Xah Lee | last post by:
in the regex module re: Note: Match() is not exactly equivalent to Search() with "^". For example: re.search(r'^B', 'A\nB',re.M) # succeeds re.match(r'B', 'A\nB',re.M) # fails if without...
9
by: raghav4web | last post by:
I use a select box with a fix width (via stylesheet). So some of the entries are cut on the right side if they're too long. Is there a way to display them complete like a tool tip on a mouseover? ...
2
by: =?Utf-8?B?TGlhbQ==?= | last post by:
My Photos folder opens automatically on startup and re-opens instantly when I close it. Occasionally a small black banner appears and disappears with the words "My Photos" on it. My Photos keeps...
0
by: Chris | last post by:
Hello, I have a problem with re-loading datasets. As a simple example, if I have an SQL table of addresses comprising active and inactive addresss, I wish to load either sub-set by clicking on...
1
by: Peterwkc | last post by:
hello all expert database administrator, i truly new to access. I want to develop a website where the password and re-enter password must be same. How to i validate this in access or i need ti...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.