Search in sources :

Example 6 with OutgoingServerSocketReader

use of org.jivesoftware.openfire.server.OutgoingServerSocketReader in project Openfire by igniterealtime.

the class LocalOutgoingServerSession method attemptSASLexternal.

private static LocalOutgoingServerSession attemptSASLexternal(SocketConnection connection, MXParser xpp, XMPPPacketReader reader, DomainPair domainPair, String id, StringBuilder openingStream) throws DocumentException, IOException, XmlPullParserException {
    final Logger log = LoggerFactory.getLogger(Log.getName() + "[EXTERNAL SASL for: " + domainPair + " (Stream ID: " + id + ")]");
    log.debug("Starting EXTERNAL SASL.");
    if (doExternalAuthentication(domainPair.getLocal(), connection, reader)) {
        log.debug("EXTERNAL SASL was successful.");
        // SASL was successful so initiate a new stream
        connection.deliverRawText(openingStream.toString());
        // Reset the parser
        // xpp.resetInput();
        // // Reset the parser to use the new secured reader
        xpp.setInput(new InputStreamReader(connection.getTLSStreamHandler().getInputStream(), StandardCharsets.UTF_8));
        // Skip the opening stream sent by the server
        for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG; ) {
            eventType = xpp.next();
        }
        // SASL authentication was successful so create new OutgoingServerSession
        id = xpp.getAttributeValue("", "id");
        StreamID streamID = new BasicStreamIDFactory().createStreamID(id);
        LocalOutgoingServerSession session = new LocalOutgoingServerSession(domainPair.getLocal(), connection, new OutgoingServerSocketReader(reader), streamID);
        connection.init(session);
        // Set the remote domain name as the address of the session
        session.setAddress(new JID(null, domainPair.getRemote(), null));
        // Set that the session was created using TLS+SASL (no server dialback)
        session.usingServerDialback = false;
        return session;
    } else {
        log.debug("EXTERNAL SASL failed.");
        return null;
    }
}
Also used : OutgoingServerSocketReader(org.jivesoftware.openfire.server.OutgoingServerSocketReader) InputStreamReader(java.io.InputStreamReader) BasicStreamIDFactory(org.jivesoftware.openfire.spi.BasicStreamIDFactory) Logger(org.slf4j.Logger)

Aggregations

OutgoingServerSocketReader (org.jivesoftware.openfire.server.OutgoingServerSocketReader)6 BasicStreamIDFactory (org.jivesoftware.openfire.spi.BasicStreamIDFactory)6 Logger (org.slf4j.Logger)6 InputStreamReader (java.io.InputStreamReader)4 ServerDialback (org.jivesoftware.openfire.server.ServerDialback)4 StreamID (org.jivesoftware.openfire.StreamID)3 JID (org.xmpp.packet.JID)3 IOException (java.io.IOException)2 Socket (java.net.Socket)2 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 DocumentException (org.dom4j.DocumentException)2 Element (org.dom4j.Element)2 XMPPPacketReader (org.dom4j.io.XMPPPacketReader)2 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)2 XmlPullParser (org.xmlpull.v1.XmlPullParser)2 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)2 InputStream (java.io.InputStream)1 SocketAddress (java.net.SocketAddress)1 Map (java.util.Map)1 SSLException (javax.net.ssl.SSLException)1