| 1 | package Catalyst::Model::LDAP::Connection; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Convenience methods for Net::LDAP | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use base qw/Net::LDAP Class::Accessor::Fast/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Catalyst::Model::LDAP::Search; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Data::Page; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use MRO::Compat; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Net::LDAP::Constant qw/LDAP_CONTROL_VLVRESPONSE/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Net::LDAP::Control::Sort; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Net::LDAP::Control::VLV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use Net::LDAP::Control::ProxyAuth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 5 | __PACKAGE__->mk_accessors(qw/base options entry_class/); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 0 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | my $base = delete $args{base}; | |||||||||||||||||||||||||||
| 24 | my %options = | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | %{ ref $args{options} eq 'HASH' ? delete $args{options} : {} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | my $entry_class = delete $args{entry_class} | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | || 'Catalyst::Model::LDAP::Entry'; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'entry_class'} || 'Catalyst::Model::LDAP::Entry'
MC/DC0%0/1
delete $args{'entry_class'} || 'Catalyst::Model::LDAP::Entry'
delete $args{'entry_class'}
Truth table0%0/2
A
A= delete $args{'entry_class'}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my $host = delete $args{host}; | |||||||||||||||||||||||||||
| 30 | 0 | my $self = $class->next::method( $host, %args ); | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | croak "Error connecting to $host: $@" unless $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | $self->base($base); | |||||||||||||||||||||||||||
| 34 | 0 | $self->options( \%options ); | |||||||||||||||||||||||||||
| 35 | 0 | $self->entry_class($entry_class); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | return $self; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub bind { | ||||||||||||||||||||||||||
|
Subroutine
bind: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | delete $args{$_} for qw/host base options connection_class entry_class/; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Bind using TLS if configured | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( delete $args{start_tls} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | my $mesg = | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $self->start_tls( %{ delete $args{start_tls_options} || {} }, ); | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'start_tls_options'} || {}
MC/DC0%0/1
delete $args{'start_tls_options'} || {}
delete $args{'start_tls_options'}
Truth table0%0/2
A
A= delete $args{'start_tls_options'}
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | croak 'LDAP TLS error: ' . $mesg->error if $mesg->is_error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # Bind via DN if configured | ||||||||||||||||||||||||||||
| 54 | 0 | my $dn = delete $args{dn}; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $self->next::method( $dn ? ( $dn, %args ) : %args ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub search { | ||||||||||||||||||||||||||
|
Subroutine
search: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | my %args = scalar @_ == 1 ? ( filter => shift ) : @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | croak "Cannot use 'page' without 'order_by'" | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if $args{page} and not $args{order_by}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"page"} and not $args{"order_by"}
MC/DC0%0/2
$args{"page"} and not $args{"order_by"}
$args{"page"}
not $args{"order_by"}
Truth table0%0/3
A and not(B)
A= $args{"page"}B= not $args{"order_by"}
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Use default base | ||||||||||||||||||||||||||||
| 68 | %args = ( | ||||||||||||||||||||||||||||
| 69 | base => $self->base, | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | %{ $self->options || {} }, | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->options || {}
MC/DC0%0/1
$self->options || {}
$self->options
Truth table0%0/2
A
A= $self->options
| |||||||||||||||||||||||||||||
| 71 | %args, | ||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # Allow ProxyAuth by itself | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ( my $authz = delete $args{authz} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | my $authz = | |||||||||||||||||||||||||||
| 77 | Net::LDAP::Control::ProxyAuth->new( authzID => q{dn:} . $authz ); | ||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $args{control} = [ @{ $args{control} || [] }, $authz ]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'control'} || []
MC/DC0%0/1
$args{'control'} || []
$args{'control'}
Truth table0%0/2
A
A= $args{'control'}
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Handle server-side sorting | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if ( my $order_by = delete $args{order_by} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | my $sort = Net::LDAP::Control::Sort->new( order => $order_by ); | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $args{control} = [ @{ $args{control} || [] }, $sort ]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'control'} || []
MC/DC0%0/1
$args{'control'} || []
$args{'control'}
Truth table0%0/2
A
A= $args{'control'}
| |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my ( $mesg, $pager ); | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( my $page = delete $args{page} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $rows = delete $args{rows} || 25; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'rows'} || 25
MC/DC0%0/1
delete $args{'rows'} || 25
delete $args{'rows'}
Truth table0%0/2
A
A= delete $args{'rows'}
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | my $vlv = Net::LDAP::Control::VLV->new( | |||||||||||||||||||||||||||
| 93 | before => 0, | ||||||||||||||||||||||||||||
| 94 | after => $rows - 1, | ||||||||||||||||||||||||||||
| 95 | content => 0, | ||||||||||||||||||||||||||||
| 96 | offset => ( $rows * $page ) - $rows + 1, | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $args{control} = [ @{ $args{control} || [] }, $vlv ]; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{'control'} || []
MC/DC0%0/1
$args{'control'} || []
$args{'control'}
Truth table0%0/2
A
A= $args{'control'}
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | $mesg = $self->next::method(%args); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | my @resp = $mesg->control(LDAP_CONTROL_VLVRESPONSE) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | or croak 'Could not get pager from LDAP response: ' | ||||||||||||||||||||||||||||
| 104 | . $mesg->server_error; | ||||||||||||||||||||||||||||
| 105 | 0 | $pager = Data::Page->new( $resp[0]->content, $rows, $page ); | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||
| 108 | 0 | $mesg = $self->next::method(%args); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | bless $mesg, 'Catalyst::Model::LDAP::Search'; | |||||||||||||||||||||||||||
| 112 | 0 | $mesg->init( $self->entry_class ); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return ( $pager ? ( $mesg, $pager ) : $mesg ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 5 | 1; | |||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | __END__ | ||||||||||||||||||||||||||||