当前位置: 首页 > 知识库问答 >
问题:

在spring boot micro服务中向Zuul服务添加Spring Security性

彭成天
2023-03-14

我是微服务架构的新手。我们有一些服务,如zuul服务(api网关)、安全服务(连接到数据库检查访问)和xyz服务。

我想知道,我们如何在zuul服务中定义的路线中添加Spring Security性。?

在zuul服务上定义如下所示的授权请求时,它应该在内部调用安全服务并对请求进行身份验证。

示例:

.authorizeRequests()
.antMatchers("/user/count").permitAll()
.antMatchers("/user/**").authenticated()

注意:/security service中定义了用户endpoint。

请帮我拿这个。

共有1个答案

东方文林
2023-03-14

我们的Zuul代理支持OAuth2安全性。安全配置的一个示例如下:

@Configuration
@EnableResourceServer
public class JwtSecurityConfig extends ResourceServerConfigurerAdapter {

    @Override
   public void configure(HttpSecurity http) throws Exception {
       http.authorizeRequests()
            .antMatchers("/oauth/**").permitAll()
            .antMatchers("/**").hasAuthority("ROLE_API_ACCESS")
            .and()
            .csrf().disable();
   }
}

我假设如果你在做基本的身份验证,你可以使用适当的类做类似的事情。也许像这样。

@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        BasicAuthenticationEntryPoint authenticationEntryPoint = new BasicAuthenticationEntryPoint();

authenticationEntryPoint
   .setRealmName("EnterpriseDeviceAuthentication");
        http
            .authorizeRequests()
            .antMatchers("/health").permitAll() // allow access to health page
            .antMatchers("/somepath").permitAll()
            .antMatchers("/somepath2").permitAll()
            .antMatchers("/bootstrap.min.css").permitAll() 
            .anyRequest().hasAnyAuthority(SecurityRoles.ALL_SECURITY_ROLES)
            .and().httpBasic()
            .authenticationEntryPoint(authenticationEntryPoint)
            .and()
            .csrf().disable();
    }

}
 类似资料:
  • 我只有很少的spring boot微服务,它们是通过云环境部署到JBoss的。这些引导服务是在Eureka服务器中注册自己的Eureka客户端。下面是一个例子: 它用user-regn-service-app Eureka主页的名称向Eureka注册应用程序 wildfly服务器在8080处运行,而user-regn-service-app部署在上下文路径/user-regn-service-ap

  • 我在我的项目中使用微服务架构。对于服务间通信,我使用消息队列NATS。我写了一个网关,处理所有超文本传输协议请求,并将其放入队列。所有终端服务都订阅到这个队列。 在endpoint服务中,我使用基于Netty IO的Xitrum。当我从队列中得到请求时,我将其反序列化为FullHttpRequest。但我不知道如何将它发送到我的netty服务器,它可以根据业务逻辑处理它(例如,不使用可以将它发送到

  • 我有一个网络服务,比如: 在链接中: 我正在尝试通过链接中的AlFresco获取此Web服务的响应:。我现在有不同的端口(当我有相同的端口时,这很好地工作),所以,使用不同的端口,我在AlFresco中得到错误: 跨源请求被阻止:同一源策略不允许在以下位置读取远程资源:http://localhost:8081/ChangesPDF/Changes?...(原因:缺少CORS的“访问控制允许原点”

  • 找到解决方案-检查底部 我知道有很多与我类似的问题,但我已经为此工作了几天,不知道如何让它工作。 我正在尝试将谷歌播放服务合并到我的应用程序中,以使用推送通知。 以下是我到目前为止所做的: > < li >创建了一个全新的项目 < li >导入“google-play-services_lib”并选择“将项目复制到工作区” < li >进入项目- proguard.config=${sdk.dir

  • 我尝试在server.xml中添加一个新的docbase,以便在我的tomcat服务器中定义一个上传目录。然而,如果我将它添加到我的独立tomcat服务器上,它会像魔咒一样工作: 但是在我的本地eclipse tomcat服务器配置中它不起作用。我的发布操作是“更新上下文路径”,我在服务器选项卡中使用“工作区元数据”。 知道我哪里做错了吗?

  • 我刚在我的科尔多瓦项目中添加了OneSignal。这似乎使用Google Play服务,即(我得到一个消息“没有有效的Google Play服务APK找到”)。我想知道添加它的最佳方法。 我的手机上安装了Google Play services V8.4.89。 我通过SDK管理器安装了Google Play服务: 这将创建一个google_play_services文件夹(其中没有很多内容):