IIS basic authentication using LDAP

2019-04-28 11:06发布

问题:

I have a web service which needs to use HTTP authentication with IIS. The only hurdle is that the user's credentials are in LDAP. Is there a way to configure IIS to use LDAP credentials for it's basic authentication? I thought I could set the default domain or realm to part of the LDAP connection string, but haven't had any luck. Thanks,

-Will

回答1:

What I would do (I'm assuming you're using a third party LDAP, and that there isn't a built in way of doing this; I haven't checked) is set up MADAM and implement a custom IUserSecurityAuthority by extending Madam.UserSecurityAuthorityBase to check the credentials against LDAP.

All you will have to do is override a handful of methods to authenticate from LDAP. If you happen to be using an LDAP Membership Provider for forms authentication, you can skip implementing that separately and use the example MembershipSecurityAuthority included with MADAM.

Excerpt from that example file here:

protected override bool ValidateUser(string userName, string password)
{
    return MembershipProvider.ValidateUser(userName, password);
}

Potentially useful LDAP user validation code



回答2:

There is a codeplex project that looks like it has exactly what you need.

It has a great Search function so you can even test what Roles the user is in.

http://ldapwebservice.codeplex.com/