Fork me on Gitee

spring boot admin抛出"status":401,"error":"Unauthorized"异常

如果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
posted @ 2020-04-09 14:25  ---dgw博客  阅读(4477)  评论(0编辑  收藏  举报