File Coverage

blib/lib/Auth/Kokolores/Request.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 18 18 100.0


line stmt bran cond sub pod time code
1             package Auth::Kokolores::Request;
2              
3 4     4   63228 use Moose;
  4         1000758  
  4         26  
4              
5             # ABSTRACT: saslauthd protocol request object
6             our $VERSION = '1.00'; # VERSION
7              
8              
9             has 'username' => ( is => 'rw', isa => 'Str', required => 1 );
10             has 'password' => ( is => 'rw', isa => 'Str', required => 1 );
11             has 'service' => ( is => 'rw', isa => 'Str', required => 1 );
12             has 'realm' => ( is => 'rw', isa => 'Str', required => 1 );
13              
14              
15             has 'server' => (
16             is => 'ro',
17             isa => 'Net::Server',
18             required => 1,
19             handles => {
20             log => 'log',
21             },
22             );
23              
24              
25             has 'userinfo' => (
26             is => 'ro', isa => 'HashRef', lazy => 1,
27             default => sub { {} },
28             traits => [ 'Hash' ],
29             handles => {
30             get_info => 'get',
31             set_info => 'set',
32             },
33             );
34              
35              
36             sub _read_sasl_string {
37 4     4   4 my ( $conn ) = @_;
38 4         4 my $buf;
39 4         11 $conn->read($buf, 2);
40 4         42 my $size = unpack('n', $buf);
41 4         8 $conn->read($buf, $size);
42 4         41 return unpack("A$size", $buf);
43             }
44              
45              
46             sub new_from_conn {
47 1     1 1 226 my ( $class, $conn, $server ) = @_;
48 1         3 my %opts = (
49             server => $server,
50             );
51 1         3 foreach my $field ('username', 'password', 'service', 'realm') {
52 4         7 $opts{$field} = _read_sasl_string( $conn );
53             }
54 1         6 return $class->new( %opts );
55             }
56              
57             1;
58              
59             __END__
60              
61             =pod
62              
63             =encoding UTF-8
64              
65             =head1 NAME
66              
67             Auth::Kokolores::Request - saslauthd protocol request object
68              
69             =head1 VERSION
70              
71             version 1.00
72              
73             =head1 DESCRIPTION
74              
75             This class holds all information associated with an authentication request.
76             It is passed to all authentication plugins.
77              
78             =head1 ATTRIBUTES
79              
80             =head2 username
81              
82             The username passed within the SASL request.
83              
84             =head2 password
85              
86             The password passed within the SASL request.
87              
88             =head2 service
89              
90             The service name passed within the SASL request.
91              
92             =head2 realm
93              
94             The sasl auth realm passed within the SASL request.
95              
96             =head2 server
97              
98             A reference to the L<Auth::Kokolores> server object.
99              
100             =head2 userinfo
101              
102             A hashref holding additional information to be passed between plugins.
103              
104             Use get_info and set_info methods to access fields.
105              
106             =head1 METHODS
107              
108             =head2 get_info( $key )
109              
110             Retrieve field $key from userinfo.
111              
112             =head2 set_info( $key, $value )
113              
114             Set field $key to $value in userinfo.
115              
116             =head2 Auth::Kokolores::Request->new_from_conn( $conn, $server )
117              
118             Constructor for Auth::Kokolores::Request for creating
119             an object by reading the parameters from a handle
120             passed in $conn.
121              
122             =head1 AUTHOR
123              
124             Markus Benning <ich@markusbenning.de>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is Copyright (c) 2016 by Markus Benning <ich@markusbenning.de>.
129              
130             This is free software, licensed under:
131              
132             The GNU General Public License, Version 2, June 1991
133              
134             =cut