SpringCloud 保护Eureka服务器
2023-11-22 11:36 更新
您只需通过spring-boot-starter-security将Spring Security添加到服务器的类路径中即可保护Eureka服务器。默认情况下,当Spring Security在类路径上时,它将要求在每次向应用程序发送请求时都发送有效的CSRF令牌。Eureka客户通常不会拥有有效的跨站点请求伪造(CSRF)令牌,您需要为/eureka/**端点禁用此要求。例如:
@EnableWebSecurity
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().ignoringAntMatchers("/eureka/**");
super.configure(http);
}
}
有关CSRF的更多信息,请参见Spring Security文档。
可以在Spring Cloud示例存储库中找到Eureka演示服务器。
以上内容是否对您有帮助:

免费 AI IDE


更多建议: