Provide a unique key to your client. Which your microservice recognises and authenticates any request based on that key. This can be also given as a request parameter
.
let say you add your key into a parameter called my-key
, now before working on your logic inside you spring-boot app validate your key. like this -
your Rest Controller would look like this-
@RestController
class MyRest{
private static final String KEY = "someValue";
@RequestMapping("/some-mapping")
public @ResponseBody myMethod(@RequestParam(value="my-key", required=true) String key){
if(!validateRequest(key)){
//return error as response
}
System.out.println("Key Validation Successful!");
//here goes your logic
}
private boolean validateRequest(String key){
return key.equals(KEY);
}
}
in order to access this rest use - http://your-host:port/some-mapping?my-key=someValue