Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am using CGI::Application::Plugin::Authorization (Driver is DBI) for my web application and i am just curious if anyone know how to get User's role (as far as i know, there is no 'official' method to get User's role, so maybe the tricky way ?)

Thanks

  • Comment on Question about getting Role's name from CGI::Application::Plugin::Authorization

Replies are listed 'Best First'.
Re: Question about getting Role's name from CGI::Application::Plugin::Authorization
by scorpio17 (Canon) on Feb 24, 2011 at 14:47 UTC

    There's no "official" way, because CGI::Application::Plugin::Authorization is designed to be generic enough that one can customize it as needed. For example, you can implement an authorization check based on IP address. In that case, you don't really have "roles" (unless you consider "authorized" and "not authorized" roles).

    On the other hand, you can create a "roles" database table and use the CGI::Application::Plugin::Authorization::Driver::DBI to implement a system that uses it. That would let you do something like:

    if ( $self->authz->authorize('role1') ) { # user belongs to the role1 group } else { # authorization failed }

    But if you want to do something like:

    my @roles = $self->authz->get_roles( $user );

    Then you should probably create your own authorization module, derived from CGI::Application::Plugin::Authorization, and then implement methods like get_roles() based on your particular implementation details.

      I understand, just like i thought.

      Thank you

Re: Question about getting Role's name from CGI::Application::Plugin::Authorization
by Khen1950fx (Canon) on Feb 24, 2011 at 01:06 UTC