站內搜尋:Yahoo搜尋的結果,如果沒有給完整的網址,請在站內再搜尋一次!

顯示具有 OpenLDAP 標籤的文章。 顯示所有文章
顯示具有 OpenLDAP 標籤的文章。 顯示所有文章

2011-10-18

LDAP參考資料:LDAP Schema Design

資料來源官方網站: http://www.skills-1st.co.uk/papers/ldap-schema-design-feb-2005/index.html
官方網站資料下載連結: http://www.skills-1st.co.uk/papers/ldap-schema-design-feb-2005/ldap-schema-design-feb-2005.pdf

2011-10-16

使用JXplorer來查詢所連接的LDAP server有哪些objectClasses可以選用?每個objectClass又包含了哪些Attributes(屬性)?

在前一篇『在ubuntu下,使用webmin管理OpenLDAP』中,曾提到使用JXplorer(http://jxplorer.org/)來測試與OpenLDAP間的連線。JXplorer是一個很棒的LDAP工具軟體,在建構與管理LDAP的過程,JXplorer可以提供很大的幫忙!

確認正確安裝OpenLDAP後,最重要的一件事,就是根據需求建構LDAP,但要如何配置?該引用哪些objectClasses呢?
JXplorer提供了Schema(綱要)瀏覽的功能,連上LDAP server後,即可透過JXplorer瀏覽有哪些objectClasses可以選用?每個objectClass又包含了哪些Attributes?

根據上圖:
在左側的選單欄,選擇『綱要』這個分頁頁籤,選擇Schema下的objectClasses,在objectClasses這個節點下,列出了目前可以使用的objectClass。
以圖例中這個account objectClass為例:

  1. attribute type為MUST,表示這個資料屬性欄位必須輸入資料。
  2. attribute type為MAY,表示這個資料屬性欄位沒有強制要輸入資料。

2011-09-04

VB.net 連接 LDAP 的程式碼範例及解說

  1. 在透過程式碼連接存取LDAP,先了解一下LDAP對使用者存取的限制,掌握了存取限制的性後,對於程式碼的編寫,有非常大的幫助。
  2.  以下要說明的LDAP存取,具有以下的特性:
    每個使用者的User DN,所在的路徑是不一定的,例如:
    uid=user01,ou=dept1,ou=people,dc=abc,dc=edu,dc=tw
    uid=user21,ou=dept11,ou=dept1,ou=people,dc=abc,dc=edu,dc=tw
    uid=user55,ou=dept36,ou=dept5,ou=people,dc=abc,dc=edu,dc=tw
    系統提供一個檢視瀏覽LDAP內容的User DN
    LDAP主機使用Linux的OpenLDAP,ou可能會使用中文來命名
接下來說明程式碼:
  1. 在專案中的『My Project』的『參考』加入:System.DirectoryServices
  2. 定義一個字串,設定LDAP主機的所在位置(LDAP://ldap.abc.edu.tw/),及登入預設的Base DN位置 (ou=people,dc=abc,dc=edu,dc=tw)
    Dim strLDAP as String = "LDAP://ldap.abc.edu.tw/ou=people,dc=abc,dc=edu,dc=tw"
  3. 將系統提供可以檢視瀏覽LDAP內容的User DN,定義為一個字串
    Dim strUID as String = "uid=xadmin,ou=people,dc=abc,dc=edu,dc=tw"
  4. 定義上述strUID所對應的密碼字串
    Dim strPWD  as String = "password"
  5. 定義並初始化一個LDAP物件,並使用LDAP系統提供的帳號登入
    Dim oLdapEntry As DirectoryEntry = New DirectoryEntry(strLDAP, strUID, strPwd, AuthenticationTypes.ServerBind)
  6. 使用LDAP系統提供的帳號登入成功後,再定義初始化一個LDAP搜尋物件
    Dim oLdapSearcher As DirectorySearcher = New DirectorySearcher(oLdapEntry)
  7. 將要進行LDAP驗證的使用者帳號、密碼,定義如下:
    Dim strUserID as String = "UserAcc"
    Dim strUserPWD as String = "UserPwd"
  8. 將進行LDAP登入驗證的使用者,設定為一個搜尋字串
    oLdapSearcher.Filter = "(uid=" & strUserID & ")"
  9. 定義並初始化,以使用者搜尋字串,所取得的搜尋結果
    Dim oSearchResult As SearchResult = oLdapSearcher.FindOne
  10. 如果可以取得搜尋結果,再從搜尋結果中,取得這個使用者在LDAP伺服器的User DN路徑
    Dim strUserLdapPath As String = oSearchResult.Path.ToString
    結果的字串範例:
    LDAP://ldap.abc.edu.tw/uid=UserAcc,ou=dept1,ou=people,dc=abc,dc=edu,dc=tw
  11. 接下來要利用strUserLdapPath這個字串來組合出,要以使用者身分登入的基本資料:
    Dim strUserUid As String = strUserLdapPath.Replace("LDAP://ldap.abc.edu.tw/", "")
    將LDAP://ldap.abc.edu.tw/uid=UserAcc,ou=dept1,ou=people,dc=abc,dc=edu,dc=tw這個字串中的LDAP://ldap.abc.edu.tw/移除,就可以得到這個User的 User DN。
  12. 將strUserLdapPath字串中,所取得的字串內容,移除uid相關內容,就可以取得這個使用者要登入的LDAP網址及Base DN
    Dim strUserDN As String = strUserLdapPath.Replace("uid=" & strUserID & ", ", "")
  13. 使用上述取得的strUserUid及strUserDN(即:使用者的身分)登入LDAP
    Dim oUserLdapEntry As DirectoryEntry = New DirectoryEntry(strUserDN, strUserUid, strUserPWD, AuthenticationTypes.FastBind)
  14. 確認oUserLdapEntry已成功初始化,以使用者帳號密碼,向LDAP伺服器進行存取的驗證,就算成功了...

AuthenticationTypes可以使用的成員,如下述:
參考:http://msdn.microsoft.com/zh-tw/library/system.directoryservices.authenticationtypes%28v=vs.80%29.aspx
成員名稱 說明
Anonymous 未執行驗證。 
Delegation 啟用 Active Directory 服務介面 (ADSI) 來委派使用者安全性內容,將物件橫跨網域移動時會需要這項內容。 
Encryption 將加密簽章附加至訊息,該簽章會識別傳送者,並確保訊息不會在傳送時遭受修改。 
FastBind 指定 ADSI 不會嘗試查詢 Active Directory objectClass 屬性。因此,只會公開 (Expose) 所有 ADSI 物件都支援的基底介面。該物件所支援的其他介面則不可用。使用者可以用這個選項,來提高只涉及基底介面方法的一系列物件管理效能。不過,ADSI 不會確認所要求的物件是否確實存在於伺服器上。如需詳細資訊,請參閱 MSDN Library (http://msdn.microsoft.com/library/cht) 中的<可進行批次寫入/修改作業的快速繫結選項>主題 (英文)。如需 objectClass 屬性的詳細資訊,請參閱 MSDN Library (http://msdn.microsoft.com/library/cht) 中的 Object-Class 主題。 
None 等於零,意味著在 LDAP 提供者中使用基本驗證 (簡單連結)。 
ReadonlyServer 對於 WinNT 提供者來說,ADSI 會嘗試連接至網域控制站。對於 Active Directory 來說,這個旗標指示無伺服器繫結並不需要可寫入的伺服器。 
Sealing 使用 Kerberos 加密資料。同時 Secure 旗標必須設定為使用密封。 
Secure 要求安全驗證。當這個旗標設定時,WinNT 提供者會使用 NTLM 驗證用戶端。Active Directory 會使用 Kerberos 驗證用戶端,也可能使用 NTLM 驗證。當使用者名稱和密碼為 null 參考時 (在 Visual Basic 中為 Nothing),ADSI 會使用呼叫執行緒的安全性內容繫結至物件,它是應用程式在其下執行之使用者帳戶的安全性內容,或者是模擬呼叫執行緒之用戶端使用者帳戶的安全性內容。 
SecureSocketsLayer 將加密簽章附加至訊息,該簽章會識別傳送者,並確保訊息不會在傳送時遭受修改。Active Directory 需要有安裝憑證伺服器,才能支援 Secure Sockets Layer (SSL) 加密。 
ServerBind 如果您的 ADsPath 包括伺服器名稱,則在使用 LDAP 提供者時指定這個旗標。請不要為包括網域名稱的路徑或無伺服器路徑使用這個旗標。指定伺服器名稱時不指定這個旗標會導致不必要的網路流量。 
Signing 確認資料的完整性,以確保所接收的資料與傳送的資料相同。同時 Secure 旗標必須設定為使用簽名。 

2011-08-07

在ubuntu上安裝OpenLDAP

參考資料:
https://help.ubuntu.com/11.04/serverguide/C/openldap-server.html
https://help.ubuntu.com/10.04/serverguide/C/openldap-server.html

  1. 安裝OpenLDAP的daemon程式 slapd 及 ldap-utils
    sudo apt-get install slapd ldap-utils
  2. 再加入一些schema的檔案:
    sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
    sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
    sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
    在ubuntu11.04版中,應該已加入以上三個schema,所以會出現 Duplicate attributeType的訊息。
  3. 建立以下的LDIF檔案內容(backend.example.com.ldif),將檔案存放在自行指定的位置:
    # Load dynamic backend modules
    dn: cn=module,cn=config
    objectClass: olcModuleList
    cn: module
    olcModulepath: /usr/lib/ldap
    olcModuleload: back_hdb

    # Database settings
    dn: olcDatabase=hdb,cn=config
    objectClass: olcDatabaseConfig
    objectClass: olcHdbConfig
    olcDatabase: {1}hdb
    olcSuffix: dc=example,dc=com
    olcDbDirectory: /var/lib/ldap
    olcRootDN: cn=admin,dc=example,dc=com
    olcRootPW: secret
    olcDbConfig: set_cachesize 0 2097152 0
    olcDbConfig: set_lk_max_objects 1500
    olcDbConfig: set_lk_max_locks 1500
    olcDbConfig: set_lk_max_lockers 1500
    olcDbIndex: objectClass eq
    olcLastMod: TRUE
    olcDbCheckpoint: 512 30
    olcAccess: to attrs=userPassword by dn="cn=admin,dc=example,dc=com" write by anonymous auth by self write by * none
    olcAccess: to attrs=shadowLastChange by self write by * read
    olcAccess: to dn.base="" by * read
    olcAccess: to * by dn="cn=admin,dc=example,dc=com" write by * read
  4. 使用以下指令,將backend.example.com.ldif新增到LDAP中:
    sudo ldapadd -Y EXTERNAL -H ldapi:/// -f backend.example.com.ldif
  5. 建立以下的LDIF檔案內容(frontend.example.com.ldif),將檔案存放在自行指定的位置:
    # Create top-level object in domain
    dn: dc=example,dc=com
    objectClass: top
    objectClass: dcObject
    objectclass: organization
    o: Example Organization
    dc: Example
    description: LDAP Example 
    
    # Admin user.
    dn: cn=admin,dc=example,dc=com
    objectClass: simpleSecurityObject
    objectClass: organizationalRole
    cn: admin
    description: LDAP administrator
    userPassword: secret
    
    dn: ou=people,dc=example,dc=com
    objectClass: organizationalUnit
    ou: people
    
    dn: ou=groups,dc=example,dc=com
    objectClass: organizationalUnit
    ou: groups
    
    dn: uid=john,ou=people,dc=example,dc=com
    objectClass: inetOrgPerson
    objectClass: posixAccount
    objectClass: shadowAccount
    uid: john
    sn: Doe
    givenName: John
    cn: John Doe
    displayName: John Doe
    uidNumber: 1000
    gidNumber: 10000
    userPassword: password
    gecos: John Doe
    loginShell: /bin/bash
    homeDirectory: /home/john
    shadowExpire: -1
    shadowFlag: 0
    shadowWarning: 7
    shadowMin: 8
    shadowMax: 999999
    shadowLastChange: 10877
    mail: john.doe@example.com
    postalCode: 31000
    l: Toulouse
    o: Example
    mobile: +33 (0)6 xx xx xx xx
    homePhone: +33 (0)5 xx xx xx xx
    title: System Administrator
    postalAddress: 
    initials: JD
    
    dn: cn=example,ou=groups,dc=example,dc=com
    objectClass: posixGroup
    cn: example
    gidNumber: 10000
    
  6. 使用以下指令,將frontend.example.com.ldif新增到LDAP中:
    sudo ldapadd -x -D cn=admin,dc=example,dc=com -W -f frontend.example.com.ldif
    
  7. 使用ldapsearch測試一下
    ldapsearch -xLLL -b "dc=example,dc=com" uid=john sn givenName cn