How can I allow only one micorservice method request with a specific URL @PathVariableper user. My controller
@RestController
@RequestMapping(value = "/rest/product", produces = "application/json;charset=UTF-8")
public class ProductRestController {
@Autowired
ProductService productService;
@Autowired
ProductAsm productAsm;
@RequestMapping(value = "/ID/{ID}", method = RequestMethod.GET)
public ResponseEntity<ProductResource> getProductID(@PathVariable("ID") Long ID, @AuthenticationPrincipal User) {
Product product = productService.getProduct(ID);
if (product == null)
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(productAsm.toResource(product), HttpStatus.OK);
}
For example:
- first request
/rest/product/ID/2231allowed for USER (with login = "xaxa") - second request
/rest/product/ID/2545allowed for USER (with login = "xaxa") - Third request is
/rest/product/ID/2231not allowed for USER (with login = "xaxa")
What is the best way to implement this functionality? (Should I store this request URL with the user login in the database or is there already a solution)
source
share