Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC: Authorization inside an Action - Suggested Patterns or this is a smell?
    primarykey
    data
    text
    <p>I have an ASP.NET MVC application using Authorization Attributes on Controllers and Actions. This has been working well but a new wrinkle has shown up.</p> <p>Object: Shipment</p> <p>Roles: Shipping, Accounting, General User</p> <p>The Shipment moves through a workflow. In state A it can be edited by Shipping only. In state B it can be edited by Accounting only.</p> <p>I have a ShipmentController, and an Edit Action. I can put an Authorization attribute to limit the Edit action to only those two roles, but this doesn't distinguish between which state the Shipment is in. I would need to do some Authorization inside the action before the service call to determine if the user is really authorized to execute the edit action.</p> <p>So I'm left with two questions:</p> <p>1) Whats a good way to have authorization inside an Action. The Controller Action calls to a service, and the service then makes appropriate calls to the Shipment object (update quantity, update date, etc). I know for sure I want the Shipment object to be agnostic of any authorization requirements. On the other hand, I don't have a real grasp if I would want the service object to know about authorization or not. Are there any good patterns for this?</p> <p>2) Is my problem actually a symptom of bad design? Instead of ShipmentController should I have a StateAShipmentController and StateBShipmentController? I don't have any polymorphism built into the Shipment object (the state is just an enum), but maybe I should and maybe the Controllers should reflect that.</p> <p>I guess I'm after more general solutions, not a specific one for my case. I just wanted to provide an example to illustrate the question.</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload