I'm creating an asp.net mvc application that has the concept of users. Each user is able to edit their own profile. For instance:
Nothing particularly exciting there...
However, I have run into a bit of trouble with the Authorization scheme. There are only two roles in the system right now, "Administrator" and "DefaultUser", but there will likely be more in the future.
I can't use the regular Authorize attribute to specify Authorization because both users are in the same role (i.e., "DefaultUser").
So, if I specify the Authorize Filter like so:
[Authorize(Roles = "DefaultUser")]
then there is no effect. PersonID=1 can go in and edit their own profile (as they should be able to), but they can also just change the URL to http://localhost/person/edit/2 and they have full access to edit PersonID=2's profile as well (which they should not be able to do).
Does this mean that I have to create my own Authorization filter that checks if the action the user is requesting "belongs" to them before allowing them access? That is, if the edit action, with parameter = 1 is being requested by the currently logged in person, do I need to do a custom check to make sure that the currently logged in person is PersonID=1, and if so, authorize them, and if not, deny access?
Feels like I'm missing something obvious here, so any guidance would be appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…