【问题标题】:Spring Security antMatchers RegexSpring Security antMatchers 正则表达式
【发布时间】:2018-07-17 05:14:45
【问题描述】:

我的 spring 安全配置中已经有 antmatchers() 使用通配符。我需要从这个通配符中过滤掉“表格”。 这是我的原始代码:

    .antMatchers("/api/keepSessionAlive").authenticated()
    .antMatchers("/api/users/**").authenticated()

我尝试将通配符更改为正则表达式,如下所示,但它对我不起作用:

   .antMatchers("/api/users/(?!forms).*").authenticated() 

任何帮助将不胜感激

【问题讨论】:

标签: regex spring spring-security spring-java-config


【解决方案1】:

请在“/users/**”antMatchers 之前添加“/users/forms”过滤器

.antMatchers("/api/keepSessionAlive").authenticated()
.antMatchers("/api/users/forms/**").authenticated() 
.antMatchers("/api/users/**").authenticated()

【讨论】:

    【解决方案2】:

    只需在其他人之前为“form”添加一个antmatcher,并将其保持为permit-all,如下所示:

    .antMatchers("/api/users/form").permitAll()
    .antMatchers("/api/keepSessionAlive").authenticated()
    .antMatchers("/api/users/forms/**").authenticated() 
    .antMatchers("/api/users/**").authenticated()
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2013-12-30
      • 2015-09-14
      • 1970-01-01
      • 2019-09-27
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 2015-02-23
      • 2015-12-29
      相关资源
      最近更新 更多