# 17.3.1 在 Admin 服务端中启用登录

Admin 服务端默认没有安全措施，所以给 Admin 服务端添加安全保护是一个好主意。Admin 服务端本质就是一个 Spring Boot 应用程序，所以您可以像保护任何其他 Spring Boot 应用程序一样进行设置，而且与任何受 Spring Security 保护的应用程序一样，您可以自由决定哪种安全方案最适合您的需要。

最简单的方式，您只需将 Spring Boot Security starter 添加到 Admin 服务端构建中。若使用 Initializr ，可通过选中 Security 复选框，或者添加以下内容到项目 pom.xml 文件中：

```markup
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>
```

这样您就不必一直查看 Admin 服务端的日志来查找随机生成的密码了。您可以在 application.yml 中配置一个简单的管理用户名和密码：

```yaml
spring:
  security:
    user:
      name: admin
      password: 53cr3t
```

现在，当在浏览器访问 Admin 服务端时，会弹出 Spring Security 默认登录表单，提示您输入用户名和密码。输入上边代码片段中的 admin 和 53cr3t，就可以登录进入。当然，这是一种极其基础的安全配置，我建议您参考第 4 章，了解 Spring Security 为管理服务器提供的更丰富的安全方案。


---

# 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://potoyang.gitbook.io/spring-in-action-v5/di-17-zhang-guan-li-spring/17.3-bao-hu-admin-fu-wu-duan/17.3.1-zai-admin-fu-wu-duan-zhong-qi-yong-deng-lu.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.
