> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/v.-spring-boot-actuator/50.-endpoints/50.3-securing-http-endpoints.md).

# 50.3 加密HTTP端点

你应当采取与处理其它敏感的URL相同的方式，加密HTTP端点。如果存在Spring Security，端点会默认用Spring Security的内容协商策略加密。如果你要为HTTP端点配置自定义的安全，例如，只允许某一角色的用户访问它们，Spring Boot提供了一些方便的`RequestMatcher`对象。它们可以与Spring Security结合使用。

典型的Spring Security配置可能类似于下面的例子：

```java
@Configuration
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
                .anyRequest().hasRole("ENDPOINT_ADMIN")
                .and()
            .httpBasic();
    }

}
```

之前的例子使用`EndpointRequest.toAnyEndpoint()`将请求匹配端点，然后确保所有请求都有`ENDPOINT_ADMIN`角色。另外几个匹配器方法也可以用于`EndpointRequest`。详情请查看API文档（[HTML](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/actuator-api//html)或者[PDF](https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/actuator-api//pdf/spring-boot-actuator-web-api.pdf)）。

如果你在防火墙后面部署应用，你可能更喜欢不需要验证，你所有的执行器端点就能被访问。你可以改变`management.endpoints.web.exposure.include`属性，达到这种效果。如下所示：

**application.properties.**

```
management.endpoints.web.exposure.include=*
```

另外，如果Spring Security存在，你需要添加自定义的安全配置，来允许未验证的访问。如下所示：

```java
@Configuration
public class ActuatorSecurity extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests()
            .anyRequest().permitAll()
    }

}
```
