Package mireka.pop.command

Source Code of mireka.pop.command.PassCommand

package mireka.pop.command;

import static mireka.pop.SessionState.*;

import java.io.IOException;

import mireka.login.LoginDecision;
import mireka.login.LoginResult;
import mireka.login.LoginSpecification;
import mireka.pop.CommandParser;
import mireka.pop.IllegalSessionStateException;
import mireka.pop.Pop3Exception;
import mireka.pop.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PassCommand extends AbstractLoginCommand {
    private final Logger logger = LoggerFactory.getLogger(PassCommand.class);
    private final UserCommand userCommand;
    private final LoginSpecification loginSpecification;

    public PassCommand(Session session, UserCommand userCommand) {
        super(session);
        this.userCommand = userCommand;
        loginSpecification = session.getServer().getLoginSpecification();
    }

    @Override
    public void execute(CommandParser commandParser) throws IOException,
            Pop3Exception {
        if (session.getSessionState() != AUTHORIZATION_PASS_COMMAND_EXPECTED)
            throw new IllegalSessionStateException();
        String password = commandParser.parseSingleExtendedArgument();
        LoginResult result =
                loginSpecification.evaluatePlain(userCommand.user, password);
        if (result.decision == LoginDecision.VALID) {
            startTransaction(result.principal);
        } else {
            logger.debug("Unsuccessful login result: {}", result.decision);
            session.getThread().sendResponse(
                    "-ERR [AUTH] Invalid user and password combination");
            session.setSessionState(AUTHORIZATION);
        }
    }
}
TOP

Related Classes of mireka.pop.command.PassCommand

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.