Spring Security 기능 잠시 끄기

Sarah·2026년 5월 20일

Spring Boot

목록 보기
17/17

exclude 활용

@SpringBootApplication(exclude = {
        SecurityAutoConfiguration.class,
        UserDetailsServiceAutoConfiguration.class
})
public class CommercePjtApplication {

	public static void main(String[] args) {
		SpringApplication.run(CommercePjtApplication.class, args);
	}

}

위 코드처럼 exclude를 추가해봤지만 로그인 페이지가 없어지지 않았다.


SecurityConfig 설정

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                // 1. CSRF 보안 비활성화 (테스트할 때 이게 켜져 있으면 POST 요청이 안 돼요!)
                .csrf(csrf -> csrf.disable())

                // 2. 모든 요청에 대해 인증 없이 허용 (로그인 창 안 뜨게 함)
                .authorizeHttpRequests(auth -> auth
                        .anyRequest().permitAll()
                )

                // 3. 기본 로그인 폼 비활성화
                .formLogin(form -> form.disable())

                // 4. H2 콘솔 사용을 위해 프레임 옵션 비활성화
                .headers(headers -> headers.frameOptions(frame -> frame.disable()));

        return http.build();
    }
}

config 패키지를 하나 만들어서 SecurityConfig 클래스를 만들어 위와 같이 설정했더니 로그인 페이지가 더 이상 뜨지 않았다.

profile
헤맨 만큼 내 땅

0개의 댓글