开发者社区> 问答> 正文

如何在Spring Boot OAuth2中允许来自特定主机的特定端点

我们已经使用spring认证服务器来提供我的其他spring boot应用程序(资源服务器)。有些端点不需要为特定主机进行身份验证。

我使用了下面的代码示例,但它仅在没有OAuth服务器的情况下有效。

@Override
public void configure(final HttpSecurity http) throws Exception {
    http.authorizeRequests().antMatchers("/url/**").permitAll().

anyRequest()。authenticated(); }

展开
收起
垚tutu 2019-12-19 16:39:10 677 0
1 条回答
写回答
取消 提交回答
  • #include

    你有没有尝试过

    @Configuration
    @EnableWebSecurity
    @EnableGlobalMethodSecurity(prePostEnabled = true)
    @Order(2)
    public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http
                    .antMatcher("/**")
                    .authorizeRequests()
                        .antMatchers("/media/allVideos")
                            .permitAll()
                    .anyRequest()
                        .authenticated();   
        }
    }
    
    2019-12-19 16:39:23
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载