# OpenLDAP Docker 服务器

{% hint style="info" %}
对应的[官方页面地址](https://contributing.bitwarden.com/getting-started/business/directory-connector/open-ldap)
{% endhint %}

此方法使用 [OpenLDAP Docker 镜像](https://github.com/osixia/docker-openldap)来运行可用于开发的本地目录服务。

这也是用于在 CI 工作流程中运行集成测试的方法。

## 要求 <a href="#requirements" id="requirements"></a>

* [mkcert](https://github.com/FiloSottile/mkcert)（通过 Homebrew 提供）
* [Web Vault](/getting-started/clients/web-vault.md)
* [服务器](/getting-started/server.md)
* [目录连接器](/getting-started/business/directory-connector.md)
* 一个付费组织

## 快速开始 <a href="#ldif-filequick-start" id="ldif-filequick-start"></a>

### 启动目录服务 <a href="#start-directory-service" id="start-directory-service"></a>

1、在 Directory Connector 存储库中打开一个终端。

2、配置 TLS 证书：

```bash
npm run test:integration:setup
```

3、启动 OpenLDAP Docker 容器：

```bash
docker compose up -d
```

### 配置目录连接器 <a href="#configure-directory-connector" id="configure-directory-connector"></a>

1. 运行 Directory Connector Electron App（请参阅[构建说明](/getting-started/business/directory-connector.md#build-instructions)）。
2. 使用[组织 API 密钥](https://help.ppgg.in/organizations/bitwarden-public-api#authentication)登录。
3. 使用下面的配置设置。

**目录设置：**

* **Type**: Active Directory / LDAP
* **Server Hostname**: localhost
* **Server Port**: 389
* **Root Path**: dc=bitwarden,dc=com
* **This server uses Active Directory:** \[unchecked]
* **This server pages search results:** \[unchecked]
* **This server uses an encrypted connection:** \[unchecked]
* **Username**: cn=admin,dc=bitwarden,dc=com
* **Password**: admin

**同步设置：**

* **User Path**: \[blank]
* **User Object Class**: person
* **User Email Attribute**: mail
* **Group Path**: \[blank]
* **Group Object Class**: organizationalUnit
* **Group Name Attribute**: ou

### 同步 <a href="#sync" id="sync"></a>

{% hint style="warning" %}
当您进行真正的同步时，邀请电子邮件将发送给所有已同步的用户。确保您使用的是 [Mailcatcher](/getting-started/server/guide.md#mailcatcher)，这样您就不会发送实时电子邮件。
{% endhint %}

1. 点击 Directory Connector 中的「Test Now」按钮。您应该会得到一个用户列表。
2. 准备好后，点击「Sync Now」以执行真正的同步。您应该会在 Directory Connector 中收到确认消息，并在网页密码库中看到新的被邀请的用户。

### 集成测试 <a href="#integration-tests" id="integration-tests"></a>

您也可以针对 Docker 容器运行集成测试：

```bash
npm run test:integration
```

{% hint style="danger" %}
集成测试断言收到的同步数据与一组静态测试数据匹配。对 OpenLDAP 目录数据的任何更改都会导致这些测试失败。
{% endhint %}

## 其他数据集 <a href="#other-datasets" id="other-datasets"></a>

LDIF 文件包含您的目录的配置（例如用户、群组等）。您可以修改或使用自定义 LDIF 文件来自定义您的测试数据。

LDIF 文件可以放置在您的 Directory Connector 存储库中的 `openldap/ldifs` 位置。您可能需要删除并重新创建您的 Docker 容器，以便更改生效（例如 `docker compose up -d --force-recreate` ）。

### 使用示例 LDIF 文件 <a href="#use-example-ldif-file" id="use-example-ldif-file"></a>

不同大小的示例 LDIF 文件包含在 Directory Connector 存储库的 `openldap/examples` 文件夹中。

### 生成您自己的 LDIF 文件 <a href="#generate-your-own-ldif-file" id="generate-your-own-ldif-file"></a>

或者，您可以使用以下说明生成您自己的 LDIF 文件。除非您有特殊要求，否则您不需要这样做。

1. 下载 [LDIF 生成器](https://ldapwiki.com/wiki/LDIF%20Generator)。
2. 将 `Data/mail-hosts.txt` 文件替换为我们自己的 [mail-hosts.txt](https://contributing.bitwarden.com/enterprise/directory-connector/mail-hosts.txt) 文件。这包含大量唯一主机名，以避免生成重复的电子邮件地址。
3. 运行 `java -jar LDIFGen.jar`。
4. 使用以下设置：
   * Base Added: dc=bitwarden, dc=com
   * Generate OUs: Generic
   * Generate People: add
5. 点击「Run」。
6. LDIF 输出可能在电子邮件地址中包含非法字符（例如空格和撇号） - 您应该在使用前手动检查。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dev.ppgg.in/getting-started/business/directory-connector/open-ldap.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
