【问题标题】:Authentication in spring cloud gatewaySpring Cloud Gateway 中的身份验证
【发布时间】:2018-08-17 08:37:03
【问题描述】:

我是spring cloud的新手。我正在尝试集成 spring cloud gateway(spring cloud Finchley.SR1) 只是为了验证和路由我的请求。

我的应用栈如下

  • 主仪表板应用程序使用 spring mvc 和 angular 构建。它有登录页面和仪表板。身份验证集成在其中,根据数据库对用户凭据进行身份验证。我还在此应用中使用 hazelcast 进行会话复制。
  • 一组下游服务,一旦用户登录到上面的仪表板并在其中导航,就会调用这些服务。
  • 一个使用spring cloud gateway构建的API Gateway:目前它只做路由。
  cloud:
    gateway:
      routes:
        - id: customers
          uri: http://localhost:8282/customers
          predicates:
          - Path=/customers/**
          - Header=employeeId, \d+
          filters:
          - RewritePath=/customers/(?<segment>.*), /$\{segment}
        - id: rates
          uri: http://localhost:8383/rates
          predicates:
          - Path=/rates/**
          filters:
          - RewritePath=/rates/(?<segment>.*), /$\{segment}

需要实现以下

  • 第一个请求将到达网关我需要检查用户是否已通过身份验证,如果未通过身份验证,则我需要显示仪表板应用程序(即第一个应用程序)的登录页面,否则允许用户继续。 em>
  • 一旦用户登录并在仪表板内导航,那么对下游服务的 api 请求也将通过 api 网关 我还需要对这些请求进行身份验证,如果用户未通过身份验证,则发送 403 状态。

我无法弄清楚如何在 spring cloud gateway app 中处理这些身份验证。是否可以利用我在 Main Dashboard App 中添加的 hazelcast 会话复制,使用它在网关中验证用户?

或者有没有更好的方法使用我可以在这里使用的 spring 云套件工具。一个示例应用会很有用

【问题讨论】:

  • 我有类似的要求。我能够重定向请求,但不确定如何验证请求。您是否能够使用 Spring Cloud Gateway 做到这一点?如果是,您能否分享一些如何开始使用身份验证的想法?

标签: java spring spring-boot spring-cloud spring-cloud-gateway


【解决方案1】:

就我而言,我在 Spring Security 2.0.5 中自定义了 AuthenticationWebFilter 类。 我在AuthenticationWebFilter中自定义了ServerAuthenticationConverter类和SuccessHandler、FailureHandler和ReactiveAuthenticationManager类。 如果您使用 Spring 安全性,我建议您搜索 WebFilter。 希望对你有帮助。

【讨论】:

    猜你喜欢
    • 2019-08-30
    • 2019-05-20
    • 2018-10-29
    • 2021-11-22
    • 2020-09-04
    • 2017-09-23
    • 2018-12-11
    • 2020-09-09
    • 2016-08-20
    相关资源
    最近更新 更多