The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Catalyst::Plugin::Authorization::RoleAbilities - Ability based authorization for Catalyst (using only Roles)

VERSION

version 0.002

SYNOPSIS

    use Catalyst qw/
        Authentication
        Authorization::RoleAbilities
    /;

    sub delete : Local {
        my ( $self, $c ) = @_;

        $c->assert_user_ability( qw/delete_user/ ); # only users with roles that can perform this action can delete

        $c->model("User")->delete_it();
    }

DESCRIPTION

Ability based authorization allows more flexibility than role based authorization. Users can have roles, which then have many actions associated. An action can be associated with several roles. With this you don't check whether a user has specific roles, but instead whether the roles can perform specific actions.

Catalyst::Plugin::Authorization::RoleAbilities extends Catalyst::Plugin::Authorization::Roles so every method of Catalyst::Plugin::Authorization::Roles still can be used.

See "SEE ALSO" for other authorization modules.

METHODS

assert_user_ability [ $user ], @actions

Checks that the roles of the user (as supplied by the first argument, or, if omitted, $c->user) has the ability to perform specified actions.

If for any reason ($c->user is not defined, the user's roles are missing the appropriate action, etc.) the check fails, an error is thrown.

You can either catch these errors with an eval, or clean them up in your end action.

check_user_ability [ $user ], @actions

Takes the same args as assert_user_ability, and performs the same check, but instead of throwing errors returns a boolean value.

REQUIRED TABLES

Actions

Table name: actions

Columns:

  • id, as integer, Primary Key

  • name, as character varying or text

Roles to Actions

Table name: role_actions

Columns:

  • id, as integer, Primary Key

  • role_id, as integer, Foreign Key to roles.id

  • action_id, as integer, Foreign Key to actions.id

SEE ALSO

AUTHOR

Matthias Dietrich <perl@rainboxx.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Matthias Dietrich.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.