구글 소셜 로그인 후 URL에 ?continue
가 쿼리 파라미터로 추가되어 나오는 문제가 발생했다.
스프링 부트의 버전 업그레이드에 따라서 나타난 변화라고 한다. 아래 스프링 공식문서 링크를 보고 문제를 해결할 수 있었다.
Spring Document - Optimize Querying of RequestCache
기본적으로 쿼리 파라미터는 Spring Security가 해당 요청에서 세션을 쿼리할 것인지 여부를 알 수 있도록 추가되었는데 성능 최적화와 직결되는 부분이라고 한다. RequestCache
의 값을 임의의 다른 값으로 변경하면 문제를 해결할 수 있다. 이 프로젝트에서 나는 해당 성능 최적화를 원치 않아 null
로 코드를 수정했다.
브라우저 캐시에 캐시된 데이터로 인해 바로 반영이 안 될 수 있어 브라우저 캐시를 비운 후 동작을 확인했다.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.requestCache(cache -> cache.requestCache(new NullRequestCache()))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.sessionConcurrency(concurrency -> concurrency.maximumSessions(1)
.maxSessionsPreventsLogin(false)
.sessionRegistry(sessionRegistry())
.expiredUrl("/login?expired")))
.authenticationProvider(customAuthenticationProvider)
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(auth -> auth
.requestMatchers(
new AntPathRequestMatcher("/js/**"),
new AntPathRequestMatcher("/img/**"),
new AntPathRequestMatcher("/css/**"),
new AntPathRequestMatcher("/auth/login"),
new AntPathRequestMatcher("/auth/signup"),
new AntPathRequestMatcher("/login"),
new AntPathRequestMatcher("/signup")
).permitAll()
.anyRequest().authenticated()
)
.formLogin(form -> form
.loginPage("/auth/login")
.loginProcessingUrl("/login")
.successHandler(customAuthenticationSuccessHandler(sessionRegistry()))
.failureHandler(customAuthenticationFailureHandler)
.permitAll()
)
.logout(logout -> logout
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/auth/login")
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
)
.oauth2Login(oauth -> oauth
.userInfoEndpoint(userInfo -> userInfo
.userService(principalOauthDetailsService)
)
.defaultSuccessUrl("/board/posts")
);
return http.build();
}