AnyEvent::FTP::Server::Role::Auth - Authentication role for FTP server
version 0.19
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); });
This role provides an authentication interface for your AnyEvent::FTP::Server context.
The user specified by the last FTP USER
command.
True if the user has successfully logged in.
Sub ref used to check username password combinations. By default all authentication requests are refused.
Number of seconds to wait after a bad login attempt.
List of the commands that are safe to execute before the user has authenticated. The default is USER, PASS, HELP and QUIT
$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.
Author: Graham Ollis <plicease@cpan.org>
Contributors:
Ryo Okamoto
Shlomi Fish
José Joaquín Atria
This software is copyright (c) 2017-2021 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.