java - Spring Security 允许 root 的所有内容,但保护其他所有内容

标签 java spring spring-boot spring-security

我想允许每个人访问/但限制所有其他路径

类似于

.antMatchers("/").permitAll()
.antMatchers("NOT /").authenticated()

我如何设置“NOT/”的模式?

最佳答案

试试这个:

.antMatchers("/").permitAll()
.anyRequest().authenticated()

permitAll() 只会应用于匹配 "/" 的请求,其他请求将进一步路由到 authenticated()

关于java - Spring Security 允许 root 的所有内容,但保护其他所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61609004/

相关文章:

java - Spring/Hibernate/TestNG - 手动 session 和事务设置

java - Spring 并在运行时将参数传递给工厂方法

java - Graphics2D 和 JComponent

java - 使用 Apache Commons Math DescriptiveStatistics 跟踪多个移动平均线

java - 使用什么: JPQL or Criteria API?

java - 为什么 Spring 在处理端点异常时将 RuntimeException 包装在 NestedServletException 中?

java - 如何在不同线程中处理@KafkaListener方法?

java - 如何在没有在 application.properties 中设置的情况下获取 Controller 中的上下文路径

java - MockMvc - 使用复杂对象调用查询

java - 使用 lombok 构建器时覆盖默认值