Beginner programmer working with Spring Security for the first time. Through research and chatGPT I landed on a solution that worked! (hurray) but I'm getting a warning that .frameOptions() is deprecated.
I can't just remove frameOptions() because it's allowing me to view my H2 console, what's the current way to allow them?
@Bean
public SecurityFilterChain filterChain(HttpSecurity http, AuthService authService) throws Exception {
JwtTokenFilter jwtTokenFilter = new JwtTokenFilter(authService);
http
.csrf(csrf -> csrf.disable()) // Disable CSRF protection
.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class)
.authorizeHttpRequests(authz -> authz
.requestMatchers("/h2-console/**").permitAll() // Permit H2 console access
.requestMatchers("/api/auth/**").permitAll() // Permit all requests to auth endpoints
.requestMatchers("/chat/**").permitAll() //
.requestMatchers("/api/users/**").permitAll()
.requestMatchers("/api/audio/**").permitAll()
.anyRequest().permitAll() // Require auth for all other requests
)
.headers(headers -> headers // Set headers to allow frame options for H2 console
.frameOptions().sameOrigin());
return http.build();
}