SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


check AD membership


check AD membership

Author
Message
chandrika5
chandrika5
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 360
Comments posted to this topic are about the item check AD membership
Nicholas Cain
Nicholas Cain
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7076 Visits: 6200
I am unable to get this to work.

I've replaced the with my AD information, however get an error. Having performed ADSI queries before I am not sure how this would return results as there does not appear to be any select performed against the AD itself.

What am I missing here?



Shamless self promotion - read my blog http://sirsql.net
chandrika5
chandrika5
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 360
What is the error?
This is in production for over an year. I've put this up here after several months of being "in production".
Nicholas Cain
Nicholas Cain
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7076 Visits: 6200
I found the problem, I mistakenly removed the <> around the LDAP details, it works now.

Thanks, great script, something I have desperately needs for a while.



Shamless self promotion - read my blog http://sirsql.net
chandrika5
chandrika5
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 360
You are welcome. Smile
NeddyRock
NeddyRock
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 51
Awesome script. I can't thank you enough.

Ned
chandrika5
chandrika5
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 360
You are welcome.
Dave62
Dave62
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3549 Visits: 2831
You're right to call this a work around. Since you're using ASP and AD, wouldn't it be easier (perhaps a little more sophisticated) to have a common function called when each page loads that checks the groups the authenticated user belongs to. There are a lot of scripts available to return the information directly from server-side code without having to go through all the SQL Server configurations and making the additional database call to check AD. Here's one example:


Option Explicit

' NOTE: Replace YOUR_DOMAIN in the Select statement with the name of your AD Domain

Dim strGroup 'The AD group being checked
Dim strMessage
Dim GroupDN
Dim oConn, oCmd, oRS
Dim oGroup, oMember

strGroup = "AD Group Name"

Const ADS_SCOPE_SUBTREE = 2

Set oConn = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")

oConn.Provider = "ADsDSOObject"
oConn.Open "Active Directory Provider"
Set oCmd.ActiveConnection = oConn

oCmd.Properties("Page Size") = 1000
oCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE

'Return all the members of the group
oCmd.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=YOUR_DOMAIN,dc=com' WHERE objectCategory = 'group' And CN = '" & strGroup & "'"
Set oRS = oCmd.Execute

oRS.MoveFirst
Do Until oRS.EOF
GroupDN = oRS.Fields("distinguishedName").Value
Set oGroup = GetObject("LDAP://" & GroupDN)

For Each oMember In oGroup.Members
strMessage = strMessage & oMember.sAMAccountName & chr(13)
Next
oRS.MoveNext
Loop

msgbox strMessage, vbInformation, "Members of [" & strGroup & "]"

' Clean up
Set oMember = Nothing
Set oGroup = Nothing
Set oRS = Nothing
Set oCmd = Nothing
Set oConn = Nothing



This script will display the members of an AD group in a message box. It can easily be modified and put into a common function that checks if the authenticated user belongs to a particular group(s) and return True or False to the calling page.
chandrika5
chandrika5
SSChasing Mays
SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)SSChasing Mays (651 reputation)

Group: General Forum Members
Points: 651 Visits: 360
I am not sure how many people write new classic ASPs these days. Portability is the key here. I can deploy this SP in several SQL instances, and give developers access to this.: ASP or JSP or PHP etc. The SP is independent of web authoring server side language.
Dave62
Dave62
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3549 Visits: 2831
chandrika5 (2/8/2013)
I am not sure how many people write new classic ASPs these days. Portability is the key here. I can deploy this SP in several SQL instances, and give developers access to this.: ASP or JSP or PHP etc. The SP is independent of web authoring server side language.


Good points but it will most likely depend on where the solution is needed. I gave classic ASP code because that was mentioned in your article. A similar function can easily be ported to .NET where it can be used by many languages. Having this simple function in the front-end means it will work with a variety of back-end databases (SQL Server, MySQL, Postgre, Oracle, ...) as well as all the .NET front-end languages.

Putting all the effort needed to make it work in an SP means it can work with a few other languages that are not .NET but will not work with any other databases.

So I guess either approach can be fine depending on the environment.

Enjoy!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search