A better fix for the realm class name warning problem.
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Authentication / Realm.pm
index d7d33e6..db9b4c2 100644 (file)
@@ -29,10 +29,13 @@ sub new {
 
     $app->log->debug("Setting up auth realm $realmname") if $app->debug;
 
-    # use the Null store as a default
-    if( ! exists $config->{store}{class} ) {
+    # use the Null store as a default - Don't complain if the realm class is being overridden, 
+    # as the new realm may behave differently.
+    if( ! exists($config->{store}{class}) ) {
         $config->{store}{class} = '+Catalyst::Authentication::Store::Null';
-        $app->log->debug( qq(No Store specified for realm "$realmname", using the Null store.) );
+        if (! exists($config->{class})) {
+            $app->log->debug( qq(No Store specified for realm "$realmname", using the Null store.) );
+        }
     } 
     my $storeclass = $config->{'store'}{'class'};
     
@@ -171,7 +174,7 @@ sub user_is_restorable {
     my ($self, $c) = @_;
     
     return unless
-         $c->isa("Catalyst::Plugin::Session")
+         $c->can('session')
          and $self->config->{'use_session'}
          and $c->session_is_valid;
 
@@ -191,9 +194,10 @@ sub restore_user {
     
         # this sets the realm the user originated in.
         $user->auth_realm($self->name);
-    } else {
-               $c->log->error("Store claimed to have a restorable user, but restoration failed.  Did you change the user's id_field?");
-               $self->failed_user_restore($c);
+    } 
+    else {
+        $self->failed_user_restore($c) ||
+            $c->error("Store claimed to have a restorable user, but restoration failed.  Did you change the user's id_field?");
        }
         
     return $user;
@@ -201,17 +205,19 @@ sub restore_user {
 
 ## this occurs if there is a session but the thing the session refers to
 ## can not be found.  Do what you must do here.
+## Return true if you can fix the situation and find a user, false otherwise
 sub failed_user_restore {
        my ($self, $c) = @_;
        
        $self->remove_persisted_user($c);
+       return;
 }
 
 sub persist_user {
     my ($self, $c, $user) = @_;
     
     if (
-        $c->isa("Catalyst::Plugin::Session")
+        $c->can('session')
         and $self->config->{'use_session'}
         and $user->supports("session") 
     ) {
@@ -233,7 +239,7 @@ sub remove_persisted_user {
     my ($self, $c) = @_;
     
     if (
-        $c->isa("Catalyst::Plugin::Session")
+        $c->can('session')
         and $self->config->{'use_session'}
         and $c->session_is_valid
     ) {