【问题标题】:Spring Zuul Oauth2 Gateway/Resource ServerSpring Zuul Oauth2 网关/资源服务器
【发布时间】:2018-10-13 15:22:57
【问题描述】:

是否可以将 Zuul 用作“假”资源服务器,在返回代理内容之前检查 OAuth2 范围?

类似:

incoming request (with token) -> Zuul proxy + resource server -> internal API (insecure)

内部 API 服务可以从任何安全问题中解脱出来,Zuul 代理服务充当网关。如果有区别的话,以上所有的都是 Spring 应用程序。

【问题讨论】:

    标签: spring spring-security oauth netflix-zuul


    【解决方案1】:

    绝对

    您还必须为资源服务器配置配置 创建一个扩展 ResourceServerConfigurerAdapter 并覆盖 configure(HttpSecurity security) 方法的 bean ResourceServerConfig。使用@EnableResourceServer 注解对其进行注解。

    类似的东西

    @Configuration
    @EnableResourceServer
    public class OAuth2ResourceServerConfig extends ResourceServerConfigurerAdapter {
    
        @Override
        public void configure(HttpSecurity http) throws Exception {
            http.sessionManagement()
                    .sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
                    .and()
                    .authorizeRequests()
                    // .antMatchers("/swagger*", "/v2/**")
                    // .access("#oauth2.hasScope('read')")
                    .anyRequest()
                    .permitAll();
        }
    
        @Bean
        @Primary
        public DefaultTokenServices tokenServices() {
            DefaultTokenServices defaultTokenServices = new DefaultTokenServices();
            defaultTokenServices.setTokenStore(tokenStore());
            return defaultTokenServices;
        }
    
        @Bean
        public TokenStore tokenStore() {
    
            return new JwtTokenStore(accessTokenConverter());
        }
    
        @Bean
        public JwtAccessTokenConverter accessTokenConverter() {
            JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
             converter.setSigningKey("123");
    
    //        Resource resource = new ClassPathResource("publicKey.txt");
    //        String publicKey = null;
    //
    //        try {
    //            publicKey = IOUtils.toString(resource.getInputStream(), Charset.defaultCharset());
    //        } catch (final IOException e) {
    //            throw new RuntimeException(e);
    //        }
    //        converter.setVerifierKey(publicKey);
            return converter;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 2018-04-14
      • 2016-05-21
      • 2019-11-27
      • 2021-02-07
      • 2014-07-09
      • 2016-01-18
      • 2017-09-13
      • 2018-08-29
      相关资源
      最近更新 更多