Hello wise monks,

I am preparing to post on CPAN some modules that I have written in order to run CGI::Application apps as FastCGI "singleton" classes.

I suppose I need to explain a little. CGI::App is perfectly suitable for writing applications that run once. For example, when run in CGI or in mod_perl envoronment the usual behaviour is to instantiate the web class for every request and discard it after that. You could do the same in FastCGI environment but I have tried to make a singleton web-application class that only resets the CGI parameters on every request and reuses the same class instance. In this way I could have a heavy init phase (some constant stuff from DB) that do not affect the processing time for every request. I have found that CGI::App core is perfectly suitable for the task but there are some plugins that do not play well. So I have decided to write some drop in replacement for this modules. For example, CGI::Application::Singleton::Session is drop-in replacement for CGI::Application::Plugin::Session and CGI::Application::Singleton::Redirect is replacement for CGI::Application::Plugin::Redirect.

The problem also arised in Authentication and Authorization plugins. But I was unhappy with its API and decided to make a try on the problem. I wanted to have some declarative framework, so I opted for sub attrubutes. En example worths thousand words, so here its is:

#!/usr/bin/perl package webapp::item use webapp qw(role method); use base 'webapp'; # everybody sees it sub show :StartRunMode { ... } # Authenticated users only sub post_comment :RunMode :Protected { ... } # Authenticated & authorized - only admin or moderator # could delete items sub delete :RunMode :Protected(role('admin'), role('moderator')) { ... } # Only authenticated and throught POST http method sub save :RunMode :Protected(method('POST')) { ... }

The code in the module is short but I have added a lot of documentation in it with full example. You could get it http://luben.unixsol.org/Protect.pm. It cooperates with sessions management plugin and a dispatcher that I am refactoring now. The relevant code from the dispatcher is this:

sub cgiapp_dispatch { my $self = shift; my $mode = $self->parse_path_info(); return $self->cgiapp_protect ($mode) if $self->can('cgiapp_protect'); return $mode; }
So, here are my hesitations and questions:
  1. Regarding CGI::Application structure: is this the right way to extend it?
  2. Redarding the A&A API: Does that make sense to you and did you find this useful? One of my motivation points was that I wanted to declare the security context on the same place as the code
  3. This will be my fist CPAN submission. So, is there enought and helpfull documentation? Do I miss something?
  4. And last but not least, I am open to all kinds of suggestions and critics concerning the code

Thanks in advance

luben

Replies are listed 'Best First'.
Re: CGI::App declarative authentication and authorization
by Anonymous Monk on Jan 23, 2009 at 15:55 UTC
    TYPO: In the middle of the second paragraph. You mean 'in this way'. No need to publish my comment. It's just for you.

      Hmm, I like 'In this war' better.

      And you didn't even know bears could type.

      Yes, thanks, fixed.