JAVA-28931 :- Made changes to upgrade to Spring Boot 3 (#15516)

* Made changes to upgrade to Spring Boot 3

* Minor fixes

* Minor fixes
This commit is contained in:
Amit Pandey 2023-12-31 21:08:52 +05:30 committed by GitHub
parent 37aa0612df
commit 324082f9a8
5 changed files with 17 additions and 14 deletions

View File

@ -9,9 +9,9 @@
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath> <relativePath>../../parent-boot-3</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -59,6 +59,8 @@
<properties> <properties>
<faunadb.version>4.2.0</faunadb.version> <faunadb.version>4.2.0</faunadb.version>
<maven.compiler.release>17</maven.compiler.release>
<start-class>com.baeldung.faunablog.FaunaBlogApplication</start-class>
</properties> </properties>
</project> </project>

View File

@ -5,15 +5,17 @@ import com.faunadb.client.FaunaClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.SecurityFilterChain;
@Configuration @Configuration
@EnableWebSecurity @EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) @EnableMethodSecurity
public class WebSecurityConfiguration { public class WebSecurityConfiguration {
@Autowired @Autowired
@ -21,13 +23,11 @@ public class WebSecurityConfiguration {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf() http.csrf(CsrfConfigurer::disable)
.disable(); .authorizeHttpRequests(requests -> requests
http.authorizeRequests() .requestMatchers("/**")
.antMatchers("/**") .permitAll())
.permitAll() .httpBasic(Customizer.withDefaults());
.and()
.httpBasic();
return http.build(); return http.build();
} }

View File

@ -6,7 +6,6 @@ import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;

View File

@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Instant; import java.time.Instant;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -6,6 +6,8 @@ import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -30,8 +32,9 @@ public class FaunaUserDetailsService implements UserDetailsService {
if (userData == null) { if (userData == null) {
throw new UsernameNotFoundException("User not found"); throw new UsernameNotFoundException("User not found");
} }
PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
return User.withDefaultPasswordEncoder() return User.builder().passwordEncoder(encoder::encode)
.username(userData.at("data", "username").to(String.class).orNull()) .username(userData.at("data", "username").to(String.class).orNull())
.password(userData.at("data", "password").to(String.class).orNull()) .password(userData.at("data", "password").to(String.class).orNull())
.roles("USER") .roles("USER")