You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-users@mina.apache.org by Florent Georges <li...@fgeorges.org> on 2011/11/17 16:18:45 UTC
Custom authentication in an FTPlet?
Hi,
I'd like to have an FTPlet that controls the login of users
programmatically. That is, having a method that looks something
like (with any complex custom processing in isValidLogin(...)):
public FtpletResult tryLogin(FtpSession sess, FtpRequest req)
{
String user = [ get user name from sess or req ];
String pwd = [ get user name from sess or req ];
if ( isValidLogin(user, pwd) ) {
[ tell FTP Server that login is OK ]
}
else {
[ tell FTP Server that login is NOT OK ]
}
}
By using beforeCommand(...) and afterCommand(...) I can see
they are properly called on my FTPlet for USER and PASS commands.
But I just don't know what value to return from what method (or
what method to call on the session or request objects) to tell
FTP Server the outcome of the authentication taken care by my
application.
Any idea?
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
Re: Custom authentication in an FTPlet?
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Sun, Nov 20, 2011 at 10:14 PM, Florent Georges <li...@fgeorges.org> wrote:
> Niklas Gustavsson wrote:
>> On Sun, Nov 20, 2011 at 8:54 PM, Florent Georges wrote:
>
> Niklas,
>
> Thank you very much for your help, much appreciated!
>
>>> But I don't understand how I am supposed to do. If I am
>>> right, the beforeCommand() method is called first on the
>>> FTPlet, then FTP Server itself handles the command, then
>>> afterCommand() is called. But I did not find any way to
>>> handle the request myself and return myself the FtpReply I
>>> want to.
>
>> This page should describe the basics:
>> http://mina.apache.org/ftpserver/ftplet.html
>
>> You'll need to implement the handling in your Ftplet (feel free
>> to steal from the command implementations) and return SKIP to
>> the container in order to ignore the default command handler.
>
> That's what I thought too (I've read this page before). But if
> I return SKIP, how can I control the response sent back to the
> client? (that is, how can I provide the corresponding FtpReply?)
Here's a very basic example:
https://svn.apache.org/repos/asf/mina/ftpserver/trunk/ftplet-api/src/test/java/org/apache/ftpserver/ftplet/ExampleFtplet.java
/niklas
Re: Custom authentication in an FTPlet?
Posted by Florent Georges <li...@fgeorges.org>.
Niklas Gustavsson wrote:
> On Sun, Nov 20, 2011 at 8:54 PM, Florent Georges wrote:
Niklas,
Thank you very much for your help, much appreciated!
>> But I don't understand how I am supposed to do. If I am
>> right, the beforeCommand() method is called first on the
>> FTPlet, then FTP Server itself handles the command, then
>> afterCommand() is called. But I did not find any way to
>> handle the request myself and return myself the FtpReply I
>> want to.
> This page should describe the basics:
> http://mina.apache.org/ftpserver/ftplet.html
> You'll need to implement the handling in your Ftplet (feel free
> to steal from the command implementations) and return SKIP to
> the container in order to ignore the default command handler.
That's what I thought too (I've read this page before). But if
I return SKIP, how can I control the response sent back to the
client? (that is, how can I provide the corresponding FtpReply?)
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
Re: Custom authentication in an FTPlet?
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Sun, Nov 20, 2011 at 8:54 PM, Florent Georges <li...@fgeorges.org> wrote:
> Niklas Gustavsson wrote:
>> On Thu, Nov 17, 2011 at 4:18 PM, Florent Georges wrote:
>>> I'd like to have an FTPlet that controls the login of users
>>> programmatically. That is, having a method that looks
>>> something like (with any complex custom processing in
>>> isValidLogin(...)):
>
>> I would propose to use a custom UserManager rather than an
>> Ftplet for this purpose. Would that work for your case?
>
> Thanks for your response! Unfortunately I had a look at having
> a custom user manager (and made some tests), but this is not well
> documented (or I did not find the appropriate bits in the doc),
> and it's a bit hard to understand how to implement one.
>
> So for the moment, I stick to a properties file, in order to
> investigate a bit more whether FTPlets is really suitable for me.
> So now, I try to intercept a STOR command and to implement it
> myself. That is, I want to display the content of the file to the
> console (just for evaluation purpose) and respond "226 Transfer
> complete", instead of having FTP Server handling it.
>
> But I don't understand how I am supposed to do. If I am right,
> the beforeCommand() method is called first on the FTPlet, then
> FTP Server itself handles the command, then afterCommand() is
> called. But I did not find any way to handle the request myself
> and return myself the FtpReply I want to.
This page should describe the basics:
http://mina.apache.org/ftpserver/ftplet.html
You'll need to implement the handling in your Ftplet (feel free to
steal from the command implementations) and return SKIP to the
container in order to ignore the default command handler.
/niklas
Re: Custom authentication in an FTPlet?
Posted by Florent Georges <li...@fgeorges.org>.
Niklas Gustavsson wrote:
> On Thu, Nov 17, 2011 at 4:18 PM, Florent Georges wrote:
Hi Niklas,
>> I'd like to have an FTPlet that controls the login of users
>> programmatically. That is, having a method that looks
>> something like (with any complex custom processing in
>> isValidLogin(...)):
> I would propose to use a custom UserManager rather than an
> Ftplet for this purpose. Would that work for your case?
Thanks for your response! Unfortunately I had a look at having
a custom user manager (and made some tests), but this is not well
documented (or I did not find the appropriate bits in the doc),
and it's a bit hard to understand how to implement one.
So for the moment, I stick to a properties file, in order to
investigate a bit more whether FTPlets is really suitable for me.
So now, I try to intercept a STOR command and to implement it
myself. That is, I want to display the content of the file to the
console (just for evaluation purpose) and respond "226 Transfer
complete", instead of having FTP Server handling it.
But I don't understand how I am supposed to do. If I am right,
the beforeCommand() method is called first on the FTPlet, then
FTP Server itself handles the command, then afterCommand() is
called. But I did not find any way to handle the request myself
and return myself the FtpReply I want to.
Did I miss something?
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
Re: Custom authentication in an FTPlet?
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Thu, Nov 17, 2011 at 4:18 PM, Florent Georges <li...@fgeorges.org> wrote:
> I'd like to have an FTPlet that controls the login of users
> programmatically. That is, having a method that looks something
> like (with any complex custom processing in isValidLogin(...)):
I would propose to use a custom UserManager rather than an Ftplet for
this purpose. Would that work for your case?
/niklas