๐Ÿ“˜ Programming/โŒ ERR

Spring Security 6.x ๋ฒ„์ „ ์—…๊ทธ๋ ˆ์ด๋“œ ํ›„ continue ํŒŒ๋ผ๋ฏธํ„ฐ ๋ถ™๋Š” ํ˜„์ƒ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•๊ณผ ์›์ธ

ํ•œ์ฝ”๋”ฉ 2023. 11. 15. 22:41
728x90
728x90

์ƒํ™ฉ

 

๊ธฐ์กด Spring Security 5.x ๋ฒ„์ „์„ ์—…๊ทธ๋ ˆ์ด๋“œ ํ•ด์„œ Spring Security 6.1 ๋ฒ„์ „์œผ๋กœ ์ƒˆ๋กญ๊ฒŒ ๋นŒ๋“œํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ณ„๋„ ์—๋Ÿฌ๋Š” ์—†์—ˆ์œผ๋‚˜ ๊ธฐ์กด์— ๋ชป ๋ดค๋˜ ์ด์ƒํ•œ continue ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋ถ™์–ด ์žˆ์Šต๋‹ˆ๋‹ค. 


์›์ธ

์ถœ์ฒ˜ : https://docs.spring.io/spring-security/reference/5.8

 

 

๊ณต์‹ docs์—์„œ ์•Œ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค. Spring Security 5.x ๋ฒ„์ „์—์„œ๋Š” ๋ชจ๋“  ์š”์ฒญ์— โ€‹โ€‹๋Œ€ํ•ด ๊ธฐ๋ณธ๊ฐ’์ด null์ด๋‹ค ๋ณด๋‹ˆ ์•ˆ์ •์„ฑ ์ธก๋ฉด์—์„œ ์ข‹์ง€ ๋ชปํ•˜๊ณ  ํŒ๋‹จํ•˜์—ฌ 6.x ๋ฒ„์ „์—์„œ๋Š” ๊ธฐ๋ณธ๊ฐ’์„ continue๋กœ ์„ค์ •๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ƒ๊ธด๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. 

 

์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ํ†ตํ•ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์žฌ์ •์˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
requestCache.setMatchingRequestParameterName(null);

 

 

์ œ๋ชฉ์—์„œ ๋ณด๋‹ค์‹œํ”ผ ์ตœ์ ํ™” ๋ชฉ์ ์œผ๋กœ ๋ณ€๊ฒฝ๋œ ์‚ฌํ•ญ์ด๋ฏ€๋กœ 5.x ๋ฒ„์ „์—์„œ๋„ 6.x ๋ฒ„์ „์ฒ˜๋Ÿผ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ continue๋กœ ๋ณ€๊ฒฝ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. 

HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
requestCache.setMatchingRequestParameterName("continue");

ํ•ด๊ฒฐ

๊ธฐ์กด ์ฝ”๋“œ

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
	return http
                .authorizeRequests()
                .requestMatchers(new AntPathRequestMatcher("/login"),
                                 new AntPathRequestMatcher("/signup"),
                                 new AntPathRequestMatcher("/user")).permitAll()
                .anyRequest().authenticated()
            	.and()
	...
}

 

๋ณ„๋„ ์„ค์ • ์—†์ด continue ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์ƒ๊ธฐ๋ฏ€๋กœ ์ด ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ null๋กœ ๋ฐ”๊ฟ”์„œ url์„ ๊น”๋”ํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.

 

์ˆ˜์ •ํ•œ ์ฝ”๋“œ

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
	HttpSessionRequestCache requestCache = new HttpSessionRequestCache();
	requestCache.setMatchingRequestParameterName(null);

	return http
                .authorizeRequests()
                .requestMatchers(new AntPathRequestMatcher("/login"),
                                 new AntPathRequestMatcher("/signup"),
                                 new AntPathRequestMatcher("/user")).permitAll()
                .anyRequest().authenticated()
            	.and()
	...
}

 

728x90
๋ฐ˜์‘ํ˜•