migrate to spring boot 3.2
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
package de.bstly.board.security;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
|
||||
|
||||
@@ -6,9 +6,9 @@ package de.bstly.board.security;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
||||
@@ -10,8 +10,9 @@ import javax.sql.DataSource;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
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.crypto.argon2.Argon2PasswordEncoder;
|
||||
@@ -36,7 +37,8 @@ import de.bstly.board.businesslogic.UserManager;
|
||||
* The Class SecurityConfig.
|
||||
*/
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
@EnableMethodSecurity(prePostEnabled = true)
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
|
||||
@Autowired
|
||||
@@ -65,28 +67,27 @@ public class SecurityConfig {
|
||||
|
||||
http
|
||||
// crsf
|
||||
.csrf().disable()
|
||||
.csrf((csrf) -> csrf.disable())
|
||||
// cors
|
||||
// .cors().configurationSource(corsConfigurationSource()).and()
|
||||
// anonymous
|
||||
.anonymous().disable()
|
||||
.anonymous((anonymous) -> anonymous.disable())
|
||||
// login
|
||||
.formLogin().loginPage("/login").defaultSuccessUrl(loginTargetUrl)
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?error")).and()
|
||||
.formLogin((formLogin) -> formLogin.loginPage("/login").defaultSuccessUrl(loginTargetUrl)
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?error")))
|
||||
// remember me
|
||||
.rememberMe().rememberMeServices(rememberMeServices()).and()
|
||||
.rememberMe((rememberMe) -> rememberMe.rememberMeServices(rememberMeServices()))
|
||||
// logout
|
||||
.logout().logoutUrl("/logout")
|
||||
.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)).and()
|
||||
.logout((logout) -> logout.logoutUrl("/logout")
|
||||
.logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)))
|
||||
// exception
|
||||
.exceptionHandling()
|
||||
.defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED),
|
||||
new AntPathRequestMatcher("/api/**"))
|
||||
.and()
|
||||
.exceptionHandling((exceptionHandling) -> exceptionHandling
|
||||
.defaultAuthenticationEntryPointFor(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED),
|
||||
new AntPathRequestMatcher("/api/**")))
|
||||
// oidc
|
||||
.oauth2Login().successHandler(oAuth2AuthenticationSuccessHandler)
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?externalError"))
|
||||
.loginPage("/login");
|
||||
.oauth2Login((oauth2Login) -> oauth2Login.successHandler(oAuth2AuthenticationSuccessHandler)
|
||||
.failureHandler(new SimpleUrlAuthenticationFailureHandler(loginUrl + "?externalError"))
|
||||
.loginPage("/login"));
|
||||
|
||||
return http.build();
|
||||
}
|
||||
@@ -98,7 +99,7 @@ public class SecurityConfig {
|
||||
*/
|
||||
@Bean(name = "passwordEncoder")
|
||||
public Argon2PasswordEncoder passwordEncoder() {
|
||||
return new Argon2PasswordEncoder();
|
||||
return Argon2PasswordEncoder.defaultsForSpringSecurity_v5_8();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user