Changeset 214

Show
Ignore:
Timestamp:
09/24/06 00:09:55 (2 years ago)
Author:
jwalt
Message:
  • Add authentication plugin
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/MANIFEST

    r206 r214  
    118118plugins/aio/serve_file 
    119119plugins/aio/uri_to_file 
     120plugins/authenticate 
    120121plugins/cachecache 
    121122plugins/demo/doc_viewer 
  • trunk/lib/AxKit2/Config.pm

    r210 r214  
    797797    my ($config, $param) = (shift, shift); 
    798798 
    799     # the known subsections get a copy as well 
     799    # Don't overwrite values in subsections that are already set. 
     800    return if $config ne $self->config && !$param->{push} && exists $config->{$param->{key}}; 
     801 
     802    # Known subsections get a copy as well. 
    800803    if (!exists $config->_subsections->{$param->{key}}) { 
    801804        foreach my $objs (values %{$config->_subsections}) { 
  • trunk/lib/AxKit2/HTTPHeaders.pm

    r162 r214  
    5858            'requestLine',  # first line of HTTP request (if request) 
    5959            'parsed_cookies',  # parsed cookie data 
    60             'lame'          # HTTP/0.9 
     60            'lame',         # HTTP/0.9 
     61            'user',         # authenticated username 
    6162            ); 
    6263 
     
    363364 
    364365 
     366=head2 C<< $obj->user >> 
     367 
     368Gets/sets the authenticated request username, if any. 
     369 
     370=cut 
     371 
     372sub user { 
     373    my AxKit2::HTTPHeaders $self = shift; 
     374    @_ and $self->{user} = shift; 
     375    return $self->{user}; 
     376} 
     377 
    365378=head2 C<< $obj->request_uri >> 
    366379 
  • trunk/lib/AxKit2/Plugin.pm

    r205 r214  
    275275This declaration: 
    276276 
    277     sub conf_foo_bar; 
     277    sub conf_FooBar; 
    278278 
    279279will create this entry: 
    280280 
    281     $self->config('foo_bar'); 
    282  
    283 and can be used in a variety of ways in the config file: 
    284  
    285     FooBar demo 
    286     foobar demo 
    287     fOObAR demo 
    288     foo-bar demo 
    289     foo_bar demo 
    290     FOo_bAr demo 
    291  
    292 which are all equivalent. 
    293  
    294 This CamelCase declaration: 
    295  
    296     sub conf_FooBar; 
    297  
    298 will create this entry: 
    299  
    300281    $self->config('FooBar'); 
    301282 
    302 and will have I<exactly> the same config file syntax as the previous example. 
    303  
    304 By default, multiple values are accepted and stored, while quoting is supported: 
    305  
    306     FooBar demo1 demo2 "demo 3" 
    307  
    308 For different ways of parsing/validating configuration directives, you can add 
     283There are actually may possible variation on directive names that are all equivalent. Anywhere 
     284a directive name is used, you can use any variation like this: 
     285 
     286    FooBar 
     287    foo_bar 
     288    foo-bar 
     289    FOO_BAR 
     290    foobar 
     291 
     292and some more. This includes C<sub conf_FOO_BAR> or C<< $self->config("foo-bar") >>. 
     293 
     294By default, a single values are accepted and stored, while quoting is supported: 
     295 
     296    FooBar "demo 3" 
     297 
     298For different ways of validating configuration directives, you can add 
    309299a custom validation routine: 
    310300 
    311     # use predefined "only one argument allowed" validator 
    312     sub FooBar : Validate(TAKE1); 
    313      
    314     # this directive takes a comma separated list of values 
    315     sub FooBar : Validate(sub { split(/,/,shift); }); 
     301    # use predefined "multiple strings" validator 
     302    sub FooBar : Validate(STRINGLIST); 
     303     
     304    # this directive takes one of two values 
     305    sub FooBar : Validate(sub { die "invalid value" if $_[1] !~ m/^(red|green)$/i; lc($_[1]); }); 
    316306 
    317307If you want to have custom actions when the directive is parsed, supply a function body: 
    318308 
    319309    # store a database connection instead 
    320     sub FooBar { my ($self, $value) = @_; return DBI->connect($value); } 
     310    sub FooBar { my ($parser, $value) = @_; return DBI->connect($value); } 
    321311     
    322312    # preprocess parameters 
    323     sub FooBar { my ($self, @values) = @_; return join(",",@values); } 
    324      
    325     # return empty list means: don't store anything 
    326     sub FooBar { my ($self, @values) = @_; return (); } 
     313    sub FooBar { my ($parser, @values) = @_; return join(",",@values); } 
    327314 
    328315Of course, all this can be combined: 
    329316 
    330317    # this is a rather nonsensical example, do you spot why? 
    331     sub FooBar : Validate(sub { split(/,/,shift); }) { 
    332         my ($self, @values) = @_; 
     318    sub FooBar : Validate(sub { split(/,/,$_[1]); }) { 
     319        my ($parser, @values) = @_; 
    333320        return join(",",@values); 
    334321    } 
    335322 
     323For full details and more ways of designing configuration directives, see L<AxKit2::Config>. 
    336324 
    337325=head1 AVAILABLE HOOKS