title: Spring Boot Admin - Basic Auth
body: <p>I'm setting up basic auth in my sb-admin and client, but the client can't register (401 unauthorized). Everything works without auth.</p>
  
  <p><strong>SB-Admin configuration:</strong></p>
  
  <ul>
  <li>application.properties</li>
  </ul>
  
  <pre><code>    server.port=8080
  
      spring.application.name=SB Admin
      spring.boot.admin.ui.title=SB Admin
  
      spring.security.user.name=admin
      spring.security.user.password=admin
  </code></pre>
  
  <ul>
  <li>build.gradle</li>
  </ul>
  
  <pre><code>    implementation 'org.springframework.boot:spring-boot-starter-web'
      implementation 'org.springframework.boot:spring-boot-starter-security'
      implementation 'de.codecentric:spring-boot-admin-starter-server'
  </code></pre>
  
  <p><strong>Client configuration:</strong></p>
  
  <ul>
  <li>application.properties</li>
  </ul>
  
  <pre><code>    server.port=9000
      management.endpoints.web.exposure.include=*
      management.security.enabled=false
  
      spring.boot.admin.client.enabled=true
      spring.boot.admin.client.url=http://localhost:8080
      spring.boot.admin.client.username=admin
      spring.boot.admin.client.password=admin
  </code></pre>
  
  <ul>
  <li>build.gradle</li>
  </ul>
  
  <pre><code>    implementation 'org.springframework.boot:spring-boot-starter-web'
      implementation 'org.springframework.boot:spring-boot-starter-security'
      implementation 'org.springframework.boot:spring-boot-starter-actuator'
      implementation 'de.codecentric:spring-boot-admin-starter-client'
  </code></pre>
  
  <p><strong>Security Config</strong></p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class SecurityConfig extends WebSecurityConfigurerAdapter {
  
      private final String adminContextPath;
      private final AdminServerProperties adminServer;
  
      public SecurityConfig(AdminServerProperties adminServerProperties) {
          this.adminContextPath = adminServerProperties.getContextPath();
          this.adminServer = adminServerProperties;
      }
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
          successHandler.setTargetUrlParameter("redirectTo");
          successHandler.setDefaultTargetUrl(this.adminServer.path("/"));
  
          http.authorizeRequests((authorizeRequests) -&gt; authorizeRequests.antMatchers(this.adminServer.path("/assets/**"))
                  .permitAll().antMatchers(this.adminServer.path("/login")).permitAll().anyRequest().authenticated())
                  .formLogin((formLogin) -&gt; formLogin.loginPage(this.adminServer.path("/login"))
                          .successHandler(successHandler).and())
                  .logout((logout) -&gt; logout.logoutUrl(this.adminServer.path("/logout")))
                  .httpBasic(Customizer.withDefaults())
                  .csrf((csrf) -&gt; csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
                          .ignoringRequestMatchers(
                                  new AntPathRequestMatcher(this.adminServer.path("/instances"),
                                          HttpMethod.POST.toString()),
                                  new AntPathRequestMatcher(this.adminServer.path("/instances/*"),
                                          HttpMethod.DELETE.toString()),
                                  new AntPathRequestMatcher(this.adminServer.path("/actuator/**"))))
                  .rememberMe((rememberMe) -&gt; rememberMe.key(UUID.randomUUID().toString()).tokenValiditySeconds(1209600));
      }
  
      @Override
      protected void configure(AuthenticationManagerBuilder auth) throws Exception {
          auth.inMemoryAuthentication().withUser("admin").password("admin").roles("USER");
      }
  
  }
  </code></pre>
  
  <p>Does anybody can help me please?</p>