我是 Spring Cloud 的新手。我正在尝试集成 Spring Cloud Gateway(Spring Cloud Finchley.SR1) 只是为了验证和路由我的请求。
My Application stack is as follows
- 主仪表板应用程序使用 Spring MVC 和 Angular 构建。它有登录页面和仪表板。其中集成了身份验证,可根据数据库对用户凭据进行身份验证。我还在这个应用程序中使用 hazelcast 进行 session 复制。
- 一组下游服务,一旦用户登录到上述仪表板并在其中导航,就会调用这些服务。
- 使用 Spring Cloud Gateway 构建的 API 网关:目前它仅执行路由操作。
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}
Need to implement following
- 第一个请求将到达网关,我需要检查用户是否已通过身份验证,如果未通过身份验证,则我需要显示仪表板应用程序(即第一个应用程序)的登录页面,否则允许用户继续。
- 用户登录并在仪表板内导航后,对下游服务的 API 请求也将通过 API 网关,我还需要对这些请求进行身份验证,如果用户未通过身份验证,则发送 403 状态。
I am not able to figure out how to handle these authentications in spring cloud gateway app. Is it possible to leverage hazelcast session replication that I added in Main Dashboard App, use it validate the user in gateway?
Or is there any better approach using spring cloud suite tools that I can use it here. A sample app will be useful
最佳答案
就我而言,我在 Spring Security 2.0.5 中自定义了 AuthenticationWebFilter 类。 我在AuthenticationWebFilter中定制了ServerAuthenticationConverter类和SuccessHandler、FailureHandler和ReactiveAuthenticationManager类。 如果您使用 Spring security,我建议搜索 WebFilter。 我希望它有帮助。
关于java - Spring Cloud Gateway 中的身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51891450/