Search code examples
javaspringannotationsspring-data-jpajpql

Spring @PreAuthorize is not working on PATCH request


In the following code I want to update the rider , Query works fine but I also want to check the authority of logged-In user but following code is not working

In the First query completeOrder @PreAuthorized annotation works but inthe second query it does not work

public interface OrderRepository extends JpaRepository<Order, Long> {

     @PreAuthorize("hasAuthority('rights')")
     @Query("Select o from Order o where o.orderStatus='DELIVERED'")
     List<Order> completedOrder(); 

     @PreAuthorize("hasAuthority('rights')")
     @Modifying
     @Query("Update Order o set o.rider=:riderId where o.id= :orderId")
     List<Order> changeRider();
}

Solution

  • My Problem is solved now, mistake is not in my code , actually I am sending different API call and check this API :| My bad