/*
* pjftp FTP server.
* Copyright (C) 2012 Dmitriy Simbiriatin <dmitriy.simbiriatin@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package ds.pjftp.command.impl;
import ds.pjftp.utils.NotNull;
import ds.pjftp.fs.FSView;
import ds.pjftp.fs.FSViews;
import ds.pjftp.user.FtpUser;
import ds.pjftp.command.Command;
import ds.pjftp.main.ClientSession;
import ds.pjftp.settings.ServerSettings;
import ds.pjftp.settings.SettingsHolder;
public class Pass extends Command {
/**
* Handles PASS command.
*/
@Override
public void invoke(@NotNull final ClientSession session, @NotNull final String param) {
final FtpUser sessionUser = session.getUser();
if (sessionUser == null) {
session.replyWithSpace(503, "Login with USER first.");
return;
}
if (sessionUser.getPassword() != null) {
session.replyWithSpace(202, "Already logged-in.");
return;
}
final ServerSettings settings = SettingsHolder.getInstance().getSettings();
final FtpUser user = settings.getUserList().get(sessionUser.getUsername());
// Checking password. For anonymous user it doesn't
// matter what password he has.
if (!param.equals(user.getPassword()) &&
!sessionUser.getUsername().equals("anonymous"))
{
session.setUser(null);
session.replyWithSpace(530, "Authentication failed.");
return;
}
sessionUser.setHomeDir(user.getHomeDir());
sessionUser.setPassword(user.getPassword());
sessionUser.setWriteAccess(user.hasWriteAccess());
final FSView fsView = FSViews.newUnixView(sessionUser);
session.setFsView(fsView);
session.replyWithSpace(230, "User logged in, proceed.");
}
}