line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PlugAuth::Lite; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
1167242
|
use strict; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
217
|
|
4
|
6
|
|
|
6
|
|
42
|
use warnings; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
201
|
|
5
|
6
|
|
|
6
|
|
135
|
use 5.010001; |
|
6
|
|
|
|
|
25
|
|
6
|
6
|
|
|
6
|
|
38
|
use Mojo::Base qw( Mojolicious ); |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
62
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Pluggable (lite) authentication and authorization server. |
9
|
|
|
|
|
|
|
our $VERSION = '0.37'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'auth'; |
13
|
|
|
|
|
|
|
has 'authz'; |
14
|
|
|
|
|
|
|
has 'host'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub startup |
17
|
|
|
|
|
|
|
{ |
18
|
5
|
|
|
5
|
1
|
28881
|
my($self, $config) = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$self->plugin('plug_auth_lite', |
21
|
0
|
|
|
0
|
|
0
|
auth => $self->auth // sub { 0 }, |
22
|
1
|
|
|
1
|
|
3
|
authz => $self->authz // sub { 1 }, |
23
|
2
|
|
|
2
|
|
14
|
host => $self->host // sub { 0 }, |
24
|
5
|
|
100
|
|
|
35
|
); |
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
1; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__END__ |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=pod |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=encoding UTF-8 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
PlugAuth::Lite - Pluggable (lite) authentication and authorization server. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 VERSION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
version 0.37 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
command line: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
% plugauthlite |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Mojolicious Plugin: |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use Mojolicious::Lite; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
plugin 'plug_auth_lite', |
54
|
|
|
|
|
|
|
auth => sub { |
55
|
|
|
|
|
|
|
my($user, $pass) = @_; |
56
|
|
|
|
|
|
|
if($user eq 'optimus' && $pass eq 'matrix') |
57
|
|
|
|
|
|
|
{ return 1; } |
58
|
|
|
|
|
|
|
else |
59
|
|
|
|
|
|
|
{ return 0; } |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
authz => sub { |
62
|
|
|
|
|
|
|
my($user, $action, $resource) = @_; |
63
|
|
|
|
|
|
|
if($user eq 'optimus && $action eq 'open' && $resource =~ m{^/matrix}) |
64
|
|
|
|
|
|
|
{ return 1 } |
65
|
|
|
|
|
|
|
else |
66
|
|
|
|
|
|
|
{ return 0 } |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Mojolicious App: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use PlugAuth::Lite; |
72
|
|
|
|
|
|
|
my $app = PlugAuth::Lite->new({ |
73
|
|
|
|
|
|
|
auth => sub { |
74
|
|
|
|
|
|
|
my($user, $pass) = @_; |
75
|
|
|
|
|
|
|
if($user eq 'optimus' && $pass eq 'matrix') |
76
|
|
|
|
|
|
|
{ return 1; } |
77
|
|
|
|
|
|
|
else |
78
|
|
|
|
|
|
|
{ return 0; } |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
authz => sub { |
81
|
|
|
|
|
|
|
my($user, $action, $resource) = @_; |
82
|
|
|
|
|
|
|
if($user eq 'optimus && $action eq 'open' && $resource =~ m{^/matrix}) |
83
|
|
|
|
|
|
|
{ return 1 } |
84
|
|
|
|
|
|
|
else |
85
|
|
|
|
|
|
|
{ return 0 } |
86
|
|
|
|
|
|
|
}, |
87
|
|
|
|
|
|
|
}); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 DESCRIPTION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This distribution provides |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item L<plugauthlite> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
L<PlugAuth> compatible server in the form of a L<Mojolicious::Lite> application. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item L<Mojolicious::Plugin::PlugAuthLite> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L<Mojolicious> plugin that adds L<PlugAuth> compatible routes to a new or |
102
|
|
|
|
|
|
|
existing L<Mojolicious> application. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item L<PlugAuth::Lite> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
L<Mojolicious> application with L<PlugAuth> compatible routes that can be spawned |
107
|
|
|
|
|
|
|
from within a perl application. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=back |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
In the future it will also contain a testing interface for testing authentication |
112
|
|
|
|
|
|
|
and authorization rules in L<Clustericious> applications. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
It has fewer prerequisites that the full fledged L<PlugAuth> server (simply |
115
|
|
|
|
|
|
|
L<Mojolicious> and perl itself) but also fewer features (it notably lacks |
116
|
|
|
|
|
|
|
the management interface). |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 auth |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Subroutine reference to call to check authentication. Passes in C<($user, $pass)> should |
123
|
|
|
|
|
|
|
return true for authenticated, false otherwise. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
If not provided, all authentications fail. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 authz |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Subroutine reference to call to check authorization. Passes in C<($user, $action, $resource)> |
130
|
|
|
|
|
|
|
and should return true for authorized, false otherwise. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
If not provided, all authorizations succeed. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 host |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Subroutine reference to call to check host information. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SEE ALSO |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<plugauthlite>, |
141
|
|
|
|
|
|
|
L<Mojolicious::Plugin::PlugAuthLite>, |
142
|
|
|
|
|
|
|
L<Test::PlugAuth>, |
143
|
|
|
|
|
|
|
L<Clustericious> |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 AUTHOR |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Graham Ollis <plicease@cpan.org> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Graham Ollis. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
154
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |