在 Liberty 中配置 LDAP 使用者登錄
您可以利用 Liberty 配置一或多部「輕量型目錄存取通訊協定 (LDAP)」伺服器,來進行鑑別。
開始之前
關於這項作業
您可以在 Liberty 中,利用現有的 LDAP 伺服器來進行應用程式鑑別。如果要這樣做,請新增 appSecurity-2.0 特性到 server.xml 檔中,然後在 server.xml 檔中指定 ldapRegistry-3.0 特性,以及用來連接 LDAP 伺服器的配置資訊。
程序
- 新增 appSecurity-2.0 和 ldapRegistry-3.0 Liberty 特性到 server.xml 檔中。
- 選擇性的: 如果要與啟用 SSL 的 LDAP 伺服器通訊,請在 server.xml 檔中新增 ssl-1.0 Liberty 特性。
- 選擇性的: 將信任儲存庫複製到伺服器配置目錄中。
例如,您可以使用 ${server.config.dir} 變數。
與 LDAP 伺服器的 SSL 通訊如果要成功,LDAP 伺服器的「簽章者」憑證必須新增到 <ldapRegistry> 元素的 sslAlias 屬性所參照的信任儲存庫中。 在下列範例中,「簽章者」憑證必須新增到 LdapSSLTrustStore.jks 中。
- 配置伺服器的 LDAP 項目。
如果您不想要 LDAP 伺服器的 SSL,請從下列範例中,移除與 SSL 及金鑰儲存庫相關的各行。
請在 server.xml 檔中配置 LDAP 伺服器,或利用 WebSphere® Application Server Developer Tools for Eclipse 來進行配置。 在 Liberty 上配置應用程式安全時,WASdev.net 網站上有一些安全配置範例可供參考。- IBM® Directory Server:
<ldapRegistry id="ldap" realm="SampleLdapIDSRealm" host="ldapserver.mycity.mycompany.com" port="389" ignoreCase="true" baseDN="o=mycompany,c=us" ldapType="IBM Tivoli Directory Server" sslEnabled="true" sslRef="LDAPSSLSettings"> <idsFilters userFilter="(&(uid=%v)(objectclass=ePerson))" groupFilter="(&(cn=%v)(|(objectclass=groupOfNames) (objectclass=groupOfUniqueNames)(objectclass=groupOfURLs)))" userIdMap="*:uid" groupIdMap="*:cn" groupMemberIdMap="mycompany-allGroups:member;mycompany-allGroups:uniqueMember; groupOfNames:member;groupOfUniqueNames:uniqueMember"> </idsFilters> </ldapRegistry> <ssl id="LDAPSSLSettings" keyStoreRef="LDAPKeyStore" trustStoreRef="LDAPTrustStore" /> <keyStore id="LDAPKeyStore" location="${server.config.dir}/LdapSSLKeyStore.jks" type="JKS" password="{xor}CDo9Hgw=" /> <keyStore id="LDAPTrustStore" location="${server.config.dir}/LdapSSLTrustStore.jks" type="JKS" password="{xor}CDo9Hgw=" />
- Microsoft Active Directory Server:
<ldapRegistry id="ldap" realm="SampleLdapADRealm" host="ldapserver.mycity.mycompany.com" port="389" ignoreCase="true" baseDN="cn=users,dc=adtest,dc=mycity,dc=mycompany,dc=com" bindDN="cn=testuser,cn=users,dc=adtest,dc=mycity,dc=mycompany,dc=com" bindPassword="testuserpwd" ldapType="Microsoft Active Directory" sslEnabled="true" sslRef="LDAPSSLSettings"> <activedFilters userFilter="(&(sAMAccountName=%v)(objectcategory=user))" groupFilter="(&(cn=%v)(objectcategory=group))" userIdMap="user:sAMAccountName" groupIdMap="*:cn" groupMemberIdMap="memberOf:member" > </activedFilters> </ldapRegistry> <ssl id="LDAPSSLSettings" keyStoreRef="LDAPKeyStore" trustStoreRef="LDAPTrustStore" /> <keyStore id="LDAPKeyStore" location="${server.config.dir}/LdapSSLKeyStore.jks" type="JKS" password="{xor}CDo9Hgw=" /> <keyStore id="LDAPTrustStore" location="${server.config.dir}/LdapSSLTrustStore.jks" type="JKS" password="{xor}CDo9Hgw=" />
如果您使用 WebSphere Application Server Developer Tools for Eclipse,bindPassword 密碼會自動編碼。如果您直接編輯 server.xml 檔,您 可以利用 securityUtility encode 指令來對 bindPassword 密碼進行編碼。在 $INSTALL_ROOT/bin 目錄中,提供了 securityUtility 指令行工具。當您執行 securityUtility encode 指令時,您可以從指令行輸入,以提供要進行編碼的密碼,或者,如果沒有指定引數,工具會提示您輸入密碼。之後,工具會輸出編碼值。請複製工具輸出的值,將這個值用於 bindPassword 密碼。
- IBM® Directory Server:
- 選擇性的: 配置 LDAP 伺服器的憑證過濾器模式。
如需 Liberty 中之憑證對映模式的相關資訊,請參閱Liberty:LDAP 憑證對映模式。<ldapRegistry id="LDAP" realm="SampleLdapIDSRealm" host="myldap.ibm.com" port="389" ignoreCase="true" baseDN="o=ibm,c=us" ldapType="IBM Tivoli Directory Server" searchTimeout="8m" certificateMapMode="CERTIFICATE_FILTER" certificateFilter="uid=${SubjectCN}"> <idsFilters userFilter="(&(uid=%v)(objectclass=ePerson))" groupFilter="(&(cn=%v)(|(objectclass=groupOfNames) (objectclass=groupOfUniqueNames)(objectclass=groupOfURLs)))" userIdMap="*:uid" groupIdMap="*:cn" groupMemberIdMap="ibm-allGroups:member;ibm-allGroups:uniqueMember; groupOfNames:member;groupOfUniqueNames:uniqueMember"> </idsFilters> </ldapRegistry>
- 選擇性的: 您可以定義 LDAP 屬性與使用者登錄綱目屬性之間的對映。
在配置對映之後,當您將使用者登錄屬性用於任何定義了對映的作業,該使用者登錄屬性值會是 LDAP 屬性的值。在下列範例中,您可以看到 server.xml 檔中,定義了 LDAP 屬性 <userPassword> 與使用者登錄內容 <password> 之間的對映。<defaultValue> 是選用屬性。
<ldapRegistry id="LDAP" realm="SampleLdapIDSRealm" host="myldap.ibm.com" port="389" ignoreCase="true" baseDN="o=ibm,c=us" ldapType="IBM Tivoli Directory Server" searchTimeout="8m"> <attributeConfiguration> <attribute name="userPassword" propertyName="password" entityType="PersonAccount" defaultValue="xyz123"/> </attributeConfiguration> </ldapRegistry>
- 選擇性的: 您可以定義 LDAP 屬性與使用者登錄 <externalId> 屬性之間的對映。
您可以定義 LDAP 屬性與使用者登錄 <externalId> 屬性之間的對映。配置對映之後,當您將使用者登錄 <externalId> 屬性用於任何作業時,該值相等於所對映之 LDAP 屬性的值。下列程式碼範例顯示針對實體類型 <PersonAccount> 所定義之使用者登錄 <externalId> 屬性與 LDAP <distinguishedName> 屬性的對映。<autoGenerate> 屬性為選用性,該值預設為 false。
<ldapRegistry id="LDAP" realm="SampleLdapIDSRealm" host="myldap.ibm.com" port="389" ignoreCase="true" baseDN="o=ibm,c=us" ldapType="IBM Tivoli Directory Server" searchTimeout="8m"> <attributeConfiguration> <externalIdAttribute name="distinguishedName" entityType="PersonAccount" autoGenerate="false"></externalIdAttribute> </attributeConfiguration> </ldapRegistry>
- 選擇性的: 配置多重 LDAP 伺服器的失效接手。
<ldapRegistry id="LDAP" realm="SampleLdapIDSRealm" host="ldapserver1.mycity.mycompany.com" port="389" ignoreCase="true" baseDN="o=ibm,c=us" ldapType="IBM Tivoli Directory Server" idsFilters="ibm_dir_server"> <failoverServers name="failoverLdapServersGroup1"> <server host="ldapserver2.mycity.mycompany.com" port="389" /> <server host="ldapserver3.mycity.mycompany.com" port="389" /> </failoverServers> <failoverServers name="failoverLdapServersGroup2"> <server host="ldapserver4.mycity.mycompany.com" port="389" /> </failoverServers> </ldapRegistry> <idsLdapFilterProperties id="ibm_dir_server" userFilter="(&(uid=%v)(objectclass=ePerson))" groupFilter="(&(cn=%v)(|(objectclass=groupOfNames) (objectclass=groupOfUniqueNames)(objectclass=groupOfURLs)))" userIdMap="*:uid" groupIdMap="*:cn" groupMemberIdMap="ibm-allGroups:member;ibm-allGroups:uniqueMember; groupOfNames:member;groupOfUniqueNames:uniqueMember"> </idsLdapFilterProperties>
如需 ldapRegistry 和 failoverServers 元素的相關資訊,請參閱 LDAP User Registry。
- 選擇性的: 配置多個 LDAP 登錄。如果在 server.xml 檔中配置多個 LDAP 登錄,這些登錄會自動聯合。請確定使用者在所有聯合儲存庫之間是唯一的,否則,使用者登錄作業不會成功。 註: 當您使用多個聯合的 LDAP 儲存庫時,每個儲存庫都必須定義一個唯一 baseDN。
<ldapRegistry host="ldapserver1.mycity1.mycompany.com" baseDN="o=mycompany,c=us" port="123" ldapType="IBM Tivoli Directory Server"> </ldapRegistry> <ldapRegistry host="ldapserver2.mycity2.mycompany.com" baseDN="cn=users,dc=secfvt2,dc=mycity2,dc=mycompany,dc=com" port="456" ldapType="Microsoft Active Directory" bindDN="cn=testuser,cn=users,dc=secfvt2,dc=mycity2,dc=mycompany,dc=com" bindPassword="{xor}KzosKyosOi0vKDs="> </ldapRegistry>
註:- 聯合多個 LDAP 登錄不一定要指定 federatedRepository 元素,因為這些登錄會自動聯合。如果指定了 federatedRepository 元素來配置 participatingBaseEntry 和 primaryRealm 元素,只會在 primaryRealm元素所定義的儲存庫上,執行使用者登錄作業。 您可以在 primaryRealm 元素之下,定義不同使用者登錄 API 的輸入及輸出內容對映。
- participatingBaseEntry 元素的 name 屬性,必須與 ldapRegistry 元素中指定的 baseDN 屬性值相同。在下例中,會在主機 ldapserver1.mycity1.mycompany.com 上配置 LDAP 登錄的 baseDN 和 name 屬性。 baseDN 屬性的值,必須與 LDAP 伺服器中子樹狀結構的該屬性值相同,而 name 屬性的值必須與聯合使用者登錄中該子樹狀結構的名稱相同。 指定 name 屬性是選用的。 依預設,name 屬性會使用與 baseDN 屬性相同的值。如果在 ldapRegistry 元素中指定 name 屬性,則 participatingBaseEntry 元素中的 name 屬性所使用的值必須與 ldapRegistry 元素中的 name 屬性值相同。
<ldapRegistry host="ldapserver1.mycity1.mycompany.com" baseDN="o=mycompany,ou=myou,c=us" port="123" ldapType="IBM Tivoli Directory Server" name="o=mybaseentry"> </ldapRegistry> <ldapRegistry host="ldapserver2.mycity2.mycompany.com" baseDN="cn=users,dc=secfvt2,dc=mycity2,dc=mycompany,dc=com" port="456" ldapType="Microsoft Active Directory" bindDN="cn=testuser,cn=users,dc=secfvt2,dc=mycity2,dc=mycompany,dc=com" bindPassword="{xor}KzosKyosOi0vKDs="> </ldapRegistry> <federatedRepository> <primaryRealm name="RealmName" delimiter="@" allowOpIfRepoDown="true"> <participatingBaseEntry name="o=mybaseentry"/> <participatingBaseEntry name="cn=users,dc=secfvt2,dc=mycity2,dc=mycompany,dc=com"/> <uniqueUserIdMapping inputProperty="uniqueName" outputProperty="uniqueName"/> <userSecurityNameMapping inputProperty="principalName" outputProperty="principalName"/> <userDisplayNameMapping inputProperty="principalName" outputProperty="principalName"/> <uniqueGroupIdMapping inputProperty="uniqueName" outputProperty="uniqueName"/> <groupSecurityNameMapping inputProperty="cn" outputProperty="cn"/> <groupDisplayNameMapping inputProperty="cn" outputProperty="cn"/> </primaryRealm> </federatedRepository>
如需聯合 ldapRegistry 元素的相關資訊,請參閱LDAP User Registry。
- 選擇性的: 您可以依照下列範例來配置 LDAP 登錄的其他選用屬性(如 contextPool 或 ldapCache):
<ldapRegistry id="IBMDirectoryServerLDAP" realm="SampleLdapIDSRealm" host="host.domain.com" port="389" ignoreCase="true" baseDN="o=domain,c=us" bindDN="cn=testuser,o=domain,c=us" bindPassword="mypassword" ldapType="IBM Tivoli Directory Server" searchTimeout="8m"> <contextPool enabled="true" initialSize="1" maxSize="0" timeout="0s" waitTime="3000ms" preferredSize="3"/> <ldapCache> <attributesCache size="4000" timeout="1200s" enabled="true" sizeLimit="2000"/> <searchResultsCache size="2000" timeout="600s" enabled="true" resultsSizeLimit="1000"/> </ldapCache> </ldapRegistry>
註:- 聯合使用者登錄會使用環境定義儲存區作業機制,來改善並行存取 LDAP 伺服器的效能。環境定義儲存區作業的運作層次,較連線儲存區作業來得高。環境定義儲存區中的每一個環境定義項目,都會對應於 LDAP 伺服器的一個 Socket 連線。 在您配置 LDAP 登錄時,會指定這個儲存區所使用的連結認證。
- 聯合儲存庫利用快取機制來加強效能。 它會根據所執行的使用者作業來快取 LDAP 使用者和群組的相關資訊。 比方說,如果您在 LDAP 使用者和群組上執行搜尋,會快取作業結果。 您可以依照前一個範例所示來啟用 server.xml 檔中的 ldapCache 元素。
疑難排解提示 : 如果要進行任何 LDAP 鑑別問題的疑難排解,請在 bootstrap.properties 檔中,使用下列追蹤規格:com.ibm.ws.security.wim.*=all:com.ibm.websphere.security.wim.*=all
次主題
- Liberty:LDAP 憑證對映模式
憑證對映模式用來指定利用 Liberty 中的 EXACT_DN 或 CERTIFICATE_FILTER,將 X.509 憑證對映至 LDAP 目錄。


http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=twlp_sec_ldap
檔名:twlp_sec_ldap.html