From the course: Extending, Securing, and Dockerizing Spring Boot Microservices

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Securing APIs

Securing APIs

- [Instructor] So, now that some APIs in TourRatingController requires pre-authorization, guess what? Those JUnit API tests are now failing. So, we see that I've run all the tests in TourRatingControllerTest and delete updateWithPut, createTourRating and createManyTourRatings which are the endpoints that require pre-authorization to have the CSR role are failing. The problem is we need to make a restTemplate request that also includes an HttpEntity object where we can put in a JWT token. Let's look at a specific test, probably the easiest one in here is delete because it doesn't have a payload and it doesn't really have a response payload either. So, in the delete method on restTemplate, we don't have the ability to add a header, so we need to add a header with the restTemplate exchange method. So, I'm going to change this to exchange. And I'm using the same URL. Then I have to have the verb, the HttpMethod delete and then I need a new HttpEntity object and having a parameter of null…

Contents