【发布时间】:2020-06-21 12:47:25
【问题描述】:
我有一个响应式 Spring Boot 应用程序,它负责使用 Spring Cloud Gateway(即它是一个 API 网关)将请求路由到下游服务。该应用程序有一些需要保护的执行器端点,因此我只想为此使用简单的安全性,例如基本身份验证。
我想配置应用程序,要求对 /actuator/refresh 的请求使用基本身份验证(使用配置的 Spring 安全用户和密码)进行授权。所有对其他端点的请求,即使它们包含基本身份验证,也只需要传递给下游服务。
我当前的 Spring 安全配置:
@Bean
@Order(1)
SecurityWebFilterChain securityWebFilterChain(final ServerHttpSecurity http) {
http.authorizeExchange(exchanges -> {
exchanges.matchers(EndpointRequest.toAnyEndpoint().excluding(HealthEndpoint.class, InfoEndpoint.class)).hasRole("ACTUATOR"); // requires Http Basic Auth
});
http.httpBasic(withDefaults()); // if not enabled, you cannot get the ACTUATOR role
return http.build();
}
@Bean
@Order(2)
SecurityWebFilterChain permitAllWebFilterChain(final ServerHttpSecurity http) {
http.authorizeExchange(exchanges -> exchanges.anyExchange().permitAll()); // allow unauthenticated access to any endpoint (other than secured actuator endpoints?)
http.httpBasic(ServerHttpSecurity.HttpBasicSpec::disable); // disable Http Basic Auth for all other endpoints
return http.build();
}
API 网关不会传播用于下游服务的请求。 Spring Boot 服务在此设置中返回 401,而预期/需要 200。
任何想法为什么这个配置不起作用/应该如何配置?
【问题讨论】:
-
什么不起作用?
-
API 网关不传播用于下游服务的请求。 Spring Boot 服务在此设置中返回 401,而预期/需要 200。
标签: spring-boot spring-security spring-webflux spring-cloud-gateway