Skip to content
Ameen Abozaid
Planned lessonJNR-040-L06

Demo: method security with ownership checks

  • Lesson 6 of 6
  • Junior
On This Lesson 3 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

combine roles and ownership in the service layer. Prepares JNR-040-LAB1.

Draft outline details

Step by step

  1. Enable method security.
  2. Add @PreAuthorize("hasRole('ADMIN')") to the "list all orders" service method.
  3. Add a service method getMyOrders(currentUser) that filters by owner.
  4. Remove customerId from the create-order request body and take it from the principal.
  5. Planned mistake: leaving the customerId in the body, so customer A creates an order for B. Show the attack, then fix.
  6. Add tests for customer A, customer B, and admin.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Type to search levels, phases, modules and lessons.