[Catalyst] How to "sudo" using the Authentication plugin

Francisco Obispo fobispo at isc.org
Sat May 12 16:39:57 GMT 2012


Using the standard Authentication plugin:

<Plugin::Authentication>
default_realm default
<default>
class SimpleDB
user_model MySchema::Login
id_field name
password_field password
password_type crypted
</default>

<admin>
  class SimpleDB
  user_model MySchema::Login
  id_field name
  password_type none
</admin>

</Plugin::Authentication>


Then, whenever you need to 'sudo', just:

sub LoginAs : Private {
  my ( $self, $c ) = @_;

  my $user = $c->request->param('email') || q{};

  if ($user) {
    my $real = $c->user->name;
    $c->delete_session;
    $c->session->{real_user} = $real;
    $c->authenticate( { name => $user }, 'admin' );
    $c->response->redirect('/account/manage');
  }

  return 1;

}


Hope that helps.




On May 12, 2012, at 9:06 AM, Francisco Obispo wrote:

> No need to use a plugin, just use an authentication realm that requires no password.
> 
> Store the current user in a persistent session cookie and go back and forth with a single ->authenticate method
> 
> Sent from my iPhone
> 
> On May 12, 2012, at 6:01 AM, Robert Rothenberg <robrwo at gmail.com> wrote:
> 
>> 
>> Actually, I came across
>> 
>> Catalyst::Plugin::Authentication::Credential::NoPassword
>> 
>> in the latest version, which is apparently intended for the purpose of sudoing.
>> 
>> With a bit of fiddling, I was able to get it to work.
>> 
>> 
>> _______________________________________________
>> List: Catalyst at lists.scsys.co.uk
>> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
>> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
>> Dev site: http://dev.catalyst.perl.org/
> 
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/

Francisco Obispo 
email: fobispo at isc.org
Phone: +1 650 423 1374 || INOC-DBA *3557* NOC
PGP KeyID = B38DB1BE




More information about the Catalyst mailing list