본문 바로가기

Spring

Spring Security Config설정 Spring boot 3.2버전

728x90

Spring Security config 설정을 하는데 블로그에서 가져다 사용한 것은 인텔리 제이에서 경고를 날려줬다..

그이유는 다음 버전부턴 지원을 안한다는거!!!

이 프로젝트가 얼마나 오래 갈지는 모르지만 그래도 최신 버전에 맞춰 작성해야 하기에 찾아서 수정!!

 

http.httpBasic().disable();
        http.csrf().disable();
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
        http.cors().configurationSource(corsConfigurationSource());
        http.exceptionHandling()
                .authenticationEntryPoint(jwtAuthenticationEntryPoint)
                .accessDeniedHandler(jwtAccessDeniedHandler);

 

기존 이 설정에 경고가 생겼는데

 

 http.httpBasic(HttpBasicConfigurer::disable);
        http.csrf(CsrfConfigurer::disable);
        http.sessionManagement(configurer -> configurer
        .sessionCreationPolicy(SessionCreationPolicy.STATELESS));
        http.cors(Customizer.withDefaults());

 

이렇게 변경한 후 경고가 사라졌다.!!

 

다른것도 마찬가지로

 

  http.headers(headers -> headers
                .contentSecurityPolicy(CSP_POLICY)
                .and()
                .frameOptions().deny()
                .httpStrictTransportSecurity(hsts -> hsts
                        .includeSubDomains(true)
                        .maxAgeInSeconds(31536000)));

 

이걸 아래와 같이 변경

 

http.headers(headers -> headers
                .contentSecurityPolicy(csp -> csp.policyDirectives(CSP_POLICY))
                .frameOptions(HeadersConfigurer.FrameOptionsConfig::deny)
                .httpStrictTransportSecurity(hsts -> hsts
                        .includeSubDomains(true)
                        .maxAgeInSeconds(31536000)
                        .preload(true))
        );

 

 

마지막이로 이것도 이와 같이 변경했다.

 http.exceptionHandling(authenticationManager -> authenticationManager
                .authenticationEntryPoint(jwtAuthenticationEntryPoint)
                .accessDeniedHandler(jwtAccessDeniedHandler));

 

'Spring' 카테고리의 다른 글

Spring data jpa 타임리프 페이징  (0) 2024.03.14