Fixed SecurityConfiguration to permit all requests. Small isPublic test line in RecipeControllerTests.

This commit is contained in:
Jesse Brault 2024-08-02 10:47:59 -05:00
parent ebc58e6221
commit 83b1f63a56
2 changed files with 4 additions and 15 deletions

View File

@ -59,7 +59,8 @@ public class RecipeControllerTests {
.andExpect(jsonPath("$.text").value("<h1>Hello, World!</h1>")) .andExpect(jsonPath("$.text").value("<h1>Hello, World!</h1>"))
.andExpect(jsonPath("$.ownerUsername").value(owner.getUsername())) .andExpect(jsonPath("$.ownerUsername").value(owner.getUsername()))
.andExpect(jsonPath("$.starCount").value(0)) .andExpect(jsonPath("$.starCount").value(0))
.andExpect(jsonPath("$.viewerCount").value(0)); .andExpect(jsonPath("$.viewerCount").value(0))
.andExpect(jsonPath("$.isPublic").value(true));
} }
@Test @Test
@ -78,7 +79,7 @@ public class RecipeControllerTests {
.andExpect(jsonPath("$.content[0].slug").value(recipe.getSlug())) .andExpect(jsonPath("$.content[0].slug").value(recipe.getSlug()))
.andExpect(jsonPath("$.content[0].title").value(recipe.getTitle())) .andExpect(jsonPath("$.content[0].title").value(recipe.getTitle()))
.andExpect(jsonPath("$.content[0].ownerUsername").value(owner.getUsername())) .andExpect(jsonPath("$.content[0].ownerUsername").value(owner.getUsername()))
.andExpect(jsonPath("$.content[0].public").value(true)) .andExpect(jsonPath("$.content[0].isPublic").value(true))
.andExpect(jsonPath("$.content[0].starCount").value(0)); .andExpect(jsonPath("$.content[0].starCount").value(0));
} }

View File

@ -11,7 +11,6 @@ import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@ -32,20 +31,9 @@ public class SecurityConfiguration {
this.beanFactory = beanFactory; this.beanFactory = beanFactory;
} }
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return web -> web.ignoring().requestMatchers(
"/greeting",
"/auth/**",
"/images/**",
"/recipes/**",
"/sign-up/**"
);
}
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws Exception {
httpSecurity.authorizeHttpRequests(requests -> requests.anyRequest().authenticated()); httpSecurity.authorizeHttpRequests(requests -> requests.anyRequest().permitAll());
httpSecurity.csrf(AbstractHttpConfigurer::disable); httpSecurity.csrf(AbstractHttpConfigurer::disable);
httpSecurity.cors(Customizer.withDefaults()); httpSecurity.cors(Customizer.withDefaults());
httpSecurity.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy( httpSecurity.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(