File Coverage

blib/lib/Dancer/Plugin/Auth/Krb5.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Dancer::Plugin::Auth::Krb5;
2              
3             our $VERSION = '0.02';
4              
5 1     1   23150 use 5.006;
  1         4  
  1         48  
6 1     1   6 use strict;
  1         2  
  1         39  
7 1     1   5 use warnings;
  1         6  
  1         28  
8              
9 1     1   404 use Authen::Krb5::Simple;
  0            
  0            
10             use Dancer ':syntax';
11             use Dancer::Plugin;
12              
13             register krb5_auth => sub {
14             return Dancer::Plugin::Auth::Krb5->new(@_);
15             };
16              
17             sub new {
18             my $class = shift;
19             my ($user, $pass) = @_;
20              
21             my $self = {
22             user => '',
23             errors => '',
24             };
25             bless $self, $class;
26              
27             my $settings = plugin_setting;
28              
29             if ($settings->{realm}){
30             $self->{krb} = Authen::Krb5::Simple->new(realm => $settings->{realm});
31             }else{
32             $self->{errors} = "realm not configured";
33             return $self;
34             }
35              
36             if ($user && $pass){
37             $self->{user} = $user;
38             if ($self->{krb}->authenticate($user, $pass)){
39             session 'user' => {name => $user};
40             }else{
41             $self->{errors} = $self->{krb}->errstr;
42             }
43             }else{
44             $self->{errors} = "username and password are required";
45             }
46              
47             return $self;
48             }
49              
50             sub user {
51             my $self = shift;
52             return $self->{user};
53             }
54              
55             sub errors {
56             my $self = shift;
57             return $self->{errors};
58             }
59              
60             sub realm {
61             my $self = shift;
62             return exists $self->{krb} ? $self->{krb}->realm : '';
63             }
64              
65             register_plugin;
66              
67             =head1 NAME
68              
69             Dancer::Plugin::Auth::Krb5 - kerberos authentication for Dancer web apps
70              
71             =head1 VERSION
72              
73             Version 0.02
74              
75             =cut
76              
77             =head1 SYNOPSIS
78              
79             use Dancer::Plugin::Auth::Krb5;
80              
81             my $auth = krb5_auth($username, $password);
82             if ($auth->errors){
83             # auth failed
84             }else{
85             # auth success
86             }
87              
88             =head1 CONFIGURATION
89              
90             session: 'SessionEngine'
91             plugins:
92             Auth::Krb5:
93             realm: 'REALM.DOMAIN.COM'
94              
95             reference L for 'SessionEngine'
96              
97             =head1 METHODS
98              
99             use Dancer::Plugin::Auth::Krb5;
100              
101             my $auth = krb5_auth($username, $password);
102              
103             =head2 user
104              
105             $auth->user;
106              
107             return username
108              
109             =cut
110              
111             =head2 errors
112              
113             $auth->errors;
114              
115             return error message
116              
117             =cut
118              
119             =head2 realm
120              
121             $auth->realm;
122              
123             return realm
124              
125             =cut
126              
127             =head1 AUTHOR
128              
129             Hypo Lin, C<< >>
130              
131             =head1 BUGS
132              
133             Please report any bugs or feature requests to C, or through
134             the web interface at L. I will be notified, and then you'll
135             automatically be notified of progress on your bug as I make changes.
136              
137              
138              
139              
140             =head1 SUPPORT
141              
142             You can find documentation for this module with the perldoc command.
143              
144             perldoc Dancer::Plugin::Auth::Krb5
145              
146              
147             You can also look for information at:
148              
149             =over 4
150              
151             =item * RT: CPAN's request tracker (report bugs here)
152              
153             L
154              
155             =item * AnnoCPAN: Annotated CPAN documentation
156              
157             L
158              
159             =item * CPAN Ratings
160              
161             L
162              
163             =item * Search CPAN
164              
165             L
166              
167             =back
168              
169              
170             =head1 ACKNOWLEDGEMENTS
171              
172              
173             =head1 LICENSE AND COPYRIGHT
174              
175             Copyright 2012 Hypo Lin.
176              
177             This program is free software; you can redistribute it and/or modify it
178             under the terms of either: the GNU General Public License as published
179             by the Free Software Foundation; or the Artistic License.
180              
181             See http://dev.perl.org/licenses/ for more information.
182              
183              
184             =cut
185              
186             1; # End of Dancer::Plugin::Auth::Krb5