diff --git a/persistence-modules/fauna/pom.xml b/persistence-modules/fauna/pom.xml index 4c37c2ae9e..3a34ad3ca1 100644 --- a/persistence-modules/fauna/pom.xml +++ b/persistence-modules/fauna/pom.xml @@ -9,9 +9,9 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 @@ -59,6 +59,8 @@ 4.2.0 + 17 + com.baeldung.faunablog.FaunaBlogApplication \ No newline at end of file diff --git a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/WebSecurityConfiguration.java b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/WebSecurityConfiguration.java index 12770c47ce..005f1751ea 100644 --- a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/WebSecurityConfiguration.java +++ b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/WebSecurityConfiguration.java @@ -5,15 +5,17 @@ import com.faunadb.client.FaunaClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; 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.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.CsrfConfigurer; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.web.SecurityFilterChain; @Configuration @EnableWebSecurity -@EnableGlobalMethodSecurity(prePostEnabled = true) +@EnableMethodSecurity public class WebSecurityConfiguration { @Autowired @@ -21,13 +23,11 @@ public class WebSecurityConfiguration { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - http.csrf() - .disable(); - http.authorizeRequests() - .antMatchers("/**") - .permitAll() - .and() - .httpBasic(); + http.csrf(CsrfConfigurer::disable) + .authorizeHttpRequests(requests -> requests + .requestMatchers("/**") + .permitAll()) + .httpBasic(Customizer.withDefaults()); return http.build(); } diff --git a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsController.java b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsController.java index e8e6316ea8..37701ae531 100644 --- a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsController.java +++ b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsController.java @@ -6,7 +6,6 @@ import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.web.bind.annotation.*; -import org.springframework.web.server.ResponseStatusException; import java.util.List; import java.util.concurrent.ExecutionException; diff --git a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsService.java b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsService.java index 5143a24b28..5865c1af49 100644 --- a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsService.java +++ b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/posts/PostsService.java @@ -6,7 +6,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.time.Instant; -import java.util.Collection; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; diff --git a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/users/FaunaUserDetailsService.java b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/users/FaunaUserDetailsService.java index 2e88aaa477..d0ddea3f69 100644 --- a/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/users/FaunaUserDetailsService.java +++ b/persistence-modules/fauna/src/main/java/com/baeldung/faunablog/users/FaunaUserDetailsService.java @@ -6,6 +6,8 @@ import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; 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; @@ -30,8 +32,9 @@ public class FaunaUserDetailsService implements UserDetailsService { if (userData == null) { 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()) .password(userData.at("data", "password").to(String.class).orNull()) .roles("USER")