3

我是春天云的新手。我正在尝试集成 spring 云网关(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}

需要实现以下

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

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

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

4

1 回答 1

0

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

于 2019-01-14T08:15:28.370 回答