YAFLogo

sean73269
  • sean73269
  • 51.8% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
I was wondering if anyone has found a simple way to connect AD with user login. I have seen the other posts about it and have tried them with little success. When I modify the web.config, the pages no longer load. I am wondering if it might be easier to modify the providers project code, then to play around with the webconfig?

Any help would be greatly appreciated.

Sean

Sponsor
fidley
  • fidley
  • 54.2% (Neutral)
  • YAF Forumling
15 years ago
I've done it in this way:

in web.config :

instead of

in IIS --> Directory security i've dissabled anonymous access and selected "Integrated Windows authentication" and "Digest authentication for Windows domain servers". I've choosen realm and applied changes.

Before you do that create at least your own domain user in forum and give him admin authorizations.

In Host admin settings: i removed possibility to register and to login and logout.

After you can login to your forum with your user, you can do simple script in sql for adding users from AD, you can use something similar to :

use forum

DECLARE @AD TABLE(

username varchar(50),

email varchar(200),

name varchar(200)

);

declare @co1 varchar(50),

@co2 varchar(200)

declare c cursor for select username, email from @AD

declare @cuid varchar(500)

declare @cuidint int

insert into @AD (username, email,name)

SELECT ('pl\' + sAMAccountName), mail, yusr.Name FROM OpenQuery(ADSI, 'SELECT sAMAccountName, displayName, mail, department FROM ''LDAP://OU=Users,DC=pl,DC=domain,DC=corp'' WHERE objectCategory=''user''')

full outer join dbo.yaf_user yusr

on yusr.Name = ('pl\' + sAMAccountName)

order by sAMAccountName;

delete from @AD where Name is not null

delete from @AD where email is null

open c

fetch next from c into @co1 , @co2

while @@fetch_status = 0

begin

exec [dbo].[yaf_prov_createuser] YetAnotherForum, @co1, "Password", null,null,@co2,null,null,1,null

set @cuid = (select userid from dbo.yaf_prov_Membership where username = @co1)

exec [dbo].[yaf_user_save] null,1, @co1, @co2,60, null, null, null,1,1,@cuid

exec [dbo].[yaf_prov_role_addusertorole] YetAnotherForum, @co1,'RoleName'

fetch next from c into @co1 , @co2

end

close c

deallocate c

go

sean73269
  • sean73269
  • 51.8% (Neutral)
  • YAF Forumling Topic Starter
15 years ago
Thanks for the help. However I am having issues getting the ADSI query to work with my SQL Server 2005. I have created the linked server, but is is throwing this error when I run the query "An error occurred while preparing the query "SELECT name FROM LDAP://DC=myDomain,DC=com WHERE objectCategory = 'Person' AND objectClass = 'user'" for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".

Did you have any errors like that?

Thanks again for the post

fidley
  • fidley
  • 54.2% (Neutral)
  • YAF Forumling
15 years ago
No , i haven't got any errors. I followed instruction from http://www.kodyaz.com/articles/active-directory-services-queries-using-openquery.aspx  and everything was working from the begining.
iarann
  • iarann
  • 56% (Neutral)
  • YAF Forumling
15 years ago
If you want to only add in real users (not contacts) and not disabled AD accounts then you can change the filter as follows

insert into @AD (username, email,name)

SELECT ('pl\' + sAMAccountName), mail, yusr.Name FROM OpenQuery(ADSI, 'SELECT sAMAccountName, displayName, mail, department FROM ''LDAP://OU=Users,DC=pl,DC=domain,DC=corp'' WHERE objectCategory = ''person'' AND objectClass = ''user'' AND ''userAccountControl:1.2.840.113556.1.4.803:'' <> 2')

full outer join dbo.yaf_user yusr

on yusr.Name = ('pl\' + sAMAccountName)

order by sAMAccountName;