1818
1919import  de .codecentric .boot .admin .server .config .AdminServerProperties ;
2020import  org .springframework .boot .autoconfigure .security .SecurityProperties ;
21+ import  org .springframework .context .annotation .Bean ;
2122import  org .springframework .context .annotation .Configuration ;
2223import  org .springframework .http .HttpMethod ;
2324import  org .springframework .security .config .Customizer ;
24- import  org .springframework .security .config .annotation .authentication .builders .AuthenticationManagerBuilder ;
2525import  org .springframework .security .config .annotation .web .builders .HttpSecurity ;
26- import  org .springframework .security .config .annotation .web .configuration .WebSecurityConfigurerAdapter ;
26+ import  org .springframework .security .core .userdetails .User ;
27+ import  org .springframework .security .core .userdetails .UserDetails ;
28+ import  org .springframework .security .provisioning .InMemoryUserDetailsManager ;
29+ import  org .springframework .security .web .SecurityFilterChain ;
2730import  org .springframework .security .web .authentication .SavedRequestAwareAuthenticationSuccessHandler ;
2831import  org .springframework .security .web .csrf .CookieCsrfTokenRepository ;
2932import  org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
3033
3134import  java .util .UUID ;
3235
3336@ Configuration (proxyBeanMethods  = false )
34- public  class  SecurityConfiguration  extends   WebSecurityConfigurerAdapter   {
37+ public  class  SecurityConfiguration  {
3538
3639// TODO: https://codecentric.github.io/spring-boot-admin/current/#_securing_spring_boot_admin_server 
3740// This configuration is not customized to our apps and provides basic authentication. 
@@ -46,17 +49,17 @@ public SecurityConfiguration(AdminServerProperties adminServer, SecurityProperti
4649        this .security  = security ;
4750    }
4851
49-     @ Override 
50-     protected   void   configure (HttpSecurity  http ) throws  Exception  {
52+     @ Bean 
53+     public   SecurityFilterChain   filterChain (HttpSecurity  http ) throws  Exception  {
5154        SavedRequestAwareAuthenticationSuccessHandler  successHandler  = new  SavedRequestAwareAuthenticationSuccessHandler ();
5255        successHandler .setTargetUrlParameter ("redirectTo" );
5356        successHandler .setDefaultTargetUrl (this .adminServer .path ("/" ));
5457
5558        http .authorizeRequests (
56-                         authorizeRequests  -> authorizeRequests .antMatchers (this .adminServer .path ("/assets/**" )).permitAll ()
57-                                 .antMatchers (this .adminServer .path ("/actuator/info" )).permitAll ()
58-                                 .antMatchers (this .adminServer .path ("/actuator/health" )).permitAll ()
59-                                 .antMatchers (this .adminServer .path ("/login" )).permitAll ().anyRequest ().authenticated ()
59+                         authorizeRequests  -> authorizeRequests .requestMatchers (this .adminServer .path ("/assets/**" )).permitAll ()
60+                                 .requestMatchers (this .adminServer .path ("/actuator/info" )).permitAll ()
61+                                 .requestMatchers (this .adminServer .path ("/actuator/health" )).permitAll ()
62+                                 .requestMatchers (this .adminServer .path ("/login" )).permitAll ().anyRequest ().authenticated ()
6063                ).formLogin (
6164                        formLogin  -> formLogin .loginPage (this .adminServer .path ("/login" )).successHandler (successHandler ).and ()
6265                ).logout (logout  -> logout .logoutUrl (this .adminServer .path ("/logout" ))).httpBasic (Customizer .withDefaults ())
@@ -69,12 +72,17 @@ protected void configure(HttpSecurity http) throws Exception {
6972                                new  AntPathRequestMatcher (this .adminServer .path ("/actuator/**" ))
7073                        ))
7174                .rememberMe (rememberMe  -> rememberMe .key (UUID .randomUUID ().toString ()).tokenValiditySeconds (1209600 ));
75+         return  http .build ();
7276    }
7377
7478    // Required to provide UserDetailsService for "remember functionality" 
75-     @ Override 
76-     protected  void  configure (AuthenticationManagerBuilder  auth ) throws  Exception  {
77-         auth .inMemoryAuthentication ().withUser (security .getUser ().getName ())
78-                 .password ("{noop}"  + security .getUser ().getPassword ()).roles ("USER" );
79+     @ Bean 
80+     protected  InMemoryUserDetailsManager  userDetailsService () {
81+         UserDetails  user  = User .withDefaultPasswordEncoder ()
82+                 .username (security .getUser ().getName ())
83+                 .password (security .getUser ().getPassword ())
84+                 .roles ("USER" )
85+                 .build ();
86+         return  new  InMemoryUserDetailsManager (user );
7987    }
8088}
0 commit comments