【发布时间】:2018-07-31 20:16:48
【问题描述】:
我有一个使用 eureka 服务器和客户端的项目。 Eureka 服务器使用 Spring Security,访问任何 URL 的用户都应该进行身份验证。这也适用于 Eureka 客户端。
当前配置如下:
尤里卡服务器:
Java:
@SpringBootApplication
@EnableEurekaServer
@EnableZuulProxy
@Controller
public class UiApplication {
@GetMapping("/user")
@ResponseBody
public Principal user(Principal user) {
return user;
}
@GetMapping(value = "/{path:[^\\.]*}")
public String redirect() {
return "forward:/";
}
public static void main(String[] args) {
SpringApplication.run(UiApplication.class, args);
}
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.httpBasic().and()
.logout().and()
.authorizeRequests()
.antMatchers("/index.html", "/", "/home", "/login").permitAll()
.anyRequest().authenticated()
.and()
.csrf()
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
// @formatter:on
}
}
}
配置:
security:
basic:
enabled: true
user:
password: password
spring:
application:
name: main
session:
store-type: redis
zuul:
routes:
resource:
path: /resource/**
#url: http://localhost:9000
sensitive-headers:
eureka:
instance:
hostname: localhost
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://user:password@localhost:8080/eureka/
在启动服务器时我已经收到异常,因为为服务器启用了 eureka 客户端并尝试连接,但由于身份验证问题而无法连接。 例外情况如下:
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
如果我在服务器属性中禁用弹簧安全,一切正常。如果激活了spring security,如何验证eureka客户端?
【问题讨论】:
标签: java spring spring-security spring-cloud spring-cloud-netflix