简体   繁体   English

Spring微服务之间的通信

[英]Communication between Spring microservices

I am still learning microservices and I am asking myself, how do we secure our rest-points? 我仍在学习微服务,我在问自己,我们如何确保我们的休息点? I use the famous framework Spring Boot which extends from Spring. 我使用了著名的Spring Boot框架,它是从Spring扩展而来的。 What is the best or most used pattern to secure the endpoints of a rest API? 什么是保护Rest API端点的最佳或最常用的模式?

When I use Spring Security with oAuth2, I always need to send the credentials in the body of the request. 当我将Spring Security与oAuth2结合使用时,我总是需要在请求的正文中发送凭据。 Is there an approach without the credentials and which is easier to implement? 是否有没有凭证的方法,哪种方法更易于实施? Like API-Tokens? 像API令牌一样?

I always prefer practical tutorials. 我总是喜欢实用的教程。

I can suggest to look into spring security and various options that it provides. 我可以建议研究一下Spring Security及其提供的各种选项。 If however you are looking from microservices standpoint, you are on a right path with access tokens and as suggested JWT will do good. 但是,如果您从微服务的角度来看,那么您在使用访问令牌的道路上就正确无误,并且如建议的那样, JWT会做得很好。 No to get a JWT you can opt for another small auth service using say Pac4j or similar tools out there. 不需要JWT,您可以使用Pac4j或其他类似工具来选择其他小型身份验证服务。

I prefer to use keycloak initially Its a open source IAM There are several examples that you can find as to how to get started with Keycloak and Spring boot But here is the one that I wrote some time back . 我更喜欢使用keycloak最初它是一种开源的IAM有几个例子,你可以找到关于如何获得与Keycloak和春天开机启动,但这里是一个 ,我写了一段时间回来。

-- Just to add that for microservices it makes sense to use AccessTokens as you are not required to keep user creds and pass it along every service and also services can verify the tokens all by themselves without making an expensive network call to your auth service. -补充一点,对于微服务来说,使用AccessToken是有意义的,因为您无需保留用户信誉并将其传递给每个服务,服务也可以自行验证令牌,而无需对身份验证服务进行昂贵的网络调用。

我可以建议看一下这个示例(使用“服务器”范围): https : //github.com/sqshq/PiggyMetrics以及更高级的配置: http : //cloud.spring.io/spring-cloud-config/弹簧云config.html#_security

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM