【问题标题】:Spring Security antMatcher expression not works with path variableSpring Security antMatcher 表达式不适用于路径变量
【发布时间】:2017-01-19 09:09:48
【问题描述】:

我需要提供特定的角色来访问以下格式的 URL:

/connector/{programId}/order/{anything here}

programId 是一个整数值,所以我尝试了以下方法,但它根本不起作用。

.antMatchers('/connector/{programId:\\d+}/order/**').access("hasRole('CONNECTOR')")

但是当我使用 ** 而不是 programId 部分时,它运行良好。但是我怎样才能让它与 pathVariable (它总是一个整数)一起工作。

【问题讨论】:

    标签: java regex spring spring-security configuration


    【解决方案1】:

    您应该使用RegexRequestMatcher 而不是AntPathRequestMatcher

    .regexMatchers("/connector/(\\d+)/order/.*").access("hasRole('CONNECTOR')")
    

    【讨论】:

      【解决方案2】:

      我正在使用: .regexMatchers("/connector/(\\d+)/order/.*").access("hasRole('CONNECTOR')") 但是服务器响应405错误

      【讨论】:

        猜你喜欢
        • 2018-06-26
        • 2016-01-11
        • 1970-01-01
        • 1970-01-01
        • 2021-01-17
        • 2016-06-23
        • 2018-06-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多