【问题标题】:Spring Configuration to authorize only one URLSpring配置只授权一个URL
【发布时间】:2020-12-11 00:53:18
【问题描述】:

我只想在我的应用程序中授权一个 URL,例如:/hello 使用 JWT 令牌。我想允许所有方法在没有任何身份验证的情况下通过。有人可以帮我弄清楚我的配置文件中应该有什么才能让它工作吗?

以下是我目前拥有的

http.anonymous().disable().antMatcher("/hello").authorizeRequests().anyRequest().hasAuthority("myscope")
            .and().addFilterBefore(oauthApiFilter, UsernamePasswordAuthenticationFilter.class).csrf().disable();

【问题讨论】:

    标签: java configuration jwt


    【解决方案1】:

    您可以使用以下 sn-p 来只允许“/hello”端点,

    httpSecurity.antMatcher("/hello").authorizeRequests()
            .and().authorizeRequests().anyRequest().authenticated()
            .and().addFilterBefore(oauthApiFilter, UsernamePasswordAuthenticationFilter.class)
            .csrf().disable(); 
    

    【讨论】:

      猜你喜欢
      • 2016-09-11
      • 2018-11-13
      • 2019-06-20
      • 2021-01-29
      • 2020-08-09
      • 2017-08-09
      • 1970-01-01
      • 2015-04-24
      • 2016-12-12
      相关资源
      最近更新 更多