class ComponentStanzaHandler extends StanzaHandler {

    private static final Logger Log = LoggerFactory.getLogger(ComponentStanzaHandler.class);

    public ComponentStanzaHandler(PacketRouter router, Connection connection) {
        super(router, connection);
    }

    @Override
    boolean processUnknowPacket(Element doc) throws UnauthorizedException {<FILL_FUNCTION_BODY>}

    @Override
    protected void processIQ(IQ packet) throws UnauthorizedException {
        if (!session.isAuthenticated()) {
            // Session is not authenticated so return error
            IQ reply = new IQ();
            reply.setChildElement(packet.getChildElement().createCopy());
            reply.setID(packet.getID());
            reply.setTo(packet.getFrom());
            reply.setFrom(packet.getTo());
            reply.setError(PacketError.Condition.not_authorized);
            session.process(reply);
            return;
        }
        // Keep track of the component that sent an IQ get/set
        if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
            // Handle subsequent bind packets
            LocalComponentSession componentSession = (LocalComponentSession) session;
            // Get the external component of this session
            LocalComponentSession.LocalExternalComponent component =
                    (LocalComponentSession.LocalExternalComponent) componentSession.getExternalComponent();
            component.track(packet);
        }
        super.processIQ(packet);
    }

    @Override
    protected void processPresence(Presence packet) throws UnauthorizedException {
        if (!session.isAuthenticated()) {
            // Session is not authenticated so return error
            Presence reply = new Presence();
            reply.setID(packet.getID());
            reply.setTo(packet.getFrom());
            reply.setFrom(packet.getTo());
            reply.setError(PacketError.Condition.not_authorized);
            session.process(reply);
            return;
        }
        super.processPresence(packet);
    }

    @Override
    protected void processMessage(Message packet) throws UnauthorizedException {
        if (!session.isAuthenticated()) {
            // Session is not authenticated so return error
            Message reply = new Message();
            reply.setID(packet.getID());
            reply.setTo(packet.getFrom());
            reply.setFrom(packet.getTo());
            reply.setError(PacketError.Condition.not_authorized);
            session.process(reply);
            return;
        }
        super.processMessage(packet);
    }

    @Override
    void startTLS() throws Exception {
        connection.startTLS(false, false);
    }

    @Override
    Namespace getNamespace() {
        return new Namespace("", "jabber:component:accept");
    }

    @Override
    boolean validateHost() {
        return false;
    }

    @Override
    boolean validateJIDs() {
        return false;
    }

    @Override
    void createSession(String serverName, XmlPullParser xpp, Connection connection) throws XmlPullParserException
    {
        // The connected client is a connection manager so create a ConnectionMultiplexerSession
        session = LocalComponentSession.createSession(serverName, xpp, connection);
    }
}

        String tag = doc.getName();
        if ("handshake".equals(tag)) {
            // External component is trying to authenticate
            if (!((LocalComponentSession) session).authenticate(doc.getStringValue())) {
                Log.debug( "Closing session that failed to authenticate: {}", session );
                session.close();
            }
            return true;
        } else if ("error".equals(tag) && "stream".equals(doc.getNamespacePrefix())) {
            Log.debug( "Closing session because of received stream error {}. Affected session: {}", doc.asXML(), session );
            session.close();
            return true;
        } else if ("bind".equals(tag)) {
            // Handle subsequent bind packets
            LocalComponentSession componentSession = (LocalComponentSession) session;
            // Get the external component of this session
            ComponentSession.ExternalComponent component = componentSession.getExternalComponent();
            String initialDomain = component.getInitialSubdomain();
            String extraDomain = doc.attributeValue("name");
            String allowMultiple = doc.attributeValue("allowMultiple");
            if (extraDomain == null || "".equals(extraDomain)) {
                // No new bind domain was specified so return a bad_request error
                Element reply = doc.createCopy();
                reply.add(new PacketError(PacketError.Condition.bad_request).getElement());
                connection.deliverRawText(reply.asXML());
            }
            else if (extraDomain.equals(initialDomain)) {
                // Component is binding initial domain that is already registered
                // Send confirmation that the new domain has been registered
                connection.deliverRawText("<bind/>");
            }
            else if (extraDomain.endsWith(initialDomain)) {
                // Only accept subdomains under the initial registered domain
                if (allowMultiple != null && component.getSubdomains().contains(extraDomain)) {
                    // Domain already in use so return a conflict error
                    Element reply = doc.createCopy();
                    reply.add(new PacketError(PacketError.Condition.conflict).getElement());
                    connection.deliverRawText(reply.asXML());
                }
                else {
                    try {
                        // Get the requested subdomain
                        final String subdomain;
                        int index = extraDomain.indexOf( XMPPServer.getInstance().getServerInfo().getXMPPDomain() );
                        if (index > -1) {
                            subdomain = extraDomain.substring(0, index -1);
                        } else {
                            subdomain = extraDomain;
                        }
                        InternalComponentManager.getInstance().addComponent(subdomain, component);
                        componentSession.getConnection().registerCloseListener( handback -> InternalComponentManager.getInstance().removeComponent( subdomain, (ComponentSession.ExternalComponent) handback ), component );
                        // Send confirmation that the new domain has been registered
                        connection.deliverRawText("<bind/>");
                    }
                    catch (ComponentException e) {
                        Log.error("Error binding extra domain: " + extraDomain + " to component: " +
                                component, e);
                        // Return internal server error
                        Element reply = doc.createCopy();
                        reply.add(new PacketError(
                                PacketError.Condition.internal_server_error).getElement());
                        connection.deliverRawText(reply.asXML());
                    }
                }
            }
            else {
                // Return forbidden error since we only allow subdomains of the intial domain
                // to be used by the same external component
                Element reply = doc.createCopy();
                reply.add(new PacketError(PacketError.Condition.forbidden).getElement());
                connection.deliverRawText(reply.asXML());
            }
            return true;
        }
        return false;
    
<methods>public void <init>(org.jivesoftware.openfire.PacketRouter, org.jivesoftware.openfire.Connection) ,public JID getAddress() ,public void process(java.lang.String, org.dom4j.io.XMPPPacketReader) throws java.lang.Exception,public void setSession(org.jivesoftware.openfire.session.LocalSession) <variables>private static final Logger Log,public static final SystemProperty<java.lang.Boolean> PROPERTY_OVERWRITE_EMPTY_TO,private static final org.jivesoftware.openfire.StreamIDFactory STREAM_ID_FACTORY,protected org.jivesoftware.openfire.Connection connection,protected org.jivesoftware.openfire.PacketRouter router,protected org.jivesoftware.openfire.net.SASLAuthentication.Status saslStatus,protected org.jivesoftware.openfire.session.LocalSession session,protected boolean sessionCreated,protected boolean startedSASL,protected boolean startedTLS,protected boolean waitingCompressionACK