农民代表
- 积分
- 5043
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2015-10-22
- 最后登录
- 1970-1-1
|
Microservice中你想用spring security跟单体略有不同,得用distributed的验证模式。
首先用户登录,请求抵达API gateway(service1),这个可以用Spring Cloud Gateway来实现,这时在API gateway后面你需要一个centralized的authentication server(service2)用来验证用户身份,可以用Spring Security OAuth2来实现,验证成功后authentication server会返回一个token给用户,因为通常都是https requests,所以用JWT Token较多;
然后,用户新的request拿着上一步的token,发request到API gateway(service1),因为有了token,这时候就不route去authentication server(service2)的login界面了,API gateway(service1)会校验这个token,成功后API gateway(service1)会redirect到你真正的业务serviceA,serviceB。。。
最后,业务services处理用户需求并返回用户response |
|