Quiq/Ldap/Client.pm

filter: Statementstmt 51.6% 16 / 31 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.4% 5 / 11 Podpod 100% 5 / 5 totaltotal 53.0% 26 / 49 CC 2 SCAR 8.1
CC
2
Cov
48%
new
6.0
__ANON__
2.0
bind
2.0
CRAP 2.2
« Quiq/List.pm ↑ Summary Quiq/MailTo.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Ldap::Client - LDAP Client
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 DESCRIPTION
14  
15 Ein Objekt der Klasse repräsentiert einen LDAP-Client. Die Klasse
16 stellt eine Überdeckung der Klasse Net::LDAP dar, mit dem Vorteil,
17 dass keine Fehlerbehandlung nötig ist, sondern im Fehlerfall
18 eine Exception geworfen wird.
19  
20 LDAP Test Zeppelin: /usr/local/bin/test_ldap_zeppelin.sh
21  
22 Homepage: L<Net::LDAP|http://ldap.perl.org/>
23  
24 =head1 EXAMPLE
25  
26 # The following example shows how to use the Class
27 # to query the RootDSE of Acctive Directory
28
29 my $ldap = Quiq::Ldap::Client->new('dc1');
30 my $res = $ldap->search(
31 base => '',
32 filter => '(objectclass=*)',
33 scope => 'base',
34 );
35 for my $ent ($res->entries) {
36 for my $key (sort $ent->attributes) {
37 print "$key:";
38 for my $val ($ent->get($key)) {
39 print " $val";
40 }
41 print "\n";
42 }
43 }
44  
45 =cut
46  
47 # -----------------------------------------------------------------------------
48  
49 package Quiq::Ldap::Client;
50 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 1 our $VERSION = '1.240';
57  
58 1 ▶use Net::LDAP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
59  
60 # -----------------------------------------------------------------------------
61  
62 =head1 METHODS
63  
64 =head2 Konstruktor
65  
66 =head3 new() - Instantiiere Objekt
67  
68 =head4 Synopsis
69  
70 $ldap = $class->new($uri,%options);
71  
72 =head4 Arguments
73  
74 =over 4
75  
76 =item $uri
77  
78 URI des LDAP-Servers. Siehe Net::LDAP.
79  
80 =item %options
81  
82 Optionen als Schlüssel/Wert-Paare. Siehe Net::LDAP.
83  
84 =back
85  
86 =head4 Returns
87  
88 Object
89  
90 =head4 Description
91  
92 Instantiiere eine Objekt der Klasse und liefere eine Referenz auf
93 dieses Objekt zurück.
94  
95 =head4 Example
96  
97 =over 2
98  
99 =item *
100  
101 LDAP
102  
103 $ldap = Quiq::Ldap::Client->new(
104 'ldap://dc1',
105 debug => 12,
106 );
107  
108 =item *
109  
110 LDAPS
111  
112 $ldap = Quiq::Ldap::Client->new(
113 'ldaps://dc1',
114 verify => 'none',
115 debug => 12,
116 );
117  
118 =back
119  
120 =cut
121  
122 # -----------------------------------------------------------------------------
123  
124 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
125 0 my ($class,$uri) = splice @_,0,2;
126 # @_: %options
127  
128 my $ldap = Net::LDAP->new($uri,
129 0 ▶ onerror => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
130 0 my $self = shift;
131 0 $class->throw(
132 'LDAP-00099: Request failed',
133 Object => $self,
134 Code => $self->code,
135 Error => $self->error,
136 );
137 },
138 0 @_,
139 );
140 0 ▶ if (!$ldap) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ldap) 0 0 0
141 0 $class->throw(
142 'LDAP-00099: Instantiation failed',
143 Error => $@,
144 );
145 }
146  
147 0 return $class->SUPER::new(
148 ldap => $ldap,
149 );
150 }
151  
152 # -----------------------------------------------------------------------------
153  
154 =head2 Objektmethoden
155  
156 =head3 bind() - Login auf LDAP-Server
157  
158 =head4 Synopsis
159  
160 $ldap->bind; # anonymous
161 $ldap->bind($dn,%options);
162  
163 =head4 Arguments
164  
165 =over 4
166  
167 =item $dn
168  
169 DN, mit der gebunden wird.
170  
171 =item %options
172  
173 Optionen als Schlüssel/Wert-Paare. Siehe Net::LDAP.
174  
175 =back
176  
177 =head4 Description
178  
179 Logge User auf LDAP-Server ein.
180  
181 =cut
182  
183 # -----------------------------------------------------------------------------
184  
185 0 ▶sub bind {
Subroutine bind: not called CC=1 SCAR=6.9
Pod documented
186 0 my $self = shift;
187 # $dn,%options
188 0 return $self->ldap->bind(@_);
189 }
190  
191 # -----------------------------------------------------------------------------
192  
193 =head3 search() - Durchsuche Server
194  
195 =head4 Synopsis
196  
197 $ldap->search(%options);
198  
199 =head4 Arguments
200  
201 =over 4
202  
203 =item %options
204  
205 Optionen als Schlüssel/Wert-Paare. Siehe Net::LDAP.
206  
207 =back
208  
209 =head4 Description
210  
211 Durchsuche den LDAP-Server durch Anwendung eines Filters.
212  
213 =cut
214  
215 # -----------------------------------------------------------------------------
216  
217 0 ▶sub search {
Subroutine search: not called CC=1 SCAR=6.9
Pod documented
218 0 my $self = shift;
219 # @_: %options
220 0 return $self->ldap->search(@_);
221 }
222  
223 # -----------------------------------------------------------------------------
224  
225 =head3 startTls() - Wandele Verbindung nach TLS
226  
227 =head4 Synopsis
228  
229 $ldap->startTls(%options);
230  
231 =head4 Arguments
232  
233 =over 4
234  
235 =item %options
236  
237 Optionen als Schlüssel/Wert-Paare. Siehe Net::LDAP.
238  
239 =back
240  
241 =head4 Description
242  
243 Wandele Verbindung nach TLS
244  
245 =cut
246  
247 # -----------------------------------------------------------------------------
248  
249 0 ▶sub startTls {
Subroutine startTls: not called CC=1 SCAR=6.9
Pod documented
250 0 my $self = shift;
251 # @_: %options
252 0 return $self->ldap->start_tls(@_);
253 }
254  
255 # -----------------------------------------------------------------------------
256  
257 =head3 unbind() - Trenne Verbindung
258  
259 =head4 Synopsis
260  
261 $ldap->unbind;
262  
263 =head4 Description
264  
265 Trenne die Verbindung zum LDAP-Server.
266  
267 =cut
268  
269 # -----------------------------------------------------------------------------
270  
271 0 ▶sub unbind {
Subroutine unbind: not called CC=1 SCAR=6.9
Pod documented
272 0 my $self = shift;
273 0 return $self->ldap->unbind;
274 }
275  
276 # -----------------------------------------------------------------------------
277  
278 =head1 VERSION
279  
280 1.240
281  
282 =head1 AUTHOR
283  
284 Frank Seitz, L<http://fseitz.de/>
285  
286 =head1 COPYRIGHT
287  
288 Copyright (C) 2026 Frank Seitz
289  
290 =head1 LICENSE
291  
292 This code is free software; you can redistribute it and/or modify
293 it under the same terms as Perl itself.
294  
295 =cut
296  
297 # -----------------------------------------------------------------------------
298  
299 1 1;
300  
301 # eof
« Quiq/List.pm ↑ Summary Quiq/MailTo.pm »