use strict;
use warnings;
+use Scalar::Util qw/refaddr/;
-our $VERSION = '0.1004';
+our $VERSION = '1.009';
-BEGIN { __PACKAGE__->mk_accessors(qw/user store _ldap_connection_password/) }
+BEGIN { __PACKAGE__->mk_accessors(qw/user store/) }
use overload '""' => sub { shift->stringify }, fallback => 1;
+my %_ldap_connection_passwords; # Store inside-out so that they don't show up
+ # in dumps..
+
=head1 METHODS
-=head2 new($store, $user)
+=head2 new($store, $user, $c)
Takes a L<Catalyst::Authentication::Store::LDAP::Backend> object
as $store, and the data structure returned by that class's "get_user"
-method as $user.
+method as $user. The final argument is an instance of your application,
+which is passed along for those wanting to subclass User and perhaps use
+models for fetching data.
Returns a L<Catalyst::Authentication::Store::LDAP::User> object.
=cut
sub new {
- my ( $class, $store, $user ) = @_;
+ my ( $class, $store, $user, $c ) = @_;
return unless $user;
return $string;
}
else {
- my ($string) = $self->$userfield;
- return $string;
+ my $val = $self->$userfield;
+ return ref($val) eq 'ARRAY' ? $val->[0] : $val;
}
}
$self->roles($ldap);
}
# Stash a closure which can be used to retrieve the connection in the users context later.
- $self->_ldap_connection_password( sub { $password } ); # Close over
- # password to try to ensure it doesn't come out in debug dumps
- # or get serialized into sessions etc..
+ $_ldap_connection_passwords{refaddr($self)} = $password;
return 1;
}
else {
sub ldap_connection {
my $self = shift;
- my $msg = $self->store->ldap_bind( undef, $self->ldap_entry->dn,
- $self->_ldap_connection_password->() );
- $msg->code && die("Error whilst re-binding as " . $self->ldap_entry->dn
- . " after auth: " . $msg->error . " (" . $msg->code . ")");
- return $self->store;
+ $self->store->ldap_bind( undef, $self->ldap_entry->dn,
+ $_ldap_connection_passwords{refaddr($self)} );
}
=head2 AUTOLOADed methods
=cut
+sub DESTROY {
+ my $self = shift;
+ # Don't leak passwords..
+ delete $_ldap_connection_passwords{refaddr($self)};
+}
+
sub AUTOLOAD {
my $self = shift;