|
NAMETree::Authz - inheritance-based authorization schemeVERSION0.02_1DEVELOPER RELEASERe-organised to return objects (blessed into the new class "Tree::Authz::Role"), instead of strings, which are now referred to as "roles" rather than "groups" in the documentation. Some method names changed to reflect the terminology.SYNOPSISuse Tree::Authz; my $roles = { superuser => [ qw( spymasters politicians ) ], spymasters => [ qw( spies moles ) ], spies => [ 'informants' ], informants => [ 'base' ], moles => [ 'base' ], politicians => [ 'citizens' ], citizens => [ 'base' ], }; my $authz = Tree::Authz->setup_hierarchy( $roles, 'SpyLand' ); my $superuser = $authz->role( 'superuser' ); my $spies = $authz->role( 'spies' ); my $citizens = $authz->role( 'citizens' ); my $base = $authz->role( 'base' ); $spies ->setup_permissions( [ qw( read_secrets wear_disguise ) ] ); $citizens->setup_permissions( 'vote' ); $base ->setup_permissions( 'breathe' ); foreach my $role ( $superuser, $spies, $citizens, $base ) { foreach my $ability ( qw( unspecified_ability spy spies read_secrets wear_disguise vote breathe can ) ) { if ( $role->can( $ability ) ) { print "$role can '$ability'\n"; } else { print "$role cannot '$ability'\n"; } } } # prints: superuser can 'unspecified_ability' # superpowers! superuser can 'spy' superuser can 'spies' superuser can 'read_secrets' superuser can 'wear_disguise' superuser can 'vote' superuser can 'breathe' superuser can 'can' spies cannot 'unspecified_ability' spies can 'spy' spies can 'spies' spies can 'read_secrets' spies can 'wear_disguise' spies can 'vote' spies can 'breathe' spies can 'can' citizens cannot 'unspecified_ability' citizens cannot 'spy' citizens cannot 'spies' citizens cannot 'read_secrets' citizens cannot 'wear_disguise' citizens can 'vote' citizens can 'breathe' citizens can 'can' base cannot 'unspecified_ability' base cannot 'spy' base cannot 'spies' base cannot 'read_secrets' base cannot 'wear_disguise' base cannot 'vote' base cannot 'breathe' # ! base cannot 'can' # !! # storing code on the nodes (roles) of the tree $spies->setup_abilities( read_secret => $coderef ); print $spies->read_secret( '/path/to/secret/file' ); $spies->setup_plugins( 'My::Spies::Skills' ); $spies->fly( $jet ); # My::Spies::Skills::fly DESCRIPTIONClass for inheritable, role-based permissions system (Role Based Access Control - RBAC).Custom methods can be placed on role objects. Authorization can be performed either by checking whether the role name matches the required name, or by testing (via "can") whether the role can perform the method required. Two role are specified by default. At the top, superusers can do anything ("$superuser->can( $action )" always returns a coderef). At the bottom, the base role can do nothing ("$base->can( $action )" always returns undef). All roles are automatically capable of authorizing actions named for the singular and plural of the role name. ROADMAPI'm planning to implement some of the main features and terminology described in this document, which describes a standard for Role Based Access Control:http://csrc.nist.gov/rbac/rbacSTD-ACM.pdf Thanks to Kingsley Kerce for providing the link. METHODSThis class is a static class - all methods are class methods.Some methods return Tree::Authz::Role subclass objects. Namespaces and class methodsThis class is designed to work in environments where multiple applications run within the same process (i.e. websites under "mod_perl"). If the optional namespace parameter is supplied to "setup_hierarchy", the roles are isolated to the specified namespace. All methods should be called through the class name returned from "setup_hierarchy".If your program is not operating in such an environment (e.g. CGI scripts), then you can completely ignore this parameter, and call class methods either through "Tree::Authz", or through the string returned from "setup_hierarchy" (which, funnily enough, will be 'Tree::Authz').
PersistenceTree::Authz can be used independently of a persistence mechanism via "setup_hierarchy". However, if you want to manipulate the hierarchy at runtime, a persistence mechanism is required. The implementation is left up to you, but the API is defined. The persistence API should be implemented by the object passed to "setup_from_database".
Pass-through methods The following methods are passed on to the database object, after checking whether any changes would result in a recursive inheritance pattern, in which case they return false. The database methods should return true on success.
Adding authorizations
CHANGESThe deprecation policy is:1) DEPRECATED methods issue a warning (via "carp") and then call the new method. They will be documented next to the replacement method. 2) OBSOLETE methods will croak. These will be documented in a separate section. 3) Removed methods will be documented in a separate section, in the first version they no longer exist in. Main changes in 0.02 - changed terminology to refer to I<roles> instead of I<groups>. Deprecated all methods with I<role> in their name. These methods now issue a warning via C<carp>, and will be removed in a future release. - added a new class to represent a role - L<Tree::Authz::Role|Tree::Authz::Role>. L<Tree::Authz|Tree::Authz> is now a static class (all its methods are class methods). The objects it returns from some methods are subclasses of L<Tree::Authz::Role|Tree::Authz::Role>. TODORoles are now represented by their own class. This should make it easier to add constraints and other RBAC features.More methods for returning meta information, e.g. immediate subroles of a role, all subroles of a role, list available actions of a role and its subroles. Might be nice to register users with roles. Make role objects be singletons - not necessary if the only data they carry is their own name. Under "mod_perl", all setup of hierarchies and permissions must be completed during server startup, before the startup process forks off Apache children. It would be nice to have some way of communicating updates to other processes. Alternatively, you could run the full startup sequence every time you need to access a Tree::Authz role, but that seems sub-optimal. DEPENDENCIESLingua::EN::Inflect::Number, Class::Data::Inheritable.Optional - Devel::Symdump. Sub::Override for the test suite. BUGSPlease report all bugs via the CPAN Request Tracker at <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Tree-Authz>.COPYRIGHT AND LICENSECopyright 2004 by David Baird.This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHORDavid Baird, "cpan@riverside-cms.co.uk"SEE ALSODBIx::UserDB, Data::ACL.
Visit the GSP FreeBSD Man Page Interface. |