> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/yong-hu-he-xiang-mu-guan-li/user-management/migrating-to-ldap-or-saml.md).

# 迁移到 LDAP 或 SAML

```
{
  _id:        '123',
  email:      'alice@example.com'
  first_name: 'Alice',
  last_name:  'Jones'
}
```

现在，你想与你公司的 LDAP/Active Directory 系统集成。在该系统中，Alice 的详细信息是：

```
Alice：
  - uid:  'alicejones'
  - mail: 'alicejones@tech.example.com'
  - givenName:   'Alice'
  - sn: 'Jones'
```

你的目标是让 Alice 使用他们的 LDAP 用户名（`alicejones`）和密码登录，而不是他们以前的 Overleaf 凭据，同时不丢失任何工作内容。下面是实现方法。

{% hint style="warning" %}
这个过程需要重新创建 **sharelatex** 容器，这将导致一些停机时间。我们强烈建议你先在测试/预发布环境中走一遍这个流程，以便熟悉它。
{% endhint %}

{% stepper %}
{% step %}

### 要求你的用户更新他们的电子邮件地址

Overleaf 账户与电子邮件地址绑定，因此第一步是让你的用户的 Overleaf 邮箱与他们的 LDAP 或 SAML 邮箱保持同步。

在我们的示例中，你会要求 Alice 登录到他们的 Overleaf 账户，并将其邮箱从 `alice@example.com` 到 `alicejones@tech.example.com`.

{% hint style="warning" %}
别忘了你自己！如果你是管理员，也需要更新你自己的电子邮件地址。
{% endhint %}

{% hint style="success" %}
如果你有很多用户，可以使用 [用户名迁移](/on-premises/zh-cn/yong-hu-he-xiang-mu-guan-li/user-management/username-migration.md) 脚本批量更改用户的主电子邮件地址。
{% endhint %}
{% endstep %}

{% step %}

### 启用 LDAP 或 SAML 模块

当每个人的电子邮件地址都更新后，就该切换了！你需要为新的身份验证方式设置正确的环境变量，然后重新创建 **sharelatex** 容器，使用 `bin/up -d` 命令重新创建所有服务。

这会用新的 LDAP 或 SAML 登录表单替换标准的 Overleaf 登录表单。

{% hint style="info" %}
你可以在这里找到启用 LDAP 的相关信息 [这里](/on-premises/zh-cn/pei-zhi/overleaf-toolkit/authentication/ldap-authentication.md)，以及 SAML 2.0 [这里](/on-premises/zh-cn/pei-zhi/overleaf-toolkit/authentication/saml-authentication.md).
{% endhint %}
{% endstep %}

{% step %}

### 用户现在可以通过 LDAP 或 SAML 登录

下次 Alice 去登录时，他们会看到新的表单。

![LDAP/Active Directory 登录页面](/files/5efda186542bd2fecb962e45b86c032ed053a782)

他们可以输入自己的 LDAP 用户名（`alicejones`）和密码，由于他们的电子邮件地址现在与 LDAP 中的地址一致，他们会直接登录到现有的 Overleaf 账户。所有项目都会原封不动地保留在他们离开时的位置。

如果你启用了 SAML 2.0，用户会看到一个按钮，点击后会将他们重定向到你的 IdP 以输入凭据。认证成功后，他们会被重定向回你的 Overleaf 实例并登录到他们的账户。

![SAML 登录页面](/files/e194e57865250889691dc6964b47e7fafe77f4be)

{% hint style="info" %}
另请参阅 [环境变量](broken://pages/8e0a2795a807f6db8f317f47523c2b84136db8ed) 页面，了解有关自定义登录页面体验的信息。

如果你需要回滚，只需注释掉 LDAP/SAML 配置并重新创建 **sharelatex** 容器，使用 `bin/up -d` 命令。然后用户就可以使用他们当前的电子邮件地址和 Overleaf 专用密码登录。
{% endhint %}
{% endstep %}
{% endstepper %}

## 反过来：从 LDAP/SAML 切换回原生身份验证

如果你已经使用 LDAP 或 SAML 一段时间，并想切换到 Overleaf 内置的登录系统（也许你已经弃用了 LDAP）怎么办？没问题！下面是切换的方法。

{% stepper %}
{% step %}

### 检查每个人的电子邮件是否正确

你用户的账户已经与他们的 LDAP 或 SAML 电子邮件地址关联起来了。以后他们将使用这个邮箱登录，所以只要确保一切看起来正确即可。
{% endstep %}

{% step %}

### 禁用 LDAP 或 SAML 模块

只需移除或取消设置 LDAP/SAML 配置，然后重新创建 **sharelatex** 容器，使用 `bin/up -d` 命令。这将恢复原生的 Overleaf 邮箱和密码登录表单。

![原生身份验证登录页面](/files/136005a1e173f472eca154013f2da71dda1573d4)
{% endstep %}

{% step %}

### 要求用户重置密码

当你的用户现在访问登录页面时，他们看到的将是 Overleaf 登录表单，而不是 LDAP/SAML 表单。

由于他们可能从未拥有过原生的 Overleaf 密码，他们需要创建一个。每个用户都应该：

* 点击“忘记密码？”链接。
* 输入与其账户关联的电子邮件地址（即来自 LDAP/SAML 的那个）。
* 按照密码重置邮件中的链接设置新密码。

{% hint style="info" %}
如果你还没有这样做，请查看我们关于启用 [电子邮件投递](/on-premises/zh-cn/pei-zhi/overleaf-toolkit/email-delivery.md).
{% endhint %}

完成后，他们就可以使用自己的电子邮件和新的 Overleaf 专用密码登录，访问所有项目。
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/on-premises/zh-cn/yong-hu-he-xiang-mu-guan-li/user-management/migrating-to-ldap-or-saml.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
