Код: Выделить всё
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(
authorize - >
authorize
.requestMatchers("/api/**")
.authenticated())
.oauth2ResourceServer(resourceServer -> resourceServer.jwt(withDefaults()))
.oauth2Login(withDefaults());
return http.build();
}
Код: Выделить всё
public class HelloControllerTests {
@Autowired private MockMvc mockMvc;
@Test
public void shouldReturnWorld() throws Exception {
this.mockMvc
.perform(get("/api/hello").with(oauth2Login()))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Hello, World!")));
}
@Test
public void shouldReturnBob() throws Exception {
this.mockMvc
.perform(get("/api/hello").with(oauth2Login()).param("name", "bob"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("Hello, Bob")));
}
}
Как я могу сделать так, чтобыockMvc всегда включал with(oauth2Login()) во все запросы?
Подробнее здесь: https://stackoverflow.com/questions/788 ... l-requests