Added Catalyst::Plugin::Authentication::Credential::NoPassword
Oskari Okko Ojala [Fri, 30 Sep 2011 12:50:05 +0000 (15:50 +0300)]
Changes
lib/Catalyst/Plugin/Authentication.pm
lib/Catalyst/Plugin/Authentication/Credential/NoPassword.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 09e69e3..c49e5f3 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Perl extension Catalyst::Plugin::Authentication
 
+     - Catalyst::Plugin::Authentication::Credential::NoPassword added
+       (Okko)
      - Convert repository to git (fREW Schmidt)
 
 0.10018 29 Jul 2011
index e95c425..98415ce 100644 (file)
@@ -1132,9 +1132,11 @@ Florian Ragwitz C<rafl@debian.org>
 
 Stephan Jauernick C<stephanj@cpan.org>
 
+Oskari Ojala (Okko), C<perl@okko.net>
+
 =head1 COPYRIGHT & LICENSE
 
-Copyright (c) 2005 - 2009
+Copyright (c) 2005 - 2011
 the Catalyst::Plugin::Authentication L</AUTHORS>
 as listed above.
 
diff --git a/lib/Catalyst/Plugin/Authentication/Credential/NoPassword.pm b/lib/Catalyst/Plugin/Authentication/Credential/NoPassword.pm
new file mode 100644 (file)
index 0000000..a690e98
--- /dev/null
@@ -0,0 +1,81 @@
+package Catalyst::Authentication::Credential::NoPassword;
+
+use Moose;
+use utf8;
+
+has 'realm'  => (is => 'ro', required => 1);
+
+around BUILDARGS => sub {
+    my $orig  = shift;
+    my $class = shift;
+
+    if ( @_ == 3 ) {
+        my ($config, $app, $realm) = @_;
+        return $class->$orig( realm => $realm );
+    }
+    else {
+        return $class->$orig(@_);
+    }
+};
+
+sub authenticate {
+    my ($self, $c, $realm, $authinfo) = @_;
+    $self->realm->find_user($authinfo, $c);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+Catalyst::Authentication::Credential::NoPassword - Authenticate a user
+without a password.
+
+=head1 SYNOPSIS
+
+    use Catalyst qw/
+      Authentication
+      /;
+
+    package MyApp::Controller::Auth;
+
+    sub login_as_another_user : Local {
+        my ($self, $c) = @_;
+
+        if ($c->user_exists() and $c->user->username() eq 'root') {
+            $c->authenticate( {id => c->req->params->{user_id}}, 'nopassword' );
+        }
+    }
+
+=head1 DESCRIPTION
+
+This authentication credential checker takes authentication information 
+(most often a username) and retrieves the user from the store. No validation
+of any credentials is done. This is intended for administrative backdoors,
+SAML logins and so on when you have identified the new user by other means.
+
+=head1 CONFIGURATION
+
+    # example
+    <Plugin::Authentication>
+        <nopassword>
+            <credential>
+                class = NoPassword
+            </credential>
+            <store>
+                class = DBIx::Class
+                user_model = DB::User
+                role_relation = roles
+                role_field = name
+            </store>
+        </nopassword>
+    </Plugin::Authentication>
+
+=head1 METHODS
+
+=head2 authenticate ( $c, $realm, $authinfo )
+
+Try to log a user in.
+
+=cut