protected boolean login()

in geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/connection/IMAPConnection.java [468:515]


    protected boolean login() throws MessagingException
    {
        // if no username or password, fail this immediately.
        // the base connect property should resolve a username/password combo for us and
        // try again.
        if (username == null || password == null) {
            return false;
        }

        // are we permitted to use SASL mechanisms?
        if (props.getBooleanProperty(MAIL_SASL_ENABLE, false)) {
            // we might be enable for SASL, but the client and the server might
            // not have any supported mechanisms in common.  Try again with another
            // mechanism.

            //We obtain only the SASL mechanisms to use
            final List saslMechanisms = getSaslMechanisms();

            if (saslMechanisms != null && saslMechanisms.contains(AUTHENTICATION_XOAUTH2)) {
                if (processOauthAuthentication()) {
                    return true;
                }
            }

            if (processSaslAuthentication()) {
                return true;
            }
        }

        // see if we're allowed to try plain.
        if (!props.getBooleanProperty(MAIL_PLAIN_DISABLE, false) && supportsMechanism(AUTHENTICATION_PLAIN)) {
            return processPlainAuthentication();
        }

        // see if we're allowed to try login.
        if (!props.getBooleanProperty(MAIL_LOGIN_DISABLE, false) && supportsMechanism(AUTHENTICATION_LOGIN)) {
            // no authzid capability with this authentication method.
            return processLoginAuthentication();
        }

        // the server can choose to disable the LOGIN command.  If not disabled, try
        // using LOGIN rather than AUTHENTICATE.
        if (!hasCapability(CAPABILITY_LOGIN_DISABLED)) {
            return processLogin();
        }

        throw new MessagingException("No supported LOGIN methods enabled");
    }