JAVA-29315: Upgrade spring-security-web-react to parent-spring-6 (#15920)
This commit is contained in:
+2
-1
@@ -1,5 +1,4 @@
|
||||
package com.baeldung.spring;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -10,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/rest")
|
||||
public class RestController {
|
||||
|
||||
+16
-23
@@ -38,28 +38,21 @@ public class SecSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http.csrf()
|
||||
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
|
||||
.and()
|
||||
.authorizeRequests()
|
||||
.antMatchers("/admin/**")
|
||||
.hasRole("ADMIN")
|
||||
.antMatchers("/anonymous*")
|
||||
.anonymous()
|
||||
.antMatchers(HttpMethod.GET, "/index*", "/static/**", "/*.js", "/*.json", "/*.ico", "/rest")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
.and()
|
||||
.formLogin()
|
||||
.loginPage("/index.html")
|
||||
.loginProcessingUrl("/perform_login")
|
||||
.defaultSuccessUrl("/homepage.html", true)
|
||||
.failureUrl("/index.html?error=true")
|
||||
.and()
|
||||
.logout()
|
||||
.logoutUrl("/perform_logout")
|
||||
.deleteCookies("JSESSIONID");
|
||||
return http.build();
|
||||
return http.csrf(csrf -> csrf.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()))
|
||||
.authorizeHttpRequests(request -> request.requestMatchers("/admin/**")
|
||||
.hasRole("ADMIN")
|
||||
.requestMatchers("/anonymous*")
|
||||
.anonymous()
|
||||
.requestMatchers(HttpMethod.GET, "/index*", "/static/**", "/*.js", "/*.json", "/*.ico", "/rest")
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
.authenticated())
|
||||
.formLogin(form -> form.loginPage("/index.html")
|
||||
.loginProcessingUrl("/perform_login")
|
||||
.defaultSuccessUrl("/homepage.html", true)
|
||||
.failureUrl("/index.html?error=true"))
|
||||
.logout(logout -> logout.logoutUrl("/perform_logout")
|
||||
.deleteCookies("JSESSIONID"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
+11
-8
@@ -1,19 +1,22 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import com.baeldung.spring.MvcConfig;
|
||||
import com.baeldung.spring.SecSecurityConfig;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { MvcConfig.class, SecSecurityConfig.class })
|
||||
public class SpringContextTest {
|
||||
@ExtendWith(SpringExtension.class)
|
||||
class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user