代码之家  ›  专栏  ›  技术社区  ›  triples13

Spring boot admin:访问此资源需要完全身份验证

  •  0
  • triples13  · 技术社区  · 6 年前

    我们使用netflix oss进行反向代理和微服务的安全性,我们遵循这里提到的jhipster模式 https://www.jhipster.tech/microservices-architecture/ 当UI应用程序请求到API网关的网关并向我们的后端微服务代理请求时,我们使用JWT进行身份验证,我们需要一个仪表板来监视与UeReCa服务器注册的我们的微服务和API网关,我们启动了一个单独的spring boot管理服务器,以便它向eureka服务器注册,并为metrics端点轮询微服务和网关,但是我们得到了异常

    访问此资源需要完全身份验证

    它由过滤器抛出,这些过滤器在api网关和微服务级别过滤jwt, 我们也试过残疾人

    management.security.enabled: false 
    

    但是仍然没有运气,有人能帮忙指导我需要做些什么来让spring boot管理员能够成功地轮询microservices和api网关吗?

    我尝试了以下方法

    首先,我启用了web.ignoring().antMatchers(“/actuator/**”),这样执行器端点就被spring security忽略了,但是这种方法会危及我的api

    第二个想法:

    如果我在spring security中启用2个过滤器,第一个过滤器将用于spring boot管理,对执行器端点进行基本身份验证,第二个过滤器将用于rest的jwt身份验证所有api和下游api不确定是否可行?

    我启用了2个过滤器,一个过滤器用于执行器端点,一个过滤器用于api,但这些过滤器工作正常,但无法连接到SBA

    public class SpringSecurityAdminFilter extends WebSecurityConfigurerAdapter {
    
    
    
    @Autowired
    public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception {
    
           String password = passwordEncoder().encode("xxxx");
        auth.inMemoryAuthentication().passwordEncoder(passwordEncoder()).withUser("sam").password(password).roles("ADMIN");
    
    }
    
    @Bean
    public BCryptPasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
    
      http.csrf().disable()
        .authorizeRequests()
        .antMatchers("/actuator/**").hasRole("ADMIN")
        .and().httpBasic()
        .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);//We don't need sessions to be created.
    }
    
    
    }
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   triples13    6 年前

    我为spring boot管理服务器启用了基本身份验证,并在microservices中添加了属性

    eureka.instance.metadata-map.user.name: 
    eureka.instance.metadata-map.user.password:
    

    现在,执行器端点受到基本身份验证的保护

        2
  •  0
  •   Mehmet Özkan YAVUZ    6 年前

    我也遇到过类似的问题。在我的spring boot应用程序中,我们有一个cors过滤器来阻止Http Head请求。因此无法接受来自spring boot管理员的head请求。

    • 检查筛选器是否阻止了头Http请求。

    • 还需要在application.properties中设置management.security.enabled=false。