Open evillemez opened 10 years ago
This sounds good to me. Possible changes:
Looks good to me too!
After discussion with me and Evan today, we've decided that we probably don't need ABSTAIN; ALLOW and DENY are enough to cover all the use cases we can think of.
In order to account for a lot of complexity that we're going to run into, we know we can't rely solely on role mappings to guard policies. This proposes a new Authorizer/Decider set of interfaces, and reimplements the current role authorization mechanism as just one of potentially many Decider implementations.
Authorizer and Decider API
In this scenario, current Kalinka authorizer usage would not change, though the meaning would be slightly different. Currently, when you call
$kalinka->can('edit', 'document', $document);
you are declaring that you will be checking theedit
action on thedocument
guard. This guard has been configured to check policy methods internally, based on how the user roles are configured, and who the subject is.In the new implementation when you call
$kalinka->can('edit', 'document', $document);
, you are checking theedit
action on any registered deciders in thedocument
domain. One of those deciders may or may not be theRoleDecider
, which then makes a decisions based upon its guards and configuration.Essentially, the current implementation just becomes one possible implementation of a more general interface.
Authorizor::can Behavior
Now that more than one
Decider
can make decisions, the results ofAuthorizer::can
need some more explanation. Generally, any call toAuthorizer::can
behaves like a blacklist, meaning as long as oneDecider
denies the action, the action is denied.This still allows us to represent roles in the
RoleDecider
as a whitelist - for example, if any role grants access, but other roles deny access, theRoleDecider
will still decide toallow
, and the check will still pass as currently is the case. However, when more complex cases come along, new deciders still have the ability to deny access to the check for their own reasons.Refactoring
The current
RoleAuthorizor
andGuard
system would need to be somewhat refactored, but not too much. Ultimately, I think it would work this way:AuthorizerInterface
changes to the above definitionRoleAuthorizor
becomesRoleDecider
and implementsDeciderInterface
RoleDecider
, rename these toDomainGuard
To represent our current usage, setup would now look something like this:
Bundle configuration in KalinkaBundle would need to be refactored somewhat - but again, probably not too much. Some names change, but ultimately how the
DomainGuard
andRoleDecider
work, and are configured, stays roughly the same.