.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Catalyst::Plugin::Authorization::Roles 3pm" .TH Catalyst::Plugin::Authorization::Roles 3pm "2018-04-07" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Catalyst::Plugin::Authorization::Roles \- Role based authorization for Catalyst based on Catalyst::Plugin::Authentication .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& use Catalyst qw/ \& Authentication \& Authorization::Roles \& /; \& \& sub delete : Local { \& my ( $self, $c ) = @_; \& \& $c\->assert_user_roles( qw/admin/ ); # only admins can delete \& \& $c\->model("Foo")\->delete_it(); \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Role based access control is very simple: every user has a list of roles, which that user is allowed to assume, and every restricted part of the app makes an assertion about the necessary roles. .PP With \f(CW\*(C`assert_user_roles\*(C'\fR, if the user is a member in \fBall\fR of the required roles access is granted. Otherwise, access is denied. With \&\f(CW\*(C`assert_any_user_role\*(C'\fR it is enough that the user is a member in \fBone\fR role. .PP There are alternative approaches to do this on a per action basis, see Catalyst::ActionRole::ACL. .PP For example, if you have a \s-1CRUD\s0 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. .PP .Vb 5 \& sub edit : Local { \& my ( $self, $c ) = @_; \& $c\->assert_user_roles( qw/editor/ ); \& $c\->model("TheModel")\->make_changes(); \& } .Ve .PP When this plugin checks the roles of a user it will first see if the user supports the self check method. .PP When this is not supported the list of roles is extracted from the user using the \f(CW\*(C`roles\*(C'\fR method. .PP When this is supported, the \f(CW\*(C`check_roles\*(C'\fR method will be used to delegate the role check to the user class. Classes like the one provided with iCatalyst::Authentication::Store::DBIx::Class optimize the check this way. .SH "METHODS" .IX Header "METHODS" .ie n .IP "assert_user_roles [ $user ], @roles" 4 .el .IP "assert_user_roles [ \f(CW$user\fR ], \f(CW@roles\fR" 4 .IX Item "assert_user_roles [ $user ], @roles" Checks that the user (as supplied by the first argument, or, if omitted, \&\f(CW\*(C`$c\->user\*(C'\fR) has the specified roles. .Sp If for any reason (\f(CW\*(C`$c\->user\*(C'\fR is not defined, the user is missing a role, etc) the check fails, an error is thrown. .Sp You can either catch these errors with an eval, or clean them up in your \f(CW\*(C`end\*(C'\fR action. .ie n .IP "check_user_roles [ $user ], @roles" 4 .el .IP "check_user_roles [ \f(CW$user\fR ], \f(CW@roles\fR" 4 .IX Item "check_user_roles [ $user ], @roles" Takes the same args as \f(CW\*(C`assert_user_roles\*(C'\fR, and performs the same check, but instead of throwing errors returns a boolean value. .ie n .IP "assert_any_user_role [ $user ], @roles" 4 .el .IP "assert_any_user_role [ \f(CW$user\fR ], \f(CW@roles\fR" 4 .IX Item "assert_any_user_role [ $user ], @roles" Checks that the user (as supplied by the first argument, or, if omitted, \&\f(CW\*(C`$c\->user\*(C'\fR) has at least one of the specified roles. .Sp Other than that, works like \f(CW\*(C`assert_user_roles\*(C'\fR. .ie n .IP "check_any_user_role [ $user ], @roles" 4 .el .IP "check_any_user_role [ \f(CW$user\fR ], \f(CW@roles\fR" 4 .IX Item "check_any_user_role [ $user ], @roles" Takes the same args as \f(CW\*(C`assert_any_user_role\*(C'\fR, and performs the same check, but instead of throwing errors returns a boolean value. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "Catalyst::Plugin::Authentication" 4 .IX Item "Catalyst::Plugin::Authentication" .PD 0 .IP "Catalyst::ActionRole::ACL" 4 .IX Item "Catalyst::ActionRole::ACL" .IP "Catalyst::Manual::Tutorial::06_Authorization" 4 .IX Item "Catalyst::Manual::Tutorial::06_Authorization" .PD .SH "AUTHOR" .IX Header "AUTHOR" Yuval Kogman .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright (c) 2005\-2011 the Catalyst::Plugin::Authorization::Roles \*(L"\s-1AUTHOR\*(R"\s0 as listed above. .PP This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.