Catalyst::Plugin::Authorization::Roles - Role based authorization for Catalyst based on Catalyst::Plugin::Authentication.
use Catalyst qw/ Authentication Authentication::Store::ThatSupportsRoles Authorization::Roles /; sub delete : Local { my ( $self, $c ) = @_; $c->assert_user_roles( qw/admin/ ); # only admins can delete $c->model("Foo")->delete_it(); }
Role based authentication is very simple: every user has a list of roles, which that user is allowed to assume.
Whenever an area that is restricted for e.g. admins, or members, or any other role is accessed a check is made to see whether or not the user has all the required roles.
In this plugin the user objects being checked have the roles method invoked. This method is supposed to return a list of the roles the user is allowed to assume. The roles may be any item that can be compared using Set::Object.
roles
For example, if you have a CRUD application, for every mutating action you probably want to check that the user is allowed to edit. To do this, create an editor role, and add that role to every user who is allowed to edit.
sub edit : Local { my ( $self, $c ) = @_; $c->assert_user_roles( qw/editor/ ); $c->model("TheModel")->make_changes(); }
Cheks that the user (as supplied by the first argument, or, if omitted, <$c-user>>) has the specified roles.
<$c-
If for any reason (<$c-user>> is not defined, the user is missing a role, etc) the check fails, an error is thrown.
Takes the same args as assert_user_roles, and performs the same check, but instead of throwing errors returns a boolean value.
assert_user_roles
Catalyst::Plugin::Authentication
Yuval Kogman, nothingmuch@woobling.org
nothingmuch@woobling.org
Copyright (c) 2005 the aforementioned authors. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Catalyst::Plugin::Authorization::Roles, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Catalyst::Plugin::Authorization::Roles
CPAN shell
perl -MCPAN -e shell install Catalyst::Plugin::Authorization::Roles
For more information on module installation, please visit the detailed CPAN module installation guide.