본문 바로가기
트러블슈팅

[스프링 시큐리티] SecurityConfig 중에 localhost에서 리디렉션한 횟수가 너무 많습니다. 뜨는 오류

by pyogowoon 2023. 1. 18.

 


@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig {


    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{

        http.csrf().disable()
                .authorizeRequests()
                .antMatchers("/","/board")
                .permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/auth/signin");
//                .loginProcessingUrl("/user/loginProc")
//                .defaultSuccessUrl("/");

        return http.build();
    }

 

SecurityFilterChain 으로 시큐리티를 설정할 때,

 

.formlogin().loginPage("/auth/signin") 으로 로그인페이지가 이동하도록 설정해놓았는데,

 

.antMatchers() 를 보면 "/auth" 로 갈수있는 권한이 없기때문에

 

지속적인 로그인 요청이 일어나서 에러가 발생합니다. ( 아마 빠트렸거나, / 를 안붙이는 오타가 생긴경우 일것)

 

 

 

 

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig {


    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{

        http.csrf().disable()
                .authorizeRequests()
                .antMatchers("/","/board","/auth/**")
                .permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/auth/signin");
//                .loginProcessingUrl("/user/loginProc")
//                .defaultSuccessUrl("/");

        return http.build();
    }

그렇기 때문에

 

.antMatchers() 에 auth를 넣어 auth관련 url에 접근할 수 있도록 해야합니다.

 

.antMatchers("/auth/**")  : /auth/**   auth 안에있는 전체 경로

혹은

.antMatchers("/auth/signin") 를 추가하면 오류가 해결

 

댓글