【发布时间】:2018-08-29 05:47:35
【问题描述】:
我正在使用 SpringBoot 开发具有微服务架构的 Rest Backend。为了保护端点,我使用了 JWT 令牌机制。我正在使用 Zuul API 网关。
如果请求具有所需的权限(来自 JWT 的 ROLE),它将被转发到正确的微服务。 Zuul api网关的“WebSecurityConfigurerAdapter”如下。
@Autowired
private JwtAuthenticationConfig config;
@Bean
public JwtAuthenticationConfig jwtConfig() {
return new JwtAuthenticationConfig();
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.logout().disable()
.formLogin().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.anonymous()
.and()
.exceptionHandling().authenticationEntryPoint(
(req, rsp, e) -> rsp.sendError(HttpServletResponse.SC_UNAUTHORIZED))
.and()
.addFilterAfter(new JwtTokenAuthenticationFilter(config),
UsernamePasswordAuthenticationFilter.class)
.authorizeRequests()
.antMatchers(config.getUrl()).permitAll()
.antMatchers("/api/user/**").permitAll()
.antMatchers("/api/package/**").hasRole("USER")
.antMatchers("/api/dashboard/**").hasRole("USER")
.antMatchers("/api/records/**").hasRole("USER");
}
这样我必须在这个类中编写每个请求授权部分。所以我希望通过“EnableGlobalMethodSecurity”来使用方法级别的安全性。
问题是我应该如何将这个安全机制与其他微服务连接起来。因为当我将 spring 安全依赖添加到其他微服务时,它们表现为不同的 spring 安全模块。我应该如何告诉其他使用 zuul server security 的微服务?
【问题讨论】:
标签: spring spring-boot spring-security netflix-zuul