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:
parent
37aa0612df
commit
324082f9a8
@ -9,9 +9,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@ -59,6 +59,8 @@
|
||||
|
||||
<properties>
|
||||
<faunadb.version>4.2.0</faunadb.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<start-class>com.baeldung.faunablog.FaunaBlogApplication</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user