Search in sources :

Example 6 with UnauthorizedException

use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.

the class IQvCardHandler method handleIQ.

@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
    IQ result = IQ.createResultIQ(packet);
    IQ.Type type = packet.getType();
    if (type.equals(IQ.Type.set)) {
        try {
            User user = userManager.getUser(packet.getFrom().getNode());
            Element vcard = packet.getChildElement();
            if (vcard != null) {
                VCardManager.getInstance().setVCard(user.getUsername(), vcard);
            }
        } catch (UserNotFoundException e) {
            result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.item_not_found);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            result.setError(PacketError.Condition.internal_server_error);
        }
    } else if (type.equals(IQ.Type.get)) {
        JID recipient = packet.getTo();
        // If no TO was specified then get the vCard of the sender of the packet
        if (recipient == null) {
            recipient = packet.getFrom();
        }
        // By default return an empty vCard
        result.setChildElement("vCard", "vcard-temp");
        // Only try to get the vCard values of non-anonymous users
        if (recipient != null) {
            if (recipient.getNode() != null && server.isLocal(recipient)) {
                VCardManager vManager = VCardManager.getInstance();
                Element userVCard = vManager.getVCard(recipient.getNode());
                if (userVCard != null) {
                    // Check if the requester wants to ignore some vCard's fields
                    Element filter = packet.getChildElement().element(QName.get("filter", "vcard-temp-filter"));
                    if (filter != null) {
                        // Create a copy so we don't modify the original vCard
                        userVCard = userVCard.createCopy();
                        // Ignore fields requested by the user
                        for (Iterator toFilter = filter.elementIterator(); toFilter.hasNext(); ) {
                            Element field = (Element) toFilter.next();
                            Element fieldToRemove = userVCard.element(field.getName());
                            if (fieldToRemove != null) {
                                fieldToRemove.detach();
                            }
                        }
                    }
                    result.setChildElement(userVCard);
                }
            } else {
                result = IQ.createResultIQ(packet);
                result.setChildElement(packet.getChildElement().createCopy());
                result.setError(PacketError.Condition.item_not_found);
            }
        } else {
            result = IQ.createResultIQ(packet);
            result.setChildElement(packet.getChildElement().createCopy());
            result.setError(PacketError.Condition.item_not_found);
        }
    } else {
        result.setChildElement(packet.getChildElement().createCopy());
        result.setError(PacketError.Condition.not_acceptable);
    }
    return result;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) IQ(org.xmpp.packet.IQ) Iterator(java.util.Iterator) VCardManager(org.jivesoftware.openfire.vcard.VCardManager) PacketException(org.jivesoftware.openfire.PacketException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 7 with UnauthorizedException

use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.

the class HttpBindServlet method createNewSession.

protected void createNewSession(AsyncContext context, Element rootNode) throws IOException {
    final long rid = getLongAttribute(rootNode.attributeValue("rid"), -1);
    try {
        final X509Certificate[] certificates = (X509Certificate[]) context.getRequest().getAttribute("javax.servlet.request.X509Certificate");
        final HttpConnection connection = new HttpConnection(rid, context.getRequest().isSecure(), certificates, context);
        final InetAddress address = InetAddress.getByName(context.getRequest().getRemoteAddr());
        connection.setSession(sessionManager.createSession(address, rootNode, connection));
        if (JiveGlobals.getBooleanProperty("log.httpbind.enabled", false)) {
            Log.info(new Date() + ": HTTP RECV(" + connection.getSession().getStreamID().getID() + "): " + rootNode.asXML());
        }
    } catch (UnauthorizedException | HttpBindException e) {
        // Server wasn't initialized yet.
        sendLegacyError(context, BoshBindingError.internalServerError, "Server has not finished initialization.");
    }
}
Also used : UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) InetAddress(java.net.InetAddress) X509Certificate(java.security.cert.X509Certificate) Date(java.util.Date)

Example 8 with UnauthorizedException

use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.

the class ProxyConnectionManager method processConnection.

private void processConnection(Socket connection) throws IOException {
    OutputStream out = new DataOutputStream(connection.getOutputStream());
    InputStream in = new DataInputStream(connection.getInputStream());
    // first byte is version should be 5
    int b = in.read();
    if (b != 5) {
        throw new IOException("Only SOCKS5 supported");
    }
    // second byte number of authentication methods supported
    b = in.read();
    int[] auth = new int[b];
    for (int i = 0; i < b; i++) {
        auth[i] = in.read();
    }
    int authMethod = -1;
    for (int anAuth : auth) {
        // only auth method
        authMethod = (anAuth == 0 ? 0 : -1);
        // supported
        if (authMethod == 0) {
            break;
        }
    }
    if (authMethod != 0) {
        throw new IOException("Authentication method not supported");
    }
    // No auth method so respond with success
    byte[] cmd = new byte[2];
    cmd[0] = (byte) 0x05;
    cmd[1] = (byte) 0x00;
    out.write(cmd);
    String responseDigest = processIncomingSocks5Message(in);
    try {
        synchronized (connectionLock) {
            ProxyTransfer transfer = connectionMap.get(responseDigest);
            if (transfer == null) {
                transfer = createProxyTransfer(responseDigest, connection);
                transferManager.registerProxyTransfer(responseDigest, transfer);
                connectionMap.put(responseDigest, transfer);
            } else {
                transfer.setInputStream(connection.getInputStream());
            }
        }
        cmd = createOutgoingSocks5Message(0, responseDigest);
        out.write(cmd);
    } catch (UnauthorizedException eu) {
        cmd = createOutgoingSocks5Message(2, responseDigest);
        out.write(cmd);
        throw new IOException("Illegal proxy transfer");
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 9 with UnauthorizedException

use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.

the class SessionManager method createIncomingServerSession.

/**
     * Creates a session for a remote server. The session should be created only after the
     * remote server has been authenticated either using "server dialback" or SASL.
     *
     * @param conn the connection to the remote server.
     * @param id the stream ID used in the stream element when authenticating the server.
     * @return the newly created {@link IncomingServerSession}.
     * @throws UnauthorizedException if the local server has not been initialized yet.
     */
public LocalIncomingServerSession createIncomingServerSession(Connection conn, StreamID id, String fromDomain) throws UnauthorizedException {
    if (serverName == null) {
        throw new UnauthorizedException("Server not initialized");
    }
    LocalIncomingServerSession session = new LocalIncomingServerSession(serverName, conn, id, fromDomain);
    conn.init(session);
    // Register to receive close notification on this session so we can
    // remove its route from the sessions set
    conn.registerCloseListener(incomingServerListener, session);
    return session;
}
Also used : LocalIncomingServerSession(org.jivesoftware.openfire.session.LocalIncomingServerSession) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException)

Example 10 with UnauthorizedException

use of org.jivesoftware.openfire.auth.UnauthorizedException in project Openfire by igniterealtime.

the class RoutingTableImpl method routeToComponent.

/**
	 * Routes packets that are sent to components of the XMPP domain (which are
	 * subdomains of the XMPP domain)
	 * 
	 * @param jid
	 *            the recipient of the packet to route.
	 * @param packet
	 *            the packet to route.
	 * @throws PacketException
	 *             thrown if the packet is malformed (results in the sender's
	 *             session being shutdown).
	 * @return <tt>true</tt> if the packet was routed successfully,
	 *         <tt>false</tt> otherwise.
	 */
private boolean routeToComponent(JID jid, Packet packet, boolean routed) {
    if (!hasComponentRoute(jid) && !ExternalComponentManager.hasConfiguration(jid.getDomain())) {
        return false;
    }
    // First check if the component is being hosted in this JVM
    RoutableChannelHandler route = localRoutingTable.getRoute(jid.getDomain());
    if (route != null) {
        try {
            route.process(packet);
            routed = true;
        } catch (UnauthorizedException e) {
            Log.error("Unable to route packet " + packet.toXML(), e);
        }
    } else {
        // Check if other cluster nodes are hosting this component
        Set<NodeID> nodes = componentsCache.get(jid.getDomain());
        if (nodes != null) {
            for (NodeID nodeID : nodes) {
                if (server.getNodeID().equals(nodeID)) {
                    // could have been added after our previous check)
                    try {
                        RoutableChannelHandler localRoute = localRoutingTable.getRoute(jid.getDomain());
                        if (localRoute != null) {
                            localRoute.process(packet);
                            routed = true;
                            break;
                        }
                    } catch (UnauthorizedException e) {
                        Log.error("Unable to route packet " + packet.toXML(), e);
                    }
                } else {
                    // This is a route to a local component hosted in other node
                    if (remotePacketRouter != null) {
                        routed = remotePacketRouter.routePacket(nodeID.toByteArray(), jid, packet);
                        if (routed) {
                            break;
                        }
                    }
                }
            }
        }
    }
    return routed;
}
Also used : UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NodeID(org.jivesoftware.openfire.cluster.NodeID)

Aggregations

UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)30 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)13 Element (org.dom4j.Element)11 IQ (org.xmpp.packet.IQ)10 JID (org.xmpp.packet.JID)10 ConnectionException (org.jivesoftware.openfire.auth.ConnectionException)7 PacketException (org.jivesoftware.openfire.PacketException)6 InternalUnauthenticatedException (org.jivesoftware.openfire.auth.InternalUnauthenticatedException)6 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)5 IOException (java.io.IOException)4 AuthToken (org.jivesoftware.openfire.auth.AuthToken)4 StreamError (org.xmpp.packet.StreamError)4 StringprepException (gnu.inet.encoding.StringprepException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ClientSession (org.jivesoftware.openfire.session.ClientSession)3 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)3 User (org.jivesoftware.openfire.user.User)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 DataForm (org.xmpp.forms.DataForm)3 FormField (org.xmpp.forms.FormField)3