Spring Boot Admin 2获取执行器端点401

时间:2018-10-01 05:45:50

标签: java spring-boot spring-security spring-boot-actuator spring-boot-admin

我已经在API服务应用程序中创建了Spring Boot Admin 2服务器,并将Spring Boot Admin 2客户端集成了。目前,我的API服务项目受OAuth2 Framework保护。为了绕过执行器端点,我在WebSecurity类的HttpSecurityWebSecurityConfigurerAdapter中添加了配置,但看起来执行器端点仍在提供401。当我调查此问题时我发现在public void configure(HttpSecurity http)中,当我删除.antMatcher("/user")时,执行器端点已打开,并且Admin Server能够获取所有详细信息,但是当我删除.antMatcher("/user")时,OAuth2并没有失败。

我的Spring Boot Admin Server在http://localhost:8080下运行,而API项目(Admin Client)在http://localhost:8081下运行

我正在使用

Spring Boot 2(2.0.4.RELEASE)
Spring Cloud(Finchley.RELEASE)
Spring Boot Admin 2(2.0.2)

如下所示,在我的API项目中配置了Oauth2 user-info-uri

security: 
  oauth2:
    resource:
      user-info-uri: http://localhost:9999/auth/user

下面是我在API项目中添加的一些属性

management.endpoints.web.exposure.include=health,info,auditevents,metrics,loggers,logfile,httptrace,env,flyway,liquidbase,shutdown,mappings,scheduledtasks,threaddump,heapdump
management.endpoint.health.show-details=always
management.security.enabled=false
management.health.rabbit.enabled=false
spring.boot.admin.client.url[0]=http://localhost:8080
spring.boot.admin.client.username=user
spring.boot.admin.client.password=password
spring.boot.admin.client.instance.management-url=http://localhost:8081/actuator
spring.boot.admin.client.instance.health-url=http://localhost:8081/actuator/health
spring.boot.admin.client.instance.service-url=http://localhost:8081

我的自定义WebSecurityConfigurer在下面给出

@Order(1)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {

    public WebSecurityConfigurer() {
        super(true);
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
         web.ignoring()
         .antMatchers("/actuator/**");
        web.ignoring().antMatchers(HttpMethod.OPTIONS, "/**", "/actuator/**");
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.anonymous().and().antMatcher("/user").authorizeRequests()
        .requestMatchers(EndpointRequest.toAnyEndpoint()).permitAll().
         antMatchers("/actuator/**").permitAll().
         anyRequest().authenticated()
        .and()
        .csrf()
        .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
        .ignoringAntMatchers("/instances", "/actuator/**");
    }
}

有人可以帮我吗

0 个答案:

没有答案