我想使用Spring Security进行JWT身份验证.但它带有默认身份验证.我试图禁用它,但是这样做的旧方法 - 禁用它application.properties- 在2.0中已弃用.
这是我试过的:
@Configuration
public class StackWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().disable();
// http.authorizeRequests().anyRequest().permitAll(); // Also doesn't work.
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能简单地禁用基本安全性?
更新
可能很高兴知道我不使用web mvc而是web flux.
spring-security spring-boot spring-security-rest spring-webflux
在Spring Boot 1.5.x中,我已经配置了安全性,并且在某些配置文件中(例如本地),我已经security.basic.enabled=false在.properties文件中添加了一行来禁用该配置文件的所有安全性.我正在尝试迁移到新的Spring Boot 2,其中删除了该配置属性.如何在Spring Boot 2.0.x中实现相同的行为(不使用此属性)?
我已经阅读过Spring-Boot-Security-2.0和security-change-in-spring-boot-2-0-m4,这个属性没什么.
不能让我的@SpringBootTest工作.它说身份验证已启用,我不想要.
我已经设置好了 @AutoConfigureMockMvc(secure = false)
我提交了一个带有一些JSON的模拟请求,我的集成测试应该测试整个堆栈,通过Web层将SDR带到JPA然后进入内存数据库,这样我就可以使用它进行测试JdbcTemplate.
但响应是401,需要身份验证.为什么@AutoConfigureMockMvc(secure = false)不够?少了什么东西?
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = { TestDataSourceConfig.class })
@EnableAutoConfiguration
@AutoConfigureMockMvc(secure = false)
@AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.H2)
@Transactional
public class SymbolRestTests {
@Autowired
private MockMvc mockMvc;
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private SymbolRepository symbolRepository;
@PersistenceContext
private EntityManager entityManager;
@Test
public void shouldCreateEntity() throws Exception {
String testTitle = "TEST.CODE.1";
String testExtra = "Test for SymbolRestTests.java";
String json = createJsonExample(testTitle, testExtra, true);
log.debug(String.format("JSON==%s", json));
MockHttpServletRequestBuilder …Run Code Online (Sandbox Code Playgroud)