PacktPublishing / Learning-Spring-Boot-3.0-Third-Edition

Learning Spring Boot 3.0, published by Packt
MIT License
157 stars 119 forks source link

Deprecated Method on CH4 #7

Open matheusromano opened 2 weeks ago

matheusromano commented 2 weeks ago

@Bean SecurityFilterChain configureSecurity(HttpSecurity http) throws Exception { http.authorizeHttpRequests() // .requestMatchers("/login").permitAll() // .requestMatchers("/", "/search").authenticated() // .requestMatchers(HttpMethod.GET, "/api/") .authenticated() // .requestMatchers(HttpMethod.POST, "/new-video", "/api/").hasRole("ADMIN") // .anyRequest().denyAll() // .and() // .formLogin() // .and() // .httpBasic(); return http.build(); }

some methods of this security polices are deprecated, and i cant build my project with this code.

matheusromano commented 2 weeks ago

Found a solution. using this code:

@Bean SecurityFilterChain configureSecurity(HttpSecurity http) throws Exception { http .authorizeHttpRequests(authz -> authz .requestMatchers("/login").permitAll() .requestMatchers("/", "/search").authenticated() .requestMatchers(HttpMethod.GET, "/api/").authenticated() .requestMatchers(HttpMethod.POST, "/new-video", "/api/").hasRole("ADMIN") .anyRequest().denyAll() ) .formLogin(Customizer.withDefaults()) .httpBasic(Customizer.withDefaults());

    return http.build();
}