基于URL的Apacheauthentication/ LDAP组

我正在为Apache2 HTTPD进行LDAP身份validation,并想知道是否有可能让Apache根据组进行LDAPvalidation,还取决于提供的URL。 例如,如果用户请求以下内容:

http://www.example.com/(组名)/

Apache将请求凭证并检查LDAP目录服务(OpenLDAP),以确保用户属于“<a group name>”组。 本质上,用户应该能够请求任意资源,Apache应该能够获取URL,提取被请求的特定资源,并确保用户属于同一个名称的组。

我找不到任何有关从URL请求中提取信息并处理Apacheconfiguration文件中的信息的相关信息。 有没有人做过类似的事情?

虽然我没有完全按照你的要求去做,但是我相对确定这是可能的。 在我的工作中,我们对ActiveDirectory服务器使用LDAP authn / authz。

您可以通过configuration具有各种AuthLDAP指令的Location标记来设置Apache以针对LDAP进行身份validation。 一个简单的例子使用sAMAccountName对AD:

 <Location /secured> AuthType Basic AuthzLDAPAuthoritative on AuthUserFile /dev/null AuthName "Authorization required" AuthBasicProvider ldap AuthLDAPURL "ldap://ldap.example.com/ou=MyOrg,dc=myDC,dc=myDC?sAMAccountName?sub?(objectClass=*)" AuthLDAPBindDN "ldapQueryUser" AuthLDAPBindPassword "ldapQueryPassword" require valid-user </Location> 

您似乎应该能够为每个<a group name>组设置位置,每个<a group name>使用不同的LDAP查询:

 <Location /group_A> AuthSetups blah blahblah AuthLDAPURL "ldap://ldap.example.com/ou=MyOrg,dc=group_A?..." </Location> <Location /group_B> AuthSetups blah blahblah AuthLDAPURL "ldap://ldap.example.com/ou=MyOrg,dc=group_A?..." </Location> 

在使用Apache和LDAP时,我发现最好的方法是在尝试将其集成到Apache之前正确返回用户。 我的错误几乎每次都是LDAP错误,所以使查询正确使apache authn / z部分变得简单。

您可以使用虚拟主机来匹配位置,无论是通过位置还是位置匹配。

下面是一个针对Apache 2.4进行更新的示例,并在查询ActiveDirectory的Windows 2012 Server上运行(重点放在LocationMatch部分):

 <VirtualHost *:80> WSGIScriptAlias /bloodhound C:/apache/bloodhound/installer/bloodhound/site/cgi-bin/trac.wsgi <Directory C:/apache/bloodhound/installer/bloodhound/site/cgi-bin> WSGIApplicationGroup %{GLOBAL} Require all granted <Files trac.wsgi> Require all granted </Files> </Directory> LogLevel debug <LocationMatch "/bloodhound/([^/]+/)?login"> AuthLDAPURL "ldap://<HOST_NAME>:3268/<SEARCH_BASE>?sAMAccountName?sub?(objectClass=user)" AuthLDAPBindDN "<BIND_DN>" AuthLDAPBindPassword "<PASSWORD>" LDAPReferrals Off AuthType Basic AuthName "Bloodhound - Please Provide Your Credentials" AuthBasicProvider ldap #If you want to use an LDAP Filter, #uncomment the following and use instead of the ldap-group and subsequent config #Require ldap-filter memberof:1.2.840.113556.1.4.1941:=<GROUP_DN> Require ldap-group <GROUP_DN> AuthLDAPMaxSubGroupDepth 1 AuthLDAPSubgroupAttribute member AuthLDAPSubGroupClass group AuthLDAPGroupAttribute member AuthLDAPGroupAttributeIsDN on </LocationMatch> 

另一种方法是用@khoxsey的build议。 但是,如果您更好地满足您的需求,则可以使用LocationMatch而不是Location。