User-Profile-Image
hankin
  • 5
  • Java
  • Kotlin
  • Spring
  • Web
  • SQL
  • MegaData
  • More
  • Experience
  • Enamiĝu al vi
  • 分类
    • Zuul
    • Zookeeper
    • XML
    • WebSocket
    • Web Notes
    • Web
    • Vue
    • Thymeleaf
    • SQL Server
    • SQL Notes
    • SQL
    • SpringSecurity
    • SpringMVC
    • SpringJPA
    • SpringCloud
    • SpringBoot
    • Spring Notes
    • Spring
    • Servlet
    • Ribbon
    • Redis
    • RabbitMQ
    • Python
    • PostgreSQL
    • OAuth2
    • NOSQL
    • Netty
    • MySQL
    • MyBatis
    • More
    • MinIO
    • MegaData
    • Maven
    • LoadBalancer
    • Kotlin Notes
    • Kotlin
    • Kafka
    • jQuery
    • JavaScript
    • Java Notes
    • Java
    • Hystrix
    • Git
    • Gateway
    • Freemarker
    • Feign
    • Eureka
    • ElasticSearch
    • Docker
    • Consul
    • Ajax
    • ActiveMQ
  • 页面
    • 归档
    • 摘要
    • 杂图
    • 问题随笔
  • 友链
    • Spring Cloud Alibaba
    • Spring Cloud Alibaba - 指南
    • Spring Cloud
    • Nacos
    • Docker
    • ElasticSearch
    • Kotlin中文版
    • Kotlin易百
    • KotlinWeb3
    • KotlinNhooo
    • 前端开源搜索
    • Ktorm ORM
    • Ktorm-KSP
    • Ebean ORM
    • Maven
    • 江南一点雨
    • 江南国际站
    • 设计模式
    • 熊猫大佬
    • java学习
    • kotlin函数查询
    • Istio 服务网格
    • istio
    • Ktor 异步 Web 框架
    • PostGis
    • kuangstudy
    • 源码地图
    • it教程吧
    • Arthas-JVM调优
    • Electron
    • bugstack虫洞栈
    • github大佬宝典
    • Sa-Token
    • 前端技术胖
    • bennyhuo-Kt大佬
    • Rickiyang博客
    • 李大辉大佬博客
    • KOIN
    • SQLDelight
    • Exposed-Kt-ORM
    • Javalin—Web 框架
    • http4k—HTTP包
    • 爱威尔大佬
    • 小土豆
    • 小胖哥安全框架
    • 负雪明烛刷题
    • Kotlin-FP-Arrow
    • Lua参考手册
    • 美团文章
    • Java 全栈知识体系
    • 尼恩架构师学习
    • 现代 JavaScript 教程
    • GO相关文档
    • Go学习导航
    • GoCN社区
    • GO极客兔兔-案例
    • 讯飞星火GPT
    • Hollis博客
    • PostgreSQL德哥
    • 优质博客推荐
    • 半兽人大佬
    • 系列教程
    • PostgreSQL文章
    • 云原生资料库
    • 并发博客大佬
Help?

Please contact us on our email for need any support

Support
    首页   ›   Spring   ›   正文
Spring

SpringBoot—AntPathMatcher匹配原则和含义

2020-08-02 21:01:42
1564  0 0

阅读完需:约 2 分钟

在使用spring security做登陆鉴权。登陆界面相关CSS和JS,以及部分api接口需要忽略,于是代码中用到了anyMatchers。

@Override
    public void configure(WebSecurity web) throws Exception {
        // AuthenticationTokenFilter will ignore the below paths
        web
            .ignoring()
            .antMatchers(
                HttpMethod.POST,
                authenticationPath
            )

            // allow anonymous resource requests
            .and()
            .ignoring()
            .antMatchers(
                HttpMethod.GET,
                "/",
                "/*.html",
                "/favicon.ico",
                "/**/*.html",
                "/**/*.css",
                "/**/*.js"
            )

            // Un-secure H2 Database (for testing purposes, H2 console shouldn't be unprotected in production)
            .and()
            .ignoring()
            .antMatchers("/h2-console/**/**");
    }

类似于正则的**或者*都表示什么含义呢?查询了相关文档,简单的做一下总结,方便日后查询。

  1. ?匹配一个字符(matches one character)。
  2. *  匹配0个或者多个字符 ( matches zero or more characters)。
  3. ** 匹配url中的0个或多个子目录 (matches zero or more directories in a path)
  4. {spring:[a-z]+} 匹配满足正则表达式[a-z]+的路径,这些路径赋值给变量”spring” (matches the regexp [a-z]+ as a path variable named “spring”)

例子:

  1. com/t?st.jsp  匹配com/test.jsp,也匹配com/tast.jsp或者com/txst.jsp (matches com/test.jsp but also com/tast.jsp or com/txst.jsp)
  2. com/*.jsp  匹配com路径下所有的.jsp文件。个人理解这里应该是直接包含的,不支持递归,比如com/good/*.jsp应该是匹配不上的。(matches all *.jsp files in the com directory)
  3. com/**/test.jsp  匹配com路径下所有的test.jsp文件。个人理解这里是支持递归的,表示com路径下所有的test.jsp文件,例如:com/1/test.jsp, com/2/test.jsp, com/test.jsp 或者 com/java/1/test.jsp应该都可以匹配成功。(matches all test.jsp files underneath the com path)
  4. org/springframework/**/*.jsp 匹配 org/springframework路径下所有的jsp文件。(matches all .jsp files underneath the org/springframework path)
  5. org/**/servlet/bla.jsp 匹配org/springframework/servlet/bla.jsp,同时也匹配 org/springframework/testing/servlet/bla.jsp和org/servlet/bla.jsp (matches org/springframework/servlet/bla.jsp but also org/springframework/testing/servlet/bla.jsp and org/servlet/bla.jsp)
  6. com/{filename:\\w+}.jsp  匹配com/test.jsp 同时将”test”赋值给变量”filename”。(match com/test.jsp and assign the value “test” to the “filename” variable)

如本文“对您有用”,欢迎随意打赏作者,让我们坚持创作!

0 打赏
Enamiĝu al vi
不要为明天忧虑.因为明天自有明天的忧虑.一天的难处一天当就够了。
543文章 68评论 294点赞 593926浏览

随机文章
SpringMVC—ContentNegotiation内容协商机制
3年前
Git分支管理—4
5年前
SpringSecurity—OAuth 2-Spring Cloud 安全管理
5年前
SpringSecurity—防御 CSRF 攻击
4年前
SpringSecurity—OAuth 2(八)客户端信息入库
5年前
博客统计
  • 日志总数:543 篇
  • 评论数目:68 条
  • 建站日期:2020-03-06
  • 运行天数:1927 天
  • 标签总数:23 个
  • 最后更新:2024-12-20
Copyright © 2025 网站备案号: 浙ICP备20017730号 身体没有灵魂是死的,信心没有行为也是死的。
主页
页面
  • 归档
  • 摘要
  • 杂图
  • 问题随笔
博主
Enamiĝu al vi
Enamiĝu al vi 管理员
To be, or not to be
543 文章 68 评论 593926 浏览
测试
测试
看板娘
赞赏作者

请通过微信、支付宝 APP 扫一扫

感谢您对作者的支持!

 支付宝 微信支付