Spring Security Authentication using RestTemplate

后端 未结 7 1140
你的背包
你的背包 2020-12-02 17:58

I have 2 spring web apps that provide 2 separate set of services. Web App 1 has Spring Security implemented using a user-based authentication.

Now, Web App 2 needs

相关标签:
7条回答
  • 2020-12-02 18:39

    The currently authenticated user credentials should be available in Web App 1 on Authentication object, which is accessible through SecurityContext (for example, you can retrieve it by calling SecurityContextHolder.getContext().getAuthentication()).

    After you retrieve the credentials, you can use them to access Web App 2.

    You can pass "Authentiation" header with RestTemplate by either extending it with a decorator (as described here) or using RestTemplate.exchange() method, as described in this forum post.

    0 讨论(0)
提交回复
热议问题