Spring / security / 컨트롤러가 2번 호출 될 때

CKK·2023년 7월 1일
post-thumbnail

여러가지 방법을 찾아봐도 계속 컨트롤러가 2번 호출되는 경우가 있다.

intellij를 사용하고 있으며 정확한 원인은 모르겠지만 시큐리티 설정을 초기화(?) 하면 2번호출이 멈추어서 방법을 공유한다.

2번 호출되는 security configure 파일 :

	@Bean
	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		
		
		http
			.authorizeHttpRequests(request -> request
				.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll()
				.requestMatchers( "/img/**", "/member/mypage", "/auth/join").permitAll()
				.anyRequest().authenticated()
			)
			.formLogin(login -> login
				.loginPage("/join/login")
				.loginProcessingUrl("/join/login-process")
				.usernameParameter("id")
				.passwordParameter("pw")
				.defaultSuccessUrl("/view/dashboard", true)
				.permitAll()
				.successHandler(customAuthenticationSuccessHandler)
				.failureHandler(customAuthenticationFailureHandler)
			)			
			.logout((logout) ->
				logout
					.logoutUrl("/join/logout")
					.logoutSuccessUrl("/")
			);
		
		
		return http.build();
	}
	

해당부분 주석하고 빌드 후 호출해주자 (return http.huild() 는 제외) :


	@Bean
	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		
/*		
		http
			.authorizeHttpRequests(request -> request
				.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll()
				.requestMatchers( "/img/**", "/member/mypage", "/auth/join").permitAll()
				.anyRequest().authenticated()
			)
			.formLogin(login -> login
				.loginPage("/join/login")
				.loginProcessingUrl("/join/login-process")
				.usernameParameter("id")
				.passwordParameter("pw")
				.defaultSuccessUrl("/view/dashboard", true)
				.permitAll()
				.successHandler(customAuthenticationSuccessHandler)
				.failureHandler(customAuthenticationFailureHandler)
			)			
			.logout((logout) ->
				logout
					.logoutUrl("/join/logout")
					.logoutSuccessUrl("/")
			);
		
*/
		
		return http.build();
	}
	

그리고 다시 원상태로 돌린 후 호출 :


	@Bean
	public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
		
		
		http
			.authorizeHttpRequests(request -> request
				.dispatcherTypeMatchers(DispatcherType.FORWARD).permitAll()
				.requestMatchers( "/img/**", "/member/mypage", "/auth/join").permitAll()
				.anyRequest().authenticated()
			)
			.formLogin(login -> login
				.loginPage("/join/login")
				.loginProcessingUrl("/join/login-process")
				.usernameParameter("id")
				.passwordParameter("pw")
				.defaultSuccessUrl("/view/dashboard", true)
				.permitAll()
				.successHandler(customAuthenticationSuccessHandler)
				.failureHandler(customAuthenticationFailureHandler)
			)			
			.logout((logout) ->
				logout
					.logoutUrl("/join/logout")
					.logoutSuccessUrl("/")
			);
		

		
		return http.build();
	}
	

황당하지만 나같은 경우는 이렇게 하니 호출이 한번으로 돌아왔다.
intellij의 문제인것 같은데 정확히는 모르겠다..

profile
CKK

1개의 댓글

comment-user-thumbnail
2023년 7월 31일

꿀팁 감사합니다

답글 달기