store the persist_in_session setting in the session
Alexander Hartmaier [Tue, 1 Dec 2015 16:41:55 +0000 (17:41 +0100)]
so it can be used to revive the user even if the setting has been changed

lib/Catalyst/Authentication/Store/LDAP/Backend.pm
lib/Catalyst/Authentication/Store/LDAP/User.pm

index a66da0e..59f0299 100644 (file)
@@ -452,13 +452,21 @@ sub user_supports {
 
 Revives a serialized user from storage in the session.
 
+Supports users stored with a different persist_in_session setting.
+
 =cut
 
 sub from_session {
     my ( $self, $c, $frozenuser ) = @_;
 
-    if ( $self->persist_in_session eq 'all' ) {
-        return $self->user_class->new( $self, $frozenuser->{user}, $c, $frozenuser->{_roles} );
+    # we need to restore the user depending on the current storage of the
+    # user in the session store which might differ from what
+    # persist_in_session is set to now
+    if ( ref $frozenuser eq 'HASH' ) {
+        # we can rely on the existance of this key if the user is a hashref
+        if ( $frozenuser->{persist_in_session} eq 'all' ) {
+            return $self->user_class->new( $self, $frozenuser->{user}, $c, $frozenuser->{_roles} );
+        }
     }
 
     return $self->get_user( $frozenuser, $c );
index 96dc6e7..547e7c9 100644 (file)
@@ -168,6 +168,9 @@ sub roles {
 Returns the user for persistence in the session depending on the
 persist_in_session config option.
 
+Stores the persist_in_session setting so it can be used to revive the user
+even if the setting has been changed.
+
 =cut
 
 sub for_session {
@@ -175,7 +178,13 @@ sub for_session {
 
     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 {
+            # store the persistance setting in the session to know how to
+            # restore the user
+            persist_in_session  => $self->store->persist_in_session,
+            user                => $self->user,
+            _roles              => [ $self->roles ],
+        };
     }
 
     return $self->stringify;