AnyEvent::FTP::Server::Role::Auth(3pm)

NAME
AnyEvent::FTP::Server::Role::Auth - Authentication role for FTP server

VERSION
version 0.20

SYNOPSIS
In your context:

 package AnyEvent::FTP::Server::Context::MyContext;

 use Moo;
 extends 'AnyEvent::FTP::Server::Context';
 with 'AnyEvent::FTP::Server::Role::Auth';

 has '+unauthenticated_safe_commands' => (
   default => sub { [ qw( USER PASS HELP QUIT FOO ) ] },
 );

 # this command is deemed safe pre auth by
 # unauthenticated_safe_commands
 sub cmd_foo
 {
   my($self, $con, $req) = @_;
   $con->send_response(211 => 'Here to stay');
   $self->done;
 }

 # this command can pnly be executed after
 # authentication
 sub cmd_bar
 {
   my($self, $con, $req) = @_;
   $con->send_response(211 => 'And another thing');
   $self->done;
 }

Then when you create your server object:

 use AnyEvent:FTP::Server;

 my $server = AnyEvent::FTP::Server->new;
 $server->on_connect(sub {
   # $con isa AnyEvent::FTP::Server::Connection
   my $con = shift;
   # $context isa AnyEvent::FTP::Server::Context::MyContext
   my $context = $con->context;

   # allow login from user 'user' with password 'secret'
   $context->authenticator(sub {
     my($user, $pass) = @_;
     return $user eq 'user' && $pass eq 'secret';
   });

   # make the client wait 5 seconds if they enter a
   # bad username / password
   $context->bad_authentication_delay(5);
 });

DESCRIPTION
This role provides an authentication interface for your AnyEvent::FTP::Server context.

ATTRIBUTES

  user
The user specified by the last FTP "USER" command.

  authenticated
True if the user has successfully logged in.

  authenticator
Sub ref used to check username password combinations. By default all authentication requests are refused.

  bad_authentication_delay
Number of seconds to wait after a bad login attempt.

  unauthenticated_safe_commands
List of the commands that are safe to execute before the user has authenticated. The default is USER, PASS, HELP and QUIT

METHODS

  auth_command_check_hook
 $context->auth_command_check_hook($connection, $command);

This hook checks that any commands executed by the client before authentication are in the "authenticated_safe_commands" list.

COMMANDS

USER
PASS

AUTHOR
Author: Graham Ollis <plicease@cpan.org>

Contributors:

Ryo Okamoto

Shlomi Fish

José Joaquín Atria

COPYRIGHT AND LICENSE
This software is copyright (c) 2017-2022 by Graham Ollis.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.