TIL 2023-12-08 h2-console & security

장규빈·2023년 12월 10일

TIL

목록 보기
41/59
post-thumbnail

문제

Security 설정후 h2-console이 실행안됨

해결

public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        // CSRF 설정
        http.csrf((csrf) -> csrf.disable());
        http.headers(header -> header.frameOptions(options -> options.sameOrigin())); //추가

        http.authorizeHttpRequests(
            (authorizeHttpRequests) -> authorizeHttpRequests.requestMatchers(HttpMethod.GET)
                .permitAll()
                .requestMatchers("/api/users/login").permitAll()
                .requestMatchers(PathRequest.toH2Console()).permitAll() //추가
                .anyRequest().authenticated()
        );

        // 필터 관리
        http.addFilterBefore(AuthorizationFilter(), UsernamePasswordAuthenticationFilter.class);
        http.addFilterBefore(ExceptionHandleFilter(), AuthorizationFilter.class);
        //접근 불가 페이지

        return http.build();
    }
profile
나다운사람

0개의 댓글