JAVA-29333 Upgrade spring-security-web-thymeleaf (#15699)

* JAVA-29333 Upgrade spring-security-web-thymeleaf

* JAVA-29333 Fix formatting

---------

Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
timis1 2024-01-29 23:46:05 +02:00 committed by GitHub
parent aefb1e6cbc
commit c499aacc87
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 29 deletions

View File

@ -11,7 +11,8 @@
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>spring-security-modules</artifactId> <artifactId>parent-boot-3</artifactId>
<relativePath>../../parent-boot-3</relativePath>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</parent> </parent>
@ -40,8 +41,12 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.thymeleaf.extras</groupId> <groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId> <artifactId>thymeleaf-extras-springsecurity6</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<properties>
<start-class>com.baeldung.springsecuritythymeleaf.SpringSecurityThymeleafApplication</start-class>
</properties>
</project> </project>

View File

@ -7,7 +7,7 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;

View File

@ -21,19 +21,14 @@ public class SecurityConfiguration {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.userDetailsService(userDetailsService) http.userDetailsService(userDetailsService)
.authorizeRequests() .authorizeHttpRequests(authorizationManagerRequestMatcherRegistry -> authorizationManagerRequestMatcherRegistry
.anyRequest() .anyRequest().authenticated())
.authenticated() .formLogin(httpSecurityFormLoginConfigurer -> httpSecurityFormLoginConfigurer
.and() .loginPage("/login").permitAll()
.formLogin() .defaultSuccessUrl("/index"))
.loginPage("/login") .logout(httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer.permitAll()
.permitAll() .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.defaultSuccessUrl("/index") .logoutSuccessUrl("/login"));
.and()
.logout()
.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login");
return http.build(); return http.build();
} }
} }

View File

@ -16,19 +16,13 @@ public class SecurityConfiguration {
@Bean @Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeRequests() http.authorizeHttpRequests(authorizationManagerRequestMatcherRegistry ->
.anyRequest() authorizationManagerRequestMatcherRegistry.anyRequest().authenticated())
.authenticated() .formLogin(httpSecurityFormLoginConfigurer ->
.and() httpSecurityFormLoginConfigurer.loginPage("/login").permitAll().successForwardUrl("/index"))
.formLogin() .logout(httpSecurityLogoutConfigurer -> httpSecurityLogoutConfigurer.permitAll()
.loginPage("/login") .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.permitAll() .logoutSuccessUrl("/login"));
.successForwardUrl("/index")
.and()
.logout()
.permitAll()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login");
return http.build(); return http.build();
} }