Update to correct behavior when using the new 'Plugin::Authentication'
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication.pm
index 3f5a1fa..4861d93 100644 (file)
@@ -11,7 +11,7 @@ use warnings;
 
 use Tie::RefHash;
 use Class::Inspector;
-use Catalyst::Plugin::Authentication::Realm;
+use Catalyst::Authentication::Realm;
 
 # this optimization breaks under Template::Toolkit
 # use user_exists instead
@@ -20,7 +20,7 @@ use Catalyst::Plugin::Authentication::Realm;
 #      constant->import(have_want => eval { require Want });
 #}
 
-our $VERSION = "0.10003";
+our $VERSION = "0.10005";
 
 sub set_authenticated {
     my ( $c, $user, $realmname ) = @_;
@@ -39,7 +39,7 @@ sub set_authenticated {
     }
     
     if (    $c->isa("Catalyst::Plugin::Session")
-        and $c->config->{authentication}{use_session}
+        and $c->config->{'Plugin::Authentication'}{'use_session'}
         and $user->supports("session") )
     {
         $realm->save_user_in_session($c, $user);
@@ -107,7 +107,7 @@ sub logout {
 
     if (
         $c->isa("Catalyst::Plugin::Session")
-        and $c->config->{authentication}{use_session}
+        and $c->config->{'Plugin::Authentication'}{'use_session'}
         and $c->session_is_valid
     ) {
         delete @{ $c->session }{qw/__user __user_realm/};
@@ -135,7 +135,7 @@ sub _user_in_session {
 
     return unless
         $c->isa("Catalyst::Plugin::Session")
-        and $c->config->{authentication}{use_session}
+        and $c->config->{'Plugin::Authentication'}{'use_session'}
         and $c->session_is_valid;
 
     return $c->session->{__user};
@@ -179,9 +179,21 @@ sub _authentication_initialize {
     ## make classdata where it is used.  
     $app->mk_classdata( '_auth_realms' => {});
     
-    my $cfg = $app->config->{'Plugin::Authentication'} ||= $app->config->{'authentication'} ||= {};
+    my $cfg = $app->config->{'Plugin::Authentication'};
+    if (!defined($cfg)) {
+        if (exists($app->config->{'authentication'})) {
+            $cfg = $app->config->{'authentication'};
+            $app->config->{'Plugin::Authentication'} = $app->config->{'authentication'};
+        } else {
+            $cfg = {};
+        }
+    }
 
-    $cfg->{use_session} = 1;
+    # old default was to force use_session on.  This must remain for that
+    # reason - but if use_session is already in the config, we respect it's setting.
+    if (!exists($cfg->{'use_session'})) {
+        $cfg->{'use_session'} = 1;
+    }
     
     if (exists($cfg->{'realms'})) {
         foreach my $realm (keys %{$cfg->{'realms'}}) {
@@ -221,9 +233,9 @@ sub setup_auth_realm {
     my $realmclass = $config->{class};
 
     if( !$realmclass ) {
-        $realmclass = 'Catalyst::Plugin::Authentication::Realm';
+        $realmclass = 'Catalyst::Authentication::Realm';
     } elsif ($realmclass !~ /^\+(.*)$/ ) {
-        $realmclass = "Catalyst::Plugin::Authentication::Realm::${realmclass}";
+        $realmclass = "Catalyst::Authentication::Realm::${realmclass}";
     } else {
         $realmclass = $1;
     }
@@ -514,7 +526,7 @@ This means that our application will begin like this:
         Authentication
     /;
 
-    __PACKAGE__->config->{authentication} = 
+    __PACKAGE__->config->{'Plugin::Authentication'} = 
                 {  
                     default_realm => 'members',
                     realms => {
@@ -611,7 +623,7 @@ verification as user_exists, with the added requirement that if there is a
 user, it must have come from the realm specified.)
 
 The above example is somewhat similar to role based access control.  
-L<Catalyst::Plugin::Authentication::Store::Minimal> treats the roles field as
+L<Catalyst::Authentication::Store::Minimal> treats the roles field as
 an array of role names. Let's leverage this. Add the role authorization
 plugin:
 
@@ -636,7 +648,7 @@ efficient to maintain a hash of users, so you move this data to a database.
 You can accomplish this simply by installing the DBIx::Class Store and
 changing your config:
 
-    __PACKAGE__->config->{authentication} = 
+    __PACKAGE__->config->{'Plugin::Authentication'} = 
                     {  
                         default_realm => 'members',
                         realms => {
@@ -662,7 +674,7 @@ new source. The rest of your application is completely unchanged.
 =head1 CONFIGURATION
 
     # example
-    __PACKAGE__->config->{authentication} = 
+    __PACKAGE__->config->{'Plugin::Authentication'} = 
                 {  
                     default_realm => 'members',
                     realms => {
@@ -712,8 +724,9 @@ This contains the series of realm configurations you want to use for your app.
 The only rule here is that there must be at least one.  A realm consists of a
 name, which is used to reference the realm, a credential and a store.  
 
-You can also specify as realm class to instantiate instead of the default
-L<Catalyst::Plugin::Authentication::Realm> class.
+You can also specify a realm class to instantiate instead of the default
+L<Catalyst::Authentication::Realm> class using the 'class' element within the
+realm config.
 
 Each realm config contains two hashes, one called 'credential' and one called 
 'store', each of which provide configuration details to the respective modules.
@@ -725,9 +738,9 @@ The 'class' element follows the standard Catalyst mechanism of class
 specification. If a class is prefixed with a +, it is assumed to be a complete
 class name. Otherwise it is considered to be a portion of the class name. For
 credentials, the classname 'B<Password>', for example, is expanded to
-Catalyst::Plugin::Authentication::Credential::B<Password>. For stores, the
+Catalyst::Authentication::Credential::B<Password>. For stores, the
 classname 'B<storename>' is expanded to:
-Catalyst::Plugin::Authentication::Store::B<storename>.
+Catalyst::Authentication::Store::B<storename>.
 
 =back
 
@@ -806,16 +819,16 @@ API of 0.10 and are therefore compatible with realms.
 
 =head2 Realms
 
-L<Catalyst::Plugin::Authentication::Realm>
+L<Catalyst::Authentication::Realm>
 
 =head2 User Storage Backends
 
-L<Catalyst::Plugin::Authentication::Store::Minimal>,
-L<Catalyst::Plugin::Authentication::Store::DBIx::Class>,
+L<Catalyst::Authentication::Store::Minimal>,
+L<Catalyst::Authentication::Store::DBIx::Class>,
 
 =head2 Credential verification
 
-L<Catalyst::Plugin::Authentication::Credential::Password>,
+L<Catalyst::Authentication::Credential::Password>,
 
 =head2 Authorization
 
@@ -886,7 +899,7 @@ included here for reference only.
 
 Return the store whose name is 'default'.
 
-This is set to C<< $c->config->{authentication}{store} >> if that value exists,
+This is set to C<< $c->config->{'Plugin::Authentication'}{store} >> if that value exists,
 or by using a Store plugin:
 
     # load the Minimal authentication store.