'user_field' => 'uid',
'user_search_options' => {
'deref' => 'always',
+ 'attrs' => [qw( distinguishedname name mail )],
},
'user_results_filter' => sub { return shift->pop_entry },
'entry_class' => 'MyApp::LDAP::Entry',
use strict;
use warnings;
-our $VERSION = '1.013';
+our $VERSION = '1.015';
use Catalyst::Authentication::Store::LDAP::User;
use Net::LDAP;
=cut
sub ldap_bind {
- my ( $self, $ldap, $binddn, $bindpw, $forauth ) = @_;
- $forauth ||= 0;
+ my ( $self, $ldap, $binddn, $bindpw ) = @_;
$ldap ||= $self->ldap_connect;
if ( !defined($ldap) ) {
Catalyst::Exception->throw("LDAP Server undefined!");
if ($bindpw) {
my $mesg = $ldap->bind( $binddn, 'password' => $bindpw );
if ( $mesg->is_error ) {
-
- # If we're not checking this bind for authentication purposes
- # Go ahead an blow up if we fail.
- if ( $forauth ne 'forauth' ) {
- Catalyst::Exception->throw(
- "Error on Initial Bind: " . $mesg->error );
- }
- else {
- return undef;
- }
+ Catalyst::Exception->throw(
+ "Error on Initial Bind: " . $mesg->error );
}
}
else {
}
}
+=head2 ldap_auth( $binddn, $bindpw )
+
+Connect to the LDAP server and do an authenticated bind against the
+directory. Throws an exception if connecting to the LDAP server fails.
+Returns 1 if binding succeeds, 0 if it fails.
+
+=cut
+
+sub ldap_auth {
+ my ( $self, $binddn, $bindpw ) = @_;
+ my $ldap = $self->ldap_connect;
+ if ( !defined $ldap ) {
+ Catalyst::Exception->throw("LDAP server undefined!");
+ }
+ my $mesg = $ldap->bind( $binddn, password => $bindpw );
+ return $mesg->is_error ? 0 : 1;
+}
+
=head2 lookup_user($id)
Given a User ID, this method will:
sub lookup_user {
my ( $self, $id ) = @_;
- # No sneaking in wildcards!
- if ( $id =~ /\*/ ) {
- Catalyst::Exception->throw("ID $id contains wildcards!");
- }
-
# Trim trailing space or we confuse ourselves
$id =~ s/\s+$//;
my $ldap = $self->ldap_bind;
if ( $self->use_roles == 0 || $self->use_roles =~ /^false$/i ) {
return undef;
}
- $ldap ||= $self->ldap_bind;
+ $ldap ||= $self->role_search_as_user
+ ? $userobj->ldap_connection : $self->ldap_bind;
my @searchopts;
if ( defined( $self->role_basedn ) ) {
push( @searchopts, 'base' => $self->role_basedn );
my $self = shift;
my $filter = shift;
my $replace = shift;
+ $replace =~ s/([*()\\\x{0}])/sprintf '\\%02x', ord($1)/ge;
$filter =~ s/\%s/$replace/g;
return $filter;
}