Reputation: 2593
I send along every REST call my custom header, which is (for instance) an authorization token. This token remains the same, as I do not need high security in this case. Can I use some simple way how to check every request coming to RestController whether it has this token among headers?
Upvotes: 1
Views: 1512
Reputation: 8965
I can see a few ways:
Coding a @ModelAttribute
in a @ControllerAdvice
class, like this
@ControllerAdvice
public class HeaderFetcher {
@ModelAttribute
public void fetchHeader(@RequestHeader Optional<String> myHeader, Model model) {
if header is present
model.addAttribute("myHeader", the header);
else
throw exception
}
}
Haven't tried this, though.
Upvotes: 1