X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FAuthentication%2FStore%2FLDAP%2FUser.pm;h=96dc6e7b48ddc5a6a62699a246d14382120bbb20;hb=aa44391ef3a7c8733af638f12421df48c6c759bd;hp=82a24da0213ce30dc2d22a1a97c59753e55ddb59;hpb=ec21cfdc5435c6b8685734801275802bcfe4d3f1;p=catagits%2FCatalyst-Authentication-Store-LDAP.git diff --git a/lib/Catalyst/Authentication/Store/LDAP/User.pm b/lib/Catalyst/Authentication/Store/LDAP/User.pm index 82a24da..96dc6e7 100644 --- a/lib/Catalyst/Authentication/Store/LDAP/User.pm +++ b/lib/Catalyst/Authentication/Store/LDAP/User.pm @@ -4,7 +4,7 @@ =head1 NAME Catalyst::Authentication::Store::LDAP::User - - A User object representing an LDAP object. + - A User object representing an LDAP object. =head1 SYNOPSIS @@ -28,10 +28,10 @@ username. This wraps up an LDAP object and presents a simplified interface to it's contents. It uses some AUTOLOAD magic to pass method calls it doesn't understand through as simple read only accessors for the LDAP entries -various attributes. +various attributes. It gets grumpy if you ask for an attribute via the AUTOLOAD mechanism -that it doesn't know about. Avoid that with using "has_attribute", +that it doesn't know about. Avoid that with using "has_attribute", discussed in more detail below. You can skip all that and just go straight to the L @@ -49,8 +49,9 @@ use base qw( Catalyst::Authentication::User Class::Accessor::Fast ); use strict; use warnings; use Scalar::Util qw/refaddr/; +use Net::LDAP::Entry; -our $VERSION = '1.012'; +our $VERSION = '1.015'; BEGIN { __PACKAGE__->mk_accessors(qw/user store/) } @@ -74,11 +75,11 @@ Returns a L object. =cut sub new { - my ( $class, $store, $user, $c ) = @_; + my ( $class, $store, $user, $c, $roles ) = @_; return unless $user; - bless { store => $store, user => $user, }, $class; + bless { store => $store, user => $user, _roles => $roles }, $class; } =head2 id @@ -140,16 +141,7 @@ bind, 0 on failure. sub check_password { my ( $self, $password ) = @_; - my $ldap - = $self->store->ldap_bind( undef, $self->ldap_entry->dn, $password, - 'forauth' ); - if ( defined($ldap) ) { - if ($self->store->role_search_as_user) { - # FIXME - This can be removed and made to use the code below.. - # Have to do the role lookup _now_, as this is the only time - # that we have the user's password/ldap bind.. - $self->roles($ldap); - } + if ( $self->store->ldap_auth($self->ldap_entry->dn, $password) ) { # Stash a closure which can be used to retrieve the connection in the users context later. $_ldap_connection_passwords{refaddr($self)} = $password; return 1; @@ -167,25 +159,31 @@ Returns the results of L's "look sub roles { my $self = shift; - my $ldap = shift; - $self->{_roles} ||= [$self->store->lookup_roles($self, $ldap)]; + $self->{_roles} ||= [$self->store->lookup_roles($self)]; return @{$self->{_roles}}; } =head2 for_session -Returns the User object, stringified. +Returns the user for persistence in the session depending on the +persist_in_session config option. =cut sub for_session { my $self = shift; + + if ( $self->store->persist_in_session eq 'all' ) { + # use the roles accessor to ensure the roles are fetched + return { user => $self->user, _roles => [ $self->roles ] }; + } + return $self->stringify; } =head2 ldap_entry -Returns the raw ldap_entry. +Returns the raw ldap_entry. =cut @@ -215,7 +213,7 @@ sub attributes { =head2 has_attribute Returns the values for an attribute, or undef if that attribute is not present. -The safest way to get at an attribute. +The safest way to get at an attribute. =cut @@ -297,12 +295,12 @@ You can call: $c->user->homedirectory And you'll get the value of the "homeDirectory" attribute. Note that -all the AUTOLOADed methods are automatically lower-cased. +all the AUTOLOADed methods are automatically lower-cased. =head2 Special Keywords The highly useful and common method "username" will map to the configured -value of user_field (uid by default.) +value of user_field (uid by default.) $c->user->username == $c->user->uid @@ -350,7 +348,7 @@ __END__ Adam Jacob Some parts stolen shamelessly and entirely from -L. +L. Currently maintained by Peter Karman .