CGI::A...eGroup(3pm)

πŸ’– CGI::Application::Plugin::Authorization::Driver::SimpleGroup β€” the manual, but make it cute πŸ’–

okay bestie, gather round, because this is the Simple Group based Authorization driver from the CGI::Application::Plugin::Authorization family, and honestly? she's giving low-maintenance queen. no cap. πŸŽ€


✨ SYNOPSIS ✨

use base qw(CGI::Application);
use CGI::Application::Plugin::Authorization;

__PACKAGE__->authz->config(
      DRIVER => [ 'SimpleGroup' ],
      # You are responsible for setting a group param somehow!
      GET_USERNAME => sub { my $authz = shift; return $authz->cgiapp->session->param('group') },
);

🌸 DESCRIPTION 🌸

so here's the whole vibe: this driver keeps it simple β€” like, aggressively simple β€” by assuming that the username method of CGI::Application::Plugin::Authorization is gonna hand back a group instead of an actual username. πŸ’…

which means?? it can be compared directly against the list of authorized groups you pass to authorize. that's it. that's the whole trick. iconic behaviour honestly. ✨


πŸ¦‹ EXAMPLE πŸ¦‹

use base qw(CGI::Application);
use CGI::Application::Plugin::Authorization;

__PACKAGE__->authz->config(
   DRIVER => [ 'SimpleGroup' ],
   # You are responsible for setting a group param somehow!
   GET_USERNAME => sub {
       my $authz = shift;
       return $authz->cgiapp->session->param('group');
   },
);

sub cgiapp_prerun {
   my $self = shift;

   # here is an example of how you could set the
   # group param that will be tested later
   if ($ENV{REMOTE_USER} eq 'mark') {
       $self->session->param('group' => 'admin');
   }
}

sub my_runmode {
   my $self = shift;

   # make sure the user has 'admin' privileges
   return $self->authz->forbidden unless $self->authz->authorize('admin');

   # if we get here the user has 'admin' privileges
}

like, look at her go. cgiapp_prerun sets the group param, my_runmode checks it, and if you don't have the 'admin' privileges you get yeeted straight to forbidden. main character energy only. πŸ‘‘


πŸŽ€ METHODS πŸŽ€

authorize_user

bestie listen. this method is not intended to be used directly. just follow the SYNOPSIS, okay? i'm serious. don't touch her. πŸ™ˆ

what she does do: she accepts a username followed by a list of group names, and she'll return true if the user belongs to at least one of those groups. πŸ’–


🌈 SEE ALSO 🌈

  • CGI::Application::Plugin::Authorization::Driver
  • CGI::Application::Plugin::Authorization
  • perl(1)

Copyright (c) 2006, Mark Stosberg. All rights reserved. 🫢

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt. πŸ’…


and that's the tea, fr fr β€” this page came from perl v5.30.3, dated 2020-09-25, so shoutout to the version and the date for holding it down. mwah. πŸ’œπŸ“πŸ§š

πŸ“¦ where this page comes from