From: Oskari Okko Ojala Date: Fri, 30 Sep 2011 12:50:05 +0000 (+0300) Subject: Added Catalyst::Plugin::Authentication::Credential::NoPassword X-Git-Tag: v0.10019~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Authentication.git;a=commitdiff_plain;h=8a31d23d60e1b252399a376007d1f2ffe271890b Added Catalyst::Plugin::Authentication::Credential::NoPassword --- diff --git a/Changes b/Changes index 09e69e3..c49e5f3 100644 --- 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 diff --git a/lib/Catalyst/Plugin/Authentication.pm b/lib/Catalyst/Plugin/Authentication.pm index e95c425..98415ce 100644 --- a/lib/Catalyst/Plugin/Authentication.pm +++ b/lib/Catalyst/Plugin/Authentication.pm @@ -1132,9 +1132,11 @@ Florian Ragwitz C Stephan Jauernick C +Oskari Ojala (Okko), C + =head1 COPYRIGHT & LICENSE -Copyright (c) 2005 - 2009 +Copyright (c) 2005 - 2011 the Catalyst::Plugin::Authentication L 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 index 0000000..a690e98 --- /dev/null +++ b/lib/Catalyst/Plugin/Authentication/Credential/NoPassword.pm @@ -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 + + + + class = NoPassword + + + class = DBIx::Class + user_model = DB::User + role_relation = roles + role_field = name + + + + +=head1 METHODS + +=head2 authenticate ( $c, $realm, $authinfo ) + +Try to log a user in. + +=cut