The solution we worked with was to provide security using both the OAuth2 client_credentials workflow. This is an OAuth2 stream where clients request a token on their behalf and not on the calling user.
Check out Spring Cloud Security
1) Protect your services using @EnableResourceServer
@SpringBootApplication @EnableResourceServer public class Application ...
2) Make calls from one service to another using OAuth2RestTemplate
Check the Resource server token relay in http://cloud.spring.io/spring-cloud-security/spring-cloud-security.html , which will OAuth2RestTemplate you how to configure OAuth2RestTemplate forward detailed security information (token) from one service to another one.
3) Service A and Service B should be able to exchange data using these methods if they are configured using the same Oauth2 Client and Secret. This will be configured in the application.properties file of the application, which I hope will be introduced into the environment. Oauth2 Scopes can be used as role identifiers. Therefore, you can say that only the Client with Scopes (api-read, api-write) should have access to Endpoint A in Service A. This can be configured using Spring Security Authorization Configuration, as well as @EnableGlobalMethodSecurity
source share