Java 类org.jivesoftware.smack.SmackException.SecurityRequiredByServerException 实例源码

项目:Smack    文件:XMPPTCPConnection.java   
@Override
protected void afterFeaturesReceived() throws SecurityRequiredException, NotConnectedException {
    StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE);
    if (startTlsFeature != null) {
        if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) {
            notifyConnectionError(new SecurityRequiredByServerException());
            return;
        }
        // 发送StartTLS的封包
        // 让我们进入TLS链接
        if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
            send(new StartTls());
        }
    }
    // If TLS is required but the server doesn't offer it, disconnect
    // from the server and throw an error. First check if we've already negotiated TLS
    // and are secure, however (features get parsed a second time after TLS is established).
    if (!isSecureConnection() && startTlsFeature == null
                    && getConfiguration().getSecurityMode() == SecurityMode.required) {
        throw new SecurityRequiredByClientException();
    }

    if (getSASLAuthentication().authenticationSuccessful()) {
        // If we have received features after the SASL has been successfully completed, then we
        // have also *maybe* received, as it is an optional feature, the compression feature
        // from the server.
        maybeCompressFeaturesReceived.reportSuccess();
    }
}
项目:androidclient    文件:XMPPTCPConnection.java   
@Override
protected void afterFeaturesReceived() throws NotConnectedException, InterruptedException {
    StartTls startTlsFeature = getFeature(StartTls.ELEMENT, StartTls.NAMESPACE);
    if (startTlsFeature != null) {
        if (startTlsFeature.required() && config.getSecurityMode() == SecurityMode.disabled) {
            SmackException smackException = new SecurityRequiredByServerException();
            tlsHandled.reportFailure(smackException);
            notifyConnectionError(smackException);
            return;
        }

        if (config.getSecurityMode() != ConnectionConfiguration.SecurityMode.disabled) {
            sendNonza(new StartTls());
        } else {
            tlsHandled.reportSuccess();
        }
    } else {
        tlsHandled.reportSuccess();
    }

    if (getSASLAuthentication().authenticationSuccessful()) {
        // If we have received features after the SASL has been successfully completed, then we
        // have also *maybe* received, as it is an optional feature, the compression feature
        // from the server.
        maybeCompressFeaturesReceived.reportSuccess();
    }
}