What I propose is not a design by simply a standardize high-level
function API to check authorization. I currently use the following:
def checkRole(role='admin'):
# checkRole implementation.
In simple word, a checkRole function taking a string for the role, by
default 'admin'. How this is mapped internally, how role and identities
are implemented, represented and accessed is hidden from the API.
Currently checkRole() sets a turbogears flash error then redirect to
the login page ("/" on my site). Maybe checkRole could be extended to
be:
def checkRole(role='admin',error='You are not
authorized.',redirect='/')
# checkRole implementation.
A few points of discussion:
- How to plugin the checker? By setting a pre-defined tg variable?
- Alternative check result: specifiable exception, callback?
- Check without raising error? This currently can be done by a try:
block.
I also think separating authentication API and authorization APi is a
good thing, although a given implementation can (and probably will)
make them common internally for obvious reasons.
I also think it's important to to force a UI down user throats. Your
design could be applied if I can use my existing main-page login form
as a front-end and have your system with a single "hard-coded" (at
deployment) permission.
Why do you feel a user/role many-to-many design is not enough? I don't
see what having group+permission provides above roles.
I'd suggest that you break up your package into the decorator + filter
and your particular implementation anyway, so that it's easier to
deploy one without the other since you obviously already envisioned
such a scenario.
>Because I'm building a content management system, I need permissions
>like "edit-entity" which can be granted to members of the "author"
>and "editor" groups, and "approve-entity" which can be limited to
>members of the "editor" group.
That's what I thought. Permissions are more for CMS-like needs. Again,
separating the implementation for user+group and permission would be a
good idea in my opinion, but I suppose it may be hard to avoid any
permission reference in groups...?
I drool at the thought of not having to come up with another
username/password for every Web 2.0 site I try. ;-)
-Curtis