zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    C++的虚函数与多态
    Qt界面的个性设置QSS
    Qt添加背景图片应该注意的问题
    c/c++的函数参数与返回值
    堆和栈
    linux下挂载u盘
    Qt的主窗口弹出消息框
    智能家居实训系统的项目有感!
    Qt 快捷键
    FB
  • 原文地址:https://www.cnblogs.com/dgwblog/p/12666709.html
Copyright © 2011-2022 走看看