Package ds.pjftp.command.impl

Source Code of ds.pjftp.command.impl.User

/*
* 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.user.FtpUser;
import ds.pjftp.command.Command;
import ds.pjftp.main.ClientSession;
import ds.pjftp.settings.ServerSettings;
import ds.pjftp.settings.SettingsHolder;

public class User extends Command {

    /**
     * Handles USER command.
     */
    @Override
    public void invoke(@NotNull final ClientSession session, @NotNull final String param) {

        if (session.getUser() != null) {
            session.replyWithSpace(230, "Already logged-in.");
            return;
        }

        String name = null;
        if (param.length() == 0) {
            name = "anonymous";
        } else {
            name = param;

            final ServerSettings settings = SettingsHolder.getInstance().getSettings();
            final FtpUser user = settings.getUserList().get(name);

            if (user == null) {
                session.replyWithSpace(530, "Invalid user name.");
                return;
            }
        }
        final FtpUser newUser = new FtpUser();
        newUser.setUsername(name);

        session.setUser(newUser);
        session.replyWithSpace(331, "User name OK, need password.");
    }
}
TOP

Related Classes of ds.pjftp.command.impl.User

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.