我的测试始终失败并显示401错误:
@DisplayName("My controller")
@WebMvcTest(controllers = MyController.class,
excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.keycloak.adapters.*")})
public class MyControllerTest {
@Autowired
private MockMvc mvc;
@Test
public void arrayObjectLinks() throws Exception {
mvc.perform(get(Application.VERSION_URL + MyController.URL))
.andExpect(status().isOk());
}
}
安全配置:
@KeycloakConfiguration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableConfigurationProperties(KeycloakSpringBootProperties.class)
public class WebSecurityConfiguration extends KeycloakWebSecurityConfigurerAdapter {
...
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.csrf().disable()
.authorizeRequests()
.antMatchers(apiURL).hasAnyRole(RoleType.EXTERNAL_SYSTEM.getId())
.anyRequest().permitAll();
}
}
如何完全禁用网络安全?我使用Spring Boot 2.1