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
  • 相关阅读:
    调试跳转动态打印
    PHP对redis操作详解
    SSL证书没有绿锁您与此网站建立的连接并非完全安全解决办法
    63. Unique Paths II
    62. Unique Paths
    40. Combination Sum II
    60. Permutation Sequence
    59. Spiral Matrix II
    批量修改名字的脚本
    57. Insert Interval
  • 原文地址:https://www.cnblogs.com/dgwblog/p/12666709.html
Copyright © 2011-2022 走看看