| 1 | package Catalyst::Authentication::Credential::Upstream::Headers; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 2 | $Catalyst::Authentication::Credential::Upstream::Headers::VERSION = '0.02'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Catalyst authentication credentials from HTTP headers | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | has user_header => | |||||||||||||||||||||||||||
| 11 | isa => 'Str', | ||||||||||||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||||||||||
| 13 | default => 'X-Catalyst-Credential-Upstream-User'; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | has role_header => | |||||||||||||||||||||||||||
| 16 | isa => 'Str', | ||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||
| 18 | default => 'X-Catalyst-Credential-Upstream-Roles'; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | has role_delimiter => | |||||||||||||||||||||||||||
| 21 | isa => 'Str', | ||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||
| 23 | default => '|'; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | has use_x500_cn => | |||||||||||||||||||||||||||
| 26 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||
| 28 | default => 1; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 2 | has realm => | |||||||||||||||||||||||||||
| 31 | isa => 'Catalyst::Authentication::Realm', | ||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | required => 1; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | sub BUILDARGS | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 38 | 1 | my $config = shift; | |||||||||||||||||||||||||||
| 39 | 1 | my $app = shift; | |||||||||||||||||||||||||||
| 40 | 1 | my $realm = shift; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | return { %$config, realm => $realm }; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub authenticate | ||||||||||||||||||||||||||||
| 46 | 9 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 9 | my $c = shift; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # This method is a no-op for the most part. The work that is done | ||||||||||||||||||||||||||||
| 51 | # here is mostly marshalling the request headers into user objects | ||||||||||||||||||||||||||||
| 52 | # that fit the authentication plugin's interface. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 9 | my $user = undef; | |||||||||||||||||||||||||||
| 55 | 9 | my $delimiter = $self->role_delimiter; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 9 | ▶ | if (my $username = $c->req->headers->header($self->user_header)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | my @roles = split /\Q$delimiter\E */, $c->req->headers->header($self->role_header) || ''; | ||||||||||||||||||||||||||
|
Condition100%2/2
$c->req->headers->header($self->role_header) || ''
MC/DC100%1/1
$c->req->headers->header($self->role_header) || ''
$c->req->headers->header($self->role_header)
Truth table100%2/2
A
A= $c->req->headers->header($self->role_header)
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # attempt to extract the cn (common name) component of anything | ||||||||||||||||||||||||||||
| 61 | # that looks like it might be an X.501 distinguished name | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 4 | ▶ | @roles = map { { split /[;,= ]+/ }->{cn} || $_ } @roles | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
{split(/[;,= ]+/, $_, 0)}->{'cn'} || $_
MC/DC0%0/2
{split(/[;,= ]+/, $_, 0)}->{'cn'} || $_
{split(/[;,= ]+/, $_, 0)}->{'cn'}
$_
Truth table33%1/3
A || B
A= {split(/[;,= ]+/, $_, 0)}->{'cn'}B= $_
| |||||||||||||||||||||||||||||
| 64 | if $self->use_x500_cn; | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | $user = { id => $username, roles => \@roles }; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 9 | ▶ | return $user ? $self->realm->find_user($user) : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | 1; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||