当服务启用 spring 安全 bcryptpasswordencoder 时,spring boot admin 401

问题描述

这是 spring 安全配置

http
  .cors()
  .and()
  .csrf().disable()
  .authorizeRequests()
  .antMatchers(ignores).permitAll()
  .anyRequest().authenticated()
  .and().exceptionHandling().authenticationEntryPoint(unauthorizedHandler)
  .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  .and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
  .ignoringAntMatchers("/instances","/actuator/**");

cors 配置为允许所有区域。

  @Override
  public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")
            .allowedOrigins("*")
            .allowedMethods("POST","GET","PUT","OPTIONS","DELETE")
            .maxAge(3600)
            .allowCredentials(true);
  }

如果添加以下代码,我们在spring boot admin上得到401。我需要在哪里/什么配置?

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

解决方法

固定! 只需将 spring boot admin 配置的用户添加到服务数据库。 但是我还是很困惑,我都准备好了配置spring security忽略下面的路径

ignoringAntMatchers("/instances","/actuator/**");

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...