Limiting access to data of other users

Now, this is a little more tricky, as this requires us to change code at the service layer on the backend, but it is not hard. Let's get right to it.

Let's start with the product order entity. Let's modify the findAll method in src/main/java/com/mycompany/store/service/ProductOrderService.java as follows:

    @Transactional(readOnly = true)    public Page<ProductOrder> findAll(Pageable pageable) {        log.debug("Request to get all ProductOrders");        if (SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {            return productOrderRepository.findAll(pageable);        } else            return productOrderRepository.findAllByCustomerUserLogin(                SecurityUtils.getCurrentUserLogin().get(),                pageable            );    }

As you can see, we modified ...

Get Full Stack Development with JHipster now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.