Holiday service runs through spring

I created a spring application, I have one requirement to use the recreation service and just expose the same through my spring application due to some security

ie for the remaining service that I use, I provide security credentials that only my application should know and expose the same service through my spring application.

I could write a wrapper service for each recreation service that I use with the appropriate authentication, and expose these wrapper services that can be authenticated using my spring Auth credentials credentials

But this is a big job, which I mainly do is use webservice and expose the same with some auth mapping. Spring has the ability to go through the rest of the services.

+4
source share
1 answer

Why not just expose the REST service for each type of HTTP request and forward it based on the information in the path? For example (untested probably will not work as is, but you get the main idea):

@Autowired RestTemplate restTemplate; @Value("${rest.proxy.target.base.url}") String targetBaseUrl; @RequestMapping(value = "/restProxy/{restUrlPath}", method = RequestMethod.GET) public @ResponseBody String restProxyGet(@PathVariable("restUrlPath") String restUrlPath) { return restTemplate.getForObject(targetBaseUrl+ "/" + restUrlPath, String.class); } @RequestMapping(value = "/restProxy/{restUrlPath}", method = RequestMethod.POST) public @ResponseBody String restProxyPost(@PathVariable("restUrlPath") String restUrlPath, @RequestBody String body) { return restTemplate.postForObject(targetBaseUrl + "/" + restUrlPath, body, String.class); } //Can also add additional methods for PUT, DELETE, etc. if desired 

If you need to communicate with different hosts, you can simply add another path variable that acts as the key to the map, which stores different destination base URLs. You can add any authentication you want from the controller, or using special authentication in Spring Security.

Your question is somewhat covered in detail, so your specific scenario may complicate the situation, but the basic approach should work.

+3
source

All Articles