| 1 | package PlugAuth; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # ABSTRACT: (Deprecated) Pluggable authentication and authorization server. | ||||||||||||||||||||||||||||
| 4 | 41 | our $VERSION = '0.39'; # VERSION | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 41 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 41 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 41 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 41 | ▶ | use base 'Clustericious::App'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 41 | ▶ | use PlugAuth::Routes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 41 | ▶ | use Log::Log4perl qw( :easy ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 41 | ▶ | use Role::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 41 | ▶ | use PlugAuth::Role::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 41 | ▶ | use Clustericious::Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 41 | ▶ | use Mojo::Base 'Mojo::EventEmitter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub plugin | ||||||||||||||||||||||||||||
| 19 | 383 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
plugin: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 383 | my($self, $name, @rest) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # catch load of plug_auth and use self_plug_auth instead | ||||||||||||||||||||||||||||
| 23 | 383 | ▶ | if($name eq 'plug_auth' | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$name eq "plug_auth" or $name eq "PlugAuth"
MC/DC50%1/2
$name eq "plug_auth" or $name eq "PlugAuth"
$name eq "plug_auth"
$name eq "PlugAuth"
Truth table66%2/3
A or B
A= $name eq "plug_auth"B= $name eq "PlugAuth"
| |||||||||||||||||||||||||||||
| 24 | || $name eq 'PlugAuth') | ||||||||||||||||||||||||||||
| 25 | { | ||||||||||||||||||||||||||||
| 26 | 23 | TRACE "loading plugin self_plug_auth ($name)"; | |||||||||||||||||||||||||||
| 27 | 23 | return $self->SUPER::plugin('self_plug_auth', @rest); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # load the plugin | ||||||||||||||||||||||||||||
| 31 | 360 | TRACE "loading plugin $name"; | |||||||||||||||||||||||||||
| 32 | 360 | my $ret = $self->SUPER::plugin($name, @rest); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # just in case we miss it and plug_auth was loaded, | ||||||||||||||||||||||||||||
| 35 | # load self_plug_auth instead. | ||||||||||||||||||||||||||||
| 36 | 360 | ▶ | if(eval { $ret->isa('Clustericious::Plugin::PlugAuth') }) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | 0 | TRACE "detected plug_auth plugin, switching with self_plug_auth"; | |||||||||||||||||||||||||||
| 39 | 0 | return $self->SUPER::plugin('self_plug_auth', @rest); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | else | ||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 360 | return $ret; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | sub startup | ||||||||||||||||||||||||||||
| 48 | 40 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
startup: called CC=17 SCAR=56.7
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 40 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 40 | $self->SUPER::startup(@_); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | #$self->renderer->default_format('txt'); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my @plugins_config = eval { | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | my $plugins = $self->config->{plugins} // []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->config->{"plugins"} // []
MC/DC0%0/1
$self->config->{"plugins"} // []
$self->config->{"plugins"}
Truth table0%0/2
A
A= $self->config->{"plugins"}
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | ref($plugins) eq 'ARRAY' ? @$plugins : ($plugins); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my $auth_plugin; | |||||||||||||||||||||||||||
| 60 | my $authz_plugin; | ||||||||||||||||||||||||||||
| 61 | 0 | my $welcome_plugin; | |||||||||||||||||||||||||||
| 62 | 0 | my @refresh; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | foreach my $plugin_class (reverse @plugins_config) | |||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 0 | my $plugin_config; | |||||||||||||||||||||||||||
| 67 | 0 | ▶ | if(ref $plugin_class) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 0 | ($plugin_config) = values %$plugin_class; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | $plugin_config = Clustericious::Config->new($plugin_config) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | unless ref($plugin_config) eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 72 | 0 | ($plugin_class) = keys %$plugin_class; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | else | ||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 0 | $plugin_config = Clustericious::Config->new({}); | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | eval qq{ require $plugin_class }; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | LOGDIE $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | Role::Tiny::does_role($plugin_class, 'PlugAuth::Role::Plugin') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | || LOGDIE "$plugin_class is not a PlugAuth plugin"; | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my $plugin = $plugin_class->new($self->config, $plugin_config, $self); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if($plugin->does('PlugAuth::Role::Auth')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||
| 88 | 0 | $plugin->next_auth($auth_plugin); | |||||||||||||||||||||||||||
| 89 | 0 | $auth_plugin = $plugin; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if($plugin->does('PlugAuth::Role::Welcome')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||
| 94 | 0 | $welcome_plugin = $plugin; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $authz_plugin = $plugin if $plugin->does('PlugAuth::Role::Authz'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | push @refresh, $plugin if $plugin->does('PlugAuth::Role::Refresh') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | unless(defined $auth_plugin) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||
| 103 | 0 | require PlugAuth::Plugin::FlatAuth; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | if($self->config->ldap(default => '')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 0 | require PlugAuth::Plugin::LDAP; | |||||||||||||||||||||||||||
| 107 | 0 | $auth_plugin = PlugAuth::Plugin::LDAP->new($self->config, {}, $self); | |||||||||||||||||||||||||||
| 108 | 0 | $auth_plugin->next_auth(PlugAuth::Plugin::FlatAuth->new($self->config, Clustericious::Config->new({}), $self)); | |||||||||||||||||||||||||||
| 109 | 0 | push @refresh, $auth_plugin->next_auth; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | else | ||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||
| 113 | 0 | $auth_plugin = PlugAuth::Plugin::FlatAuth->new($self->config, Clustericious::Config->new({}), $self); | |||||||||||||||||||||||||||
| 114 | 0 | push @refresh, $auth_plugin; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | unless(defined $authz_plugin) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||
| 120 | 0 | require PlugAuth::Plugin::FlatAuthz; | |||||||||||||||||||||||||||
| 121 | 0 | $authz_plugin = PlugAuth::Plugin::FlatAuthz->new($self->config, Clustericious::Config->new({}), $self); | |||||||||||||||||||||||||||
| 122 | 0 | push @refresh, $authz_plugin; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | $self->helper(data => sub { $auth_plugin }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | $self->helper(auth => sub { $auth_plugin }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $self->helper(authz => sub { $authz_plugin }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if(@refresh > 0 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | 0 | ▶ | $self->hook(before_dispatch => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 132 | 0 | $_->refresh for @refresh; | |||||||||||||||||||||||||||
| 133 | 0 | }); | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | $self->helper(refresh => sub { $_->refresh for @refresh; 1 }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | else | ||||||||||||||||||||||||||||
| 137 | { | ||||||||||||||||||||||||||||
| 138 | 0 | ▶ | $self->helper(refresh => sub { 1; }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $self->helper(welcome => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 142 | 0 | my($self) = @_; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | if($welcome_plugin) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | 0 | $welcome_plugin->welcome($self); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else | ||||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||||
| 149 | 0 | $self->render_message("welcome to plug auth"); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | 0 | }); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # for historical reasons, some routes return text by default | ||||||||||||||||||||||||||||
| 154 | # in older versions, even if a format (e.g. /auth.json) is specified. | ||||||||||||||||||||||||||||
| 155 | # this is a simple helper to render using autodata if a format | ||||||||||||||||||||||||||||
| 156 | # is explicitly specified, otherwise fallback on the original | ||||||||||||||||||||||||||||
| 157 | # behavior. | ||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $self->helper(render_message => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 159 | 0 | my($self, $message, $status) = @_; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | $status //= 200; | ||||||||||||||||||||||||||
|
Condition0%0/2
$status //= 200
MC/DC0%0/1
$status //= 200
$status
Truth table0%0/2
A
A= $status
| |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $format = $self->stash->{format} // 'txt'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->stash->{"format"} // "txt"
MC/DC0%0/1
$self->stash->{"format"} // "txt"
$self->stash->{"format"}
Truth table0%0/2
A
A= $self->stash->{"format"}
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if($format ne 'txt') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | { | ||||||||||||||||||||||||||||
| 164 | 0 | $self->render(autodata => { message => $message, status => $status }, status => $status); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | else | ||||||||||||||||||||||||||||
| 167 | { | ||||||||||||||||||||||||||||
| 168 | 0 | $self->render(text => $message, status => $status, format => 'txt'); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | 0 | }); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Silence warnings; this is only used for for session | ||||||||||||||||||||||||||||
| 173 | # cookies, which we don't use. | ||||||||||||||||||||||||||||
| 174 | 0 | ▶ | if($self->can('secrets')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | { $self->secrets([rand]) } | |||||||||||||||||||||||||||
| 176 | else | ||||||||||||||||||||||||||||
| 177 | 0 | { $self->secret(rand) } | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 41 | 1; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | __END__ | ||||||||||||||||||||||||||||