Я пытаюсь отключить безопасность на модуле контроллера, но у меня всегда есть ошибка 403.
My Unit Test:
@RunWith(SpringRunner.class)
@WebMvcTest(value = MeasureController.class, secure = false)
@AutoConfigureMockMvc(secure = false)
public class MeasureControllerTest {
@Autowired
private MockMvc mvc;
@Autowired
private ObjectMapper objectMapper;
@MockBean
private ObjectService objectService;
@Autowired
private MeasureController measureController;
/**
* Test of sayHello method, of class MeasureController.
*
* @throws java.lang.Exception
*/
@Test
public void OnPostShouldReturnCreatedStatusIfEmptyMeasure() throws Exception {
final String url = "/object/" + uuidKey + "/measures/";
this.mvc.perform(post(url)
.content("[]")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated());
verifyZeroInteractions(objectService);
}
}
Конфигурация безопасности:
@Configuration
@EnableResourceServer
public class SecurityResourceServerConfig extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().authorizeRequests()
.antMatchers("/v2/api-docs", "/swagger-resources/**", "/swagger-ui.html", "/webjars/**").permitAll()
.anyRequest().authenticated()
;
}
@Primary
@Bean
public RemoteTokenServices tokenServices() {
final RemoteTokenServices tokenService = new RemoteTokenServices();
tokenService.setCheckTokenEndpointUrl("https://..../oauth/check_token");
tokenService.setClientId(".....");
tokenService.setClientSecret(".....");
return tokenService;
}
}
В весенней документации указано, что для параметра AutoConfigureMockMvc.secure значение false или значение WebMvcTest.secure равно false. Но оба не отключают безопасность. Я что-то не так?
Я использую Spring boot 2.0.4. и spring-security-oauth2 2.3.3.RELEASE
«WebMvcTest.secure» устарел. Вы должны выполнить проверку контроллера:
@RunWith(SpringRunner.class)
@WebMvcTest(value = PatientDeviceController.class, excludeAutoConfiguration = SecurityAutoConfiguration.class)
@AutoConfigureMockMvc(secure = false)