source: LATMOS-Accounts-Web/patch/basic_auth.patch @ 883

Last change on this file since 883 was 883, checked in by nanardon, 13 years ago
  • keep work about HTTP authentification
File size: 3.3 KB
  • lib/LATMOS/Accounts/Web.pm

     
    4242__PACKAGE__->config( name => 'LATMOS::Accounts::Web' ); 
    4343 
    4444__PACKAGE__->config->{'Plugin::Authentication'} = { 
    45     default_realm => 'la', 
     45    default_realm => 'remote', 
    4646    realms => { 
     47        remote => { 
     48            credential => { 
     49                class => 'Remote' 
     50            }, 
     51            store => { 
     52                class => 'Null', 
     53            }, 
     54        }, 
    4755        la => { 
    4856            credential => { 
    4957                class => 'La' 
  • lib/LATMOS/Accounts/Web/Controller/Root.pm

     
    5656sub logout : Local { 
    5757    my ( $self, $c ) = @_; 
    5858    $c->logout; 
    59     $c->res->redirect($c->uri_for('/')); 
     59    #$c->res->status(418); 
     60 
    6061} 
    6162 
    6263=head1 AUTHOR 
  • lib/LATMOS/Accounts/Web/Controller.pm

     
    33use strict; 
    44use warnings; 
    55use base 'Catalyst::Controller'; 
     6use MIME::Base64; 
    67 
    78=head1 NAME 
    89 
     
    2021 
    2122=cut 
    2223 
     24sub auth_required : Private { 
     25    my ( $self, $c ) = @_; 
     26    $c->res->status(401); 
     27    $c->res->content_type('text/plain'); 
     28    $c->res->body('Authorization required.'); 
     29    $c->res->headers->push_header( 
     30        'WWW-Authenticate' => 'Basic realm="Link::Accounts"' 
     31    ); 
     32} 
     33 
    2334sub begin : Private { 
    2435    my ( $self, $c ) = @_; 
    2536 
    26     if (!$c->user_exists) { 
     37    if ($c->user_exists) { 
     38        # Set login user: 
     39        warn $c->model('Accounts')->db->{_user} = $c->user->{username}; 
     40    } else { 
    2741        # No need to login for About section 
    2842        if ($c->namespace ne 'about') { 
    29             if ($c->req->path ne 'login') { 
    30                 $c->forward('/login'); 
     43            if ($c->authenticate({}, 'remote')) { 
     44                # Set login user: 
     45                $c->model('Accounts')->db->{_user} = $c->user->{username}; 
     46            } elsif (my $authheader = $c->req->headers->header('Authorization')) { 
     47                # TODO check auth type 
     48                my ($type, $base64) = $authheader =~ /(\w+) (\S+)/; 
     49                my ($login, $pass) = decode_base64($base64) =~ /^([^:]+):(.*)/; 
     50                if (!$c->authenticate({  
     51                            username => $login, 
     52                            password => $pass }, 'la')) { 
     53                    $c->forward('auth_required'); 
     54                    return; 
     55                } 
     56            } else { 
     57                $c->forward('auth_required'); 
     58                return; 
    3159            } 
    32             return; 
    3360        } 
    34     } else { 
    35         $c->model('Accounts')->db->connect( 
    36             $c->user->{username}, 
    37             $c->user->{password}); 
    3861    } 
    3962} 
    4063 
     
    5174 
    5275sub end : ActionClass('RenderView') { 
    5376    my ($self, $c) = @_; 
    54     $c->forward($c->view('TT')); 
     77    $c->forward($c->view('TT')) unless($c->res->body); 
    5578    $c->model('Accounts')->db->rollback; 
    5679    $c->model('Accounts')->call_batch_sync; 
    5780} 
Note: See TracBrowser for help on using the repository browser.