亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5095 | 回復: 0
打印 上一主題 下一主題

[ldap] [原]創(chuàng)建基于ldap的apache目錄驗證 [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-02-04 15:56 |只看該作者 |倒序瀏覽
創(chuàng)建基于ldap的apache目錄驗證

軟件:openldap
     ldapclient/server
     apache:添加mod_authz_ldap支持

1:設置ldap和創(chuàng)建ldap數(shù)據(jù)庫
apache的authz_ldap module通過匹配在ldap server中的attributetype:usePassword來驗證密碼,所以在ldap存儲設計中一定要使用這個attribute。而這個attribute是openldap所預先定義好的,它屬于inetOrgPerson這樣一個objectclass,我們設計的數(shù)據(jù)的objectClass就應該是inetOrgPerson或者它的一個子類。
這里有必要講一下ldap中的objectClass和attributetype。在我看來,objectClass就相當于普通數(shù)據(jù)庫中的一個table,attributetype就是table中的一個coloum。與數(shù)據(jù)庫中的table,coloum不同的是,ldap中的objectClass呈現(xiàn)一種類似與面向?qū)ο缶幊讨械睦^承關系,比如 organization->dcObject->top。top就是頂層objectClass,而 dcObject,organization都是“繼承”它而來。我們需要使用inetOrgPerson中的userPassword,因此可以直接用這個objectClass,也可以定義一個通過繼承它而來的objectClass。objectClass可以定義must和may兩種attributetype,意思是必須和不是必須的attributetype,在inetOrgPerson中sn和cn是必須的(我不知道這兩個具體代表什么意思),但我們并不需要它,因此我懷疑應該有其他不通過繼承inetOrgPerson來使用userPassword的方法,如果哪位高手明白的話,請不吝賜教。

好,說了一堆,現(xiàn)在正式來創(chuàng)建ldap數(shù)據(jù)項。

  1. attributetype (1.1.2.2.2.2
  2.          NAME 'userName'
  3.          DESC 'Employee User Name'
  4.          EQUALITY caseIgnoreMatch
  5.          SUBSTR caseIgnoreSubstringsMatch
  6.          SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE )

  7. objectclass (1.1.2.2.1
  8.         NAME 'Employee'
  9.         SUP inetOrgPerson
  10.         STRUCTURAL
  11.         MUST ( userName )
  12.     )
復制代碼

在這里我創(chuàng)建了一個叫rdpsUser的objectClass,SUP inetOrgPerson表示它是繼承inetOrgPerson而來,并且有一個必須的userName。這個userName使用來存儲網(wǎng)頁驗證時輸入的用戶名的,當然我們也可是使用inetOrgPerson已有的如sn來存儲,而且那樣的話都沒有必要建立一個新的objectClass,但在這里為了演示如何定義schema,并為了數(shù)據(jù)庫的易讀性,還是創(chuàng)建一個新的。

把它另存為/.../openldap/schema/what_ever_you_call_it.schema,然后在slapd.conf里將它include進去。重啟ldap以驗證schema的正確性。

現(xiàn)在來創(chuàng)建ldap的存儲結(jié)構,相當于創(chuàng)建數(shù)據(jù)庫的table
創(chuàng)建ldap init文件initial_create.ldif
  1. dn: dc=dps,c=us
  2. objectClass: organization
  3. objectClass: dcObject
  4. objectClass: top
  5. o: dps-us
  6. dc: dps

  7. dn: o=dps-us,dc=dps,c=us
  8. objectClass: organization
  9. objectClass: dcObject
  10. o: dps-us
  11. dc: dps

  12. dn: ou=employees,o=dps,dc=dps,c=us
  13. objectClass: organizationalUnit
  14. ou: employees
復制代碼

這里假設了slapd.conf里設置是這樣的
  1. suffix      "dc=dps,c=us"
  2. rootdn      "cn=Manager,dc=dps,c=us"
  3. rootpw            secret
復制代碼

注:這段使用來設置ldap服務器的root權限,不知道是否一定需要把ldap init文件的root dn設置為和suffix一樣,呼喚明白人

關閉ldap
  1. /etc/init.d/ldap stop
復制代碼

將數(shù)據(jù)庫定義導入ldap
  1. slapadd -v -l initial_create.ldif
  2. /etc/init.d/ldap start
復制代碼

注:我通過yum install安裝的ldap,第一次導入這些的時候出現(xiàn)了數(shù)據(jù)文件的owner不是ldap用戶的錯誤信息,使用chown改成ldap即可

導入數(shù)據(jù):
創(chuàng)建內(nèi)容為如下的data.ldif
  1. dn: userName=fduan,ou=employees,o=dps,dc=dps,c=us
  2. objectClass: top
  3. objectClass: inetOrgPerson
  4. objectClass: rdpsEmployee
  5. userPassword: {crypt}$1$d5TsJc7e$1qEaguOMwU9.89opV3BH1.
  6. userName: fduan
  7. sn: fduan
  8. cn: fduan
復制代碼

  1. ldapadd -x -D 'cn=Manager,dc=dps,c=us' -w secret -f data.ldif
復制代碼


注:userPassword可以使用明文和加密方式存儲,可以使用slappasswd來生成加密的字段,crypt是linux /etc/shadow的加密方式,所以可以使用ldap來存儲服務器用戶的密碼
  1. slappasswd -h{MD5} -s secret
  2. {MD5}Xr4ilOzQ4PCOq3aQ0qbuaQ==
復制代碼



2:為http服務目錄添加使用ldap驗證的功能
需要為apache安裝mod_authz_ldap,還有一個mod_auth_ldap的模塊,別搞混了.
假設需要添加驗證的目錄是/var/www/elog/
首先打開目錄.htaccess的override功能
  1. <Directory "/var/www/elog">
  2.     AllowOverride all
  3.     Order allow,deny
  4.     Allow from all
  5. </Directory>
復制代碼

在/var/www/elog里面創(chuàng)建.htaccess,添加如下內(nèi)容

  1. AuthzLDAPMethod ldap
  2. AuthName AuthzLDAP
  3. AuthType Basic

  4. AuthzLDAPServer "serverName"

  5. AuthzLDAPUserBase ou=employees,o=dps-us,dc=dps,c=us
  6. #這是存數(shù)據(jù)的DN
  7. AuthzLDAPUserKey userName
  8. #這是用來驗證的attributetype,所以說不一定要用userName
  9. AuthzLDAPLogLevel info
  10. Order deny,allow
  11. Deny from all
  12. require valid-user
  13. satisfy any
復制代碼



這樣應該通過ldap來做網(wǎng)頁的驗證了。

另:打開ldap的log
openldap的log默認是不打開的,要打開在/etc/syslog.conf或rsyslog.conf里面加入
  1. local4.*   -/var/log/ldap/ldap.log
復制代碼

[ 本帖最后由 redicaps 于 2009-2-5 14:08 編輯 ]
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP