如果Spring Boot Admin 配置了Spring Security的安全拦截器: 可能出现401 未授权异常:

那么检查以下配置文件:

Security配置文件

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final String adminContextPath;

    public SecurityConfig(AdminServerProperties adminServerProperties) {
        this.adminContextPath = adminServerProperties.getContextPath();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        // @formatter:off
        SavedRequestAwareAuthenticationSuccessHandler successHandler
                = new SavedRequestAwareAuthenticationSuccessHandler();
        successHandler.setTargetUrlParameter("redirectTo");
        successHandler.setDefaultTargetUrl("/");

        http.authorizeRequests()
                .antMatchers("/assets/**").permitAll()
                .antMatchers("/login").permitAll()
                .anyRequest().authenticated().and()
                .formLogin().loginPage("/login")
                .successHandler(successHandler).and()
                .logout().logoutUrl("/logout").and()
                .httpBasic().and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                .ignoringAntMatchers(
                        "/instances",
                        "/actuator/**"
                );
        // @formatter:on
    }
}

注意必须在客户端配置: 这也是其他博客忽略的点:

# 配置服务端密码
spring.boot.admin.client.username=root
spring.boot.admin.client.password=root

相关文章:

  • 2021-07-05
  • 2022-12-23
  • 2021-06-12
  • 2021-09-23
  • 2021-06-20
  • 2021-06-11
  • 2021-07-28
猜你喜欢
  • 2022-01-03
  • 2021-06-11
  • 2022-12-23
  • 2021-04-18
  • 2022-01-24
  • 2022-12-23
  • 2022-01-13
相关资源
相似解决方案