免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8127 | 回复: 4

[ldap] APACHE + LDAP 的权限认证配置方法 [复制链接]

论坛徽章:
0
发表于 2005-10-14 16:51 |显示全部楼层
APACHE + LDAP 的权限认证配置方法

作者:李治 (ddcopy@263.net)
版本:1.0.2005.1014
MSN:zli@censoft.com.cn

一、前言

    很多朋友希望利用 Apache 通过 LDAP 进行用户认证及权限管理。
    通过多次试验,总结出以下方法,与大家共享。
   
    配置思路:对用户通过“组(groups)”进行管理,对于需要权限控制的目录,
    则通过“组”进行控制。

    参考:
        http://www.moocky.net/Manual/apache/mod/mod_auth_ldap.html
        http://bbs.chinaunix.net/forum/viewtopic.php?t=618651


二、用户需求

1. 用户结构:
    YourComp
        |- groups (departments)
        |    |- grp1 (dep1)
        |    |    |- user1
        |    |    \- user2
        |    |- grp2 (dep2)
        |    |    |- user3
        |    |    \- user4
        |    \- grp3 (dep3)
        |        |- user2
        |        \- user3
        \- members (employees)
            |- user1
            |- user2
            |- user3
            \- user4
            

2. 目录权限:
    AppsDir
        |- Dir1    允许 grp1 访问
        |- Dir2    允许 grp2 访问
        \- Dir3    允许 grp1, grp3 访问
        

三、配置步骤

1. 建立 LDAP 基础记录,BaseDn.ldif 文件:
   
    dn: dc=YourComp
    dc: YourComp
    objectClass: domain
   
    dn: ou=members,dc=YourComp
    ou: members
    objectClass: organizationalUnit
   
    dn: ou=groups,dc=YourComp
    ou: groups
    objectClass: organizationalUnit

2. 建立 LDAP 用户记录,UserDn.ldif 文件:
   
    dn:cn=user1,ou=members,dc=YourComp
    cn: user1
    sn: USER1
    uid: user1
    userPassword: user1
    objectClass: inetOrgPerson
   
    dn:cn=user2,ou=members,dc=YourComp
    cn: user2
    sn: USER2
    uid: user2
    userPassword: user2
    objectClass: inetOrgPerson
   
    dn:cn=user3,ou=members,dc=YourComp
    cn: user3
    sn: USER3
    uid: user3
    userPassword: user3
    objectClass: inetOrgPerson
   
    dn:cn=user4,ou=members,dc=YourComp
    cn: user4
    sn: USER4
    uid: user4
    userPassword: user4
    objectClass: inetOrgPerson

3. 建立 LDAP 用户组记录,GroupDn.ldif 文件:
   
    dn: cn=grp1,ou=groups,dc=YourComp
    cn: grp1
    objectClass: groupOfUniqueNames
    objectClass: top
    uniqueMember: cn=user1,ou=members,dc=YourComp
    uniqueMember: cn=user2,ou=members,dc=YourComp
   
    dn: cn=grp2,ou=groups,dc=YourComp
    cn: grp2
    objectClass: groupOfUniqueNames
    objectClass: top
    uniqueMember: cn=user3,ou=members,dc=YourComp
    uniqueMember: cn=user4,ou=members,dc=YourComp
   
    dn: cn=grp3,ou=groups,dc=YourComp
    cn: grp3
    objectClass: groupOfUniqueNames
    objectClass: top
    uniqueMember: cn=user3,ou=members,dc=YourComp
    uniqueMember: cn=user2,ou=members,dc=YourComp

4. 运行 ldapadd 添加记录

    添加根记录:
    ldapadd -x -D "cn=root,dc=YourComp" -w secret -f BaseDn.ldif

    添加用户记录:
    ldapadd -x -D "cn=root,dc=YourComp" -w secret -f UserDn.ldif

    添加用户组记录:
    ldapadd -x -D "cn=root,dc=YourComp" -w secret -f GroupDn.ldif

5. 建立 Apache 配置文件,application_auth.conf:
   
    <Location /AppsDir>;
        AuthType Basic
        AuthName "lease login"
            
        AuthLDAPEnabled on
        AuthLDAPAuthoritative on
        AuthLDAPURL "ldap://localhost/dc=YourComp?uid?sub?(objectClass=*)"
    </Location>;
   
    <Location /AppsDir/dir1>;
        require group cn=grp1,dc=YourComp
    </Location>;
     
    <Location /AppsDir/dir2>;
        require group cn=grp2,dc=YourComp
    </Location>;
   
    <Location /AppsDir/dir3>;
        require group cn=grp1,dc=YourComp cn=grp3,dc=YourComp
    </Location>;

6. 在 httpd.conf 文件中,加入以下行:

    include conf/application_auth.conf

论坛徽章:
0
发表于 2005-10-14 17:47 |显示全部楼层

APACHE + LDAP 的权限认证配置方法

看来你的研究越来越深入了,好文

论坛徽章:
0
发表于 2005-10-15 01:53 |显示全部楼层

APACHE + LDAP 的权限认证配置方法

Another way, read Step 9 in:

http://web.singnet.com.sg/~garyttt/Installing%20and%20configuring%20OpenLDAP%20for%20Solaris9.htm
Installing and configuring OpenLDAP for RedHat Enterprise Linux3

===
Step 9: Configure “Apache” to use LDAP Authentication

The auth_ldap modules built-into Apache 2 is “experiemental” and may not be stable, you may use:

Apache 1.X: http://www.muquit.com/muquit/software/mod_auth_ldap/mod_auth_ldap.html
Apache 2.X: http://www.muquit.com/muquit/software/mod_auth_ldap/mod_auth_ldap_apache2.html

Apache must be built with .so (shared object) support and SSL support if StartTLS is used.

To configure Apache2 with shared object and SSL support:

./configure --enable-so --enable-ssl --with-ssl-dir=/usr/local/ssl

(Refer to the URL above for Apache 1.X syntax)

IMPORTANT NOTE: DO NOT add --enable-ldap or --enable-auth-ldap or --with-ldap, to the above, they are for the "experiemental" ldap module support built-into Apache 2.x, and they DID NOT work for me, no sure of experience of others.

To configure “mod_auth_ldap” from muquit.com:

# OpenLDAP
./configure --with-apxs=/usr/local/apache2/bin/apxs --with-ldap-dir=/usr/local

# iPlanet LDAP
./configure --with-apxs=/usr/local/apache2/bin/apxs --with-ldap-dir=/usr

After that, modify httpd.conf, add the following lines in GREEN for testing purposes.

LoadModule auth_ldap_module modules/mod_auth_ldap.so

Alias /syslog "/var/log/"

<Directory "/var/log/">;
Options Indexes FollowSymLinks MultiViews IncludesNoExec ExecCGI
AddOutputFilter Includes html
AllowOverride All
Order allow,deny
Allow from all
</Directory>;

<Location /syslog>;
AuthType Basic
AuthName "syslog"
require valid-user
#LDAP_Debug On
#LDAP_StartTLS On
LDAP_Server ldap1.example.com
# Add SLAVE LDAP Server for failover
LDAP_Server ldap2.example.com
LDAP_Port 389
Base_DN dc=example,dc=com
UID_Attr uid
</Location>;


Restart httpd, and test this URL:

http://apache.example.com/syslog/

===

论坛徽章:
0
发表于 2005-10-17 14:31 |显示全部楼层

APACHE + LDAP 的权限认证配置方法

在Windows环境下,Apache 自带的 mod_auth_ldap 模块是不能正常运行的,必须进行调整。需要以下文件:
=>;[modauthldap_apache2_dll.zip]
=>;[ldapcsdk5.08-WINNT4.0_OPT.OBJ.zip] (需要注册用户,可以用我的ddcopy:ddcopy,也可以下载本帖的附件)

复制 mod_auth_ldap 模块文件
cp -f modauthldap_apache2_dll/*.dll apache/modules

复制 Sun_ONE_Directory_SDK_for_C_5.08 运行环境文件
cp -f Sun_ONE_Directory_SDK_for_C_5.08/*.dll apache/modules

建立 Apache 配置文件,application_auth.conf:
   
    (1) For Windows 环境:
    <Location /AppsDir>;
        AuthType Basic
        AuthName "lease login"

        LDAP_Server localhost
        LDAP_Port 389
        LDAP_Protocol_Version 3

        Base_DN "dc=YourComp"
        UID_Attr "uid"
    </Location>;

    <Location /AppsDir/dir1>;
        require group cn=grp1
    </Location>;
     
    <Location /AppsDir/dir2>;
        require group cn=grp2
    </Location>;
   
    <Location /AppsDir/dir3>;
        require group cn=grp1 cn=grp3
    </Location>;

    (2) For Linux 环境:
    <Location /AppsDir>;
        AuthType Basic
        AuthName "lease login"
            
        AuthLDAPEnabled on
        AuthLDAPAuthoritative on
        AuthLDAPURL "ldap://localhost/dc=YourComp?uid?sub?(objectClass=*)"
    </Location>;
   
    <Location /AppsDir/dir1>;
        require group cn=grp1,dc=YourComp
    </Location>;
     
    <Location /AppsDir/dir2>;
        require group cn=grp2,dc=YourComp
    </Location>;
   
    <Location /AppsDir/dir3>;
        require group cn=grp1,dc=YourComp cn=grp3,dc=YourComp
    </Location>;

第2个文件

第2个文件

第1个文件 (下载后,修改后缀)

第1个文件 (下载后,修改后缀)

论坛徽章:
0
发表于 2005-10-17 14:45 |显示全部楼层

APACHE + LDAP 的权限认证配置方法

第三个文件
Sun_ONE_SDK-Mod_auth_ldap.part3.rar.jpg
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP