以下是我设置 TeamCity LDAP 配置文件以同步 AD 组的方法:
ldap-config.properties 文件
java.naming.provider.url=ldap://<your server or domain>:3268/DC=YOUR,DC=Domain,DC=Here
java.naming.security.principal=<username>
java.naming.security.credentials=<password>
teamcity.users.login.filter=(sAMAccountName=$capturedLogin$)
teamcity.users.username=sAMAccountName
### USERS SETTINGS ###
teamcity.options.users.synchronize=true
teamcity.users.filter=(objectClass=user)
teamcity.users.property.displayName=displayName
teamcity.users.property.email=mail
# Automatic user creation and deletion during users synchronization
teamcity.options.createUsers=true
teamcity.options.deleteUsers=true
### GROUPS SETTINGS ###
# These settings are mandatory if groups synchronization is turned on (ldap-mapping.xml exists)
# Set to "true" to enable the synchronization for groups listed in ldap-mapping.xml file.
# IMPORTANT NOTE: TeamCity groups should be already created manually and listed in ldap-mapping.xml file.
teamcity.options.groups.synchronize=true
# The group search LDAP filter used to retrieve groups to synchronize.
# The search is performed inside the LDAP entry denoted by "teamcity.groups.base". The result should include all the groups configured in the ldap-mapping.xml file.
teamcity.groups.filter=(objectClass=group)
### OPTIONAL SETTINGS ###
# The time interval between synchronizations (in milliseconds). By default, it is one hour.
teamcity.options.syncTimeout=3600000
# The LDAP attribute of a group storing it's members.
# Note: LDAP attribute should contain the full DN of the member, one attribute per member. See also "teamcity.users.property.memberId".
teamcity.groups.property.member=member
注意:我使用端口 3268 而不是 389,这是因为默认端口使 TeamCity 在登录时非常慢。在大多数情况下,使用 389 登录需要 5 分钟,而使用 3268 则可以立即登录。
ldap-mapping.xml 文件
<!DOCTYPE mapping SYSTEM "ldap-mapping.dtd">
<mapping>
<!-- Example mapping entry:
<group-mapping teamcityGroupKey="GROUP" ldapGroupDn="CN=Group,DC=Example,DC=Com"/>
-->
<group-mapping teamcityGroupKey="YourGroupKey" ldapGroupDn="CN=<DNName>" />
</mapping>
Powershell 和 RSAT
为了获得我添加的每个组的专有名称,我使用了安装了 RSAT(远程服务器管理工具)的计算机https://www.microsoft.com/en-us/download/details.aspx?id= 45520。RSAT 向 powershell 添加了一些 Active Directory 功能,这使您更容易获得所需的 LDAP 设置。
PowerShell命令:
get-adgroup <Group name> -properties *
将 DistinguishedName 与 teamcityGroupKey 一起添加到 ldap-mapping.xml 文件中的 ldapGroupDn 字段,您应该可以开始了。