spring配置只授权一个url

qyswt5oh  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(307)

我只想在我的应用程序中授权一个url,例如:/hello使用jwt令牌。我想让rest的所有方法都能通过而不需要任何身份验证。有人能帮我弄清楚我的配置文件中应该有什么才能工作吗?
下面是我目前的情况

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

tvokkenx1#

您可以使用以下代码段只允许“/hello”端点,

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

相关问题