【问题标题】:Spring oauth2 : Access any resource server endpoint without AuthenticationSpring oauth2:无需身份验证即可访问任何资源服务器端点
【发布时间】:2018-01-18 23:41:46
【问题描述】:

我有一个场景,我想允许用户从客户端应用程序(在 8080 运行)访问资源服务器(在 8098 运行)上的特定端点,而无需身份验证。当我试图在没有客户端身份验证的情况下访问它时,它会给出错误访问被拒绝。但是当我在用户登录后访问同一个端点时,它就可以工作了。

我在资源服务器上有以下配置:

    @Configuration
    @EnableResourceServer
    public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

        @Autowired
        private CustomUserDetailsService userDetailsService;

        public ResourceServerConfiguration() {
            super();
        }

        @Override
        public void configure(HttpSecurity http) throws Exception {
             http
                .anonymous()
                .and()
                .authorizeRequests()
                .antMatchers("/api/requestdetails/view-all-details/**").permitAll()
                .anyRequest().authenticated()
        }
}

基本上我想让这个端点“/api/requestdetails/view-all-details/** 不安全。因此用户无需身份验证即可访问它。

【问题讨论】:

    标签: spring-boot spring-security spring-oauth2


    【解决方案1】:

    我对配置方法做了一些更改,现在它可以工作了。

        @Configuration
        @EnableResourceServer
        public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
    
            @Autowired
            private CustomUserDetailsService userDetailsService;
    
            public ResourceServerConfiguration() {
                super();
            }
    
    
            @Override
            public void configure(HttpSecurity http) throws Exception {
                 http
                    .antMatcher("/**")
                    .authorizeRequests()
                    .antMatchers(HttpMethod.GET, "/api/requestdetails/view-all-details/**").permitAll()
                    .antMatchers("/api/**").authenticated()
    
    
            }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-25
      • 2018-08-05
      • 2015-01-08
      • 2018-09-11
      • 2020-11-21
      • 2020-01-13
      • 1970-01-01
      相关资源
      最近更新 更多