Package org.apache.vysper.xmpp.addressing

Examples of org.apache.vysper.xmpp.addressing.Entity


    public static StanzaBuilder createDirectReply(XMPPCoreStanza original, boolean fromIsServerOnly, String type) {
        if (original == null) throw new IllegalArgumentException();

        StanzaBuilder stanzaBuilder = new StanzaBuilder(original.getName(), original.getNamespaceURI(), original.getNamespacePrefix());
        // reverse to and from
        Entity newTo = original.getFrom();
        if (newTo != null) {
            stanzaBuilder.addAttribute("to", newTo.getFullQualifiedName());
        }
        Entity newFrom = original.getTo();
        if (newFrom != null) {
            if (fromIsServerOnly) newFrom = new EntityImpl(null, newFrom.getDomain(), null);
            stanzaBuilder.addAttribute("from", newFrom.getFullQualifiedName());
        }
        stanzaBuilder.addAttribute("type", type);
        if (original.getID() != null) stanzaBuilder.addAttribute("id", original.getID());

        return stanzaBuilder;
View Full Code Here


        }

        // make sure that 'from' (if present) matches the bare authorized entity
        // else repond with a stanza error 'unknown-sender'
        // see rfc3920_draft-saintandre-rfc3920bis-04.txt#8.5.4
        Entity from = stanza.getFrom();
        if (from != null && sessionContext.getInitiatingEntity() != null) {
            Entity fromBare = from.getBareJID();
            Entity initiatingEntity = sessionContext.getInitiatingEntity();
            if (!initiatingEntity.equals(fromBare)) {
                responseWriter.handleWrongFromJID(sessionContext, stanza);
                return;
            }
        }
        // make sure that there is a bound resource entry for that from's resource id attribute!
View Full Code Here

            SessionContext sessionContext) {
        // only handle IQs which are not directed to the server (vysper.org).
        // in the case where an IQ is send to the server, StanzaHandlerLookup.getIQHandler is responsible for
        // looking it up and we shouldn't have been come here in the first place.
        // but we might will relay to a component (chat.vysper.org)
        Entity to = stanza.getTo();
        if (to == null || to.equals(sessionContext.getServerJID())) {
            return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.FEATURE_NOT_IMPLEMENTED,
                    stanza, StanzaErrorType.CANCEL, null, null, null);
        }

        RosterManager rosterManager = RosterManagerUtils.getRosterInstance(serverRuntimeContext, sessionContext);

        if (outboundStanza) {
            try {

                boolean toComponent = EntityUtils.isAddressingServerComponent(to, serverRuntimeContext.getServerEnitity());

                Entity from = stanza.getFrom();
                if (from == null || !from.isResourceSet()) {
                    from = new EntityImpl(sessionContext.getInitiatingEntity(), serverRuntimeContext
                            .getResourceRegistry().getUniqueResourceForSession(sessionContext));
                }

                // determine if the is a matching subscription...
                boolean isFromContact = false;
                if (!toComponent) {
                    try {
                        isFromContact = rosterManager.retrieve(from.getBareJID()).getEntry(to.getBareJID()).hasFrom();
                    } catch (Exception e) {
                        isFromContact = false;
                    }
                }
                // deny relaying if neither isFromContact nor toComponent
                if (!isFromContact && !toComponent) {
                    return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.SERVICE_UNAVAILABLE,
                            stanza, StanzaErrorType.CANCEL, null, null, null);
                }

                Stanza forwardedStanza = StanzaBuilder.createForward(stanza, from, null).build();
                serverRuntimeContext.getStanzaRelay().relay(to, forwardedStanza,
                        new ReturnErrorToSenderFailureStrategy(serverRuntimeContext.getStanzaRelay()));
            } catch (DeliveryException e) {
                // TODO how to handle this exception?
            }
        } else {
            // write inbound stanza to the user

            Entity from = stanza.getFrom();

            boolean fromComponent = (from != null) && EntityUtils.isAddressingServerComponent(from, serverRuntimeContext.getServerEnitity());

            // determine if 'from' is a component or a matching subscription...
            boolean isToContact = false;
            if (!fromComponent) {
                try {
                    isToContact = rosterManager.retrieve(to.getBareJID()).getEntry(from.getBareJID()).hasTo();
                } catch (Exception e) {
                    isToContact = false;
                }
            }
            // ...otherwise relaying is denied
View Full Code Here

                    || (sessionContext != null && sessionContext
                            .getAttribute(SessionContext.SESSION_ATTRIBUTE_MESSAGE_STANZA_NO_RECEIVE) != null)) {
                return null;
            }

            Entity from = stanza.getFrom();
            if (from == null || !from.isResourceSet()) {
                // rewrite stanza with new from
                String resource = serverRuntimeContext.getResourceRegistry()
                        .getUniqueResourceForSession(sessionContext);
                if (resource == null)
                    throw new IllegalStateException("could not determine unique resource");
                from = new EntityImpl(sessionContext.getInitiatingEntity(), resource);
                StanzaBuilder stanzaBuilder = new StanzaBuilder(stanza.getName());
                for (Attribute attribute : stanza.getAttributes()) {
                    if ("from".equals(attribute.getName()))
                        continue;
                    stanzaBuilder.addAttribute(attribute);
                }
                stanzaBuilder.addAttribute("from", from.getFullQualifiedName());
                for (XMLElement preparedElement : stanza.getInnerElements()) {
                    stanzaBuilder.addPreparedElement(preparedElement);
                }
                stanza = XMPPCoreStanza.getWrapper(stanzaBuilder.build());
            }
View Full Code Here

                    stanza, StanzaErrorType.CANCEL, "cannot retrieve IQ-get-info result from internal components",
                    getErrorLanguage(serverRuntimeContext, sessionContext), null);
        }

        // if "vysper.org" is the server entity, 'to' can either be "vysper.org", "node@vysper.org", "service.vysper.org".
        Entity to = stanza.getTo();
        boolean isServerInfoRequest = false;
        boolean isComponentInfoRequest = false;
        Entity serviceEntity = serverRuntimeContext.getServerEnitity();
        if (to == null || to.equals(serviceEntity)) {
            isServerInfoRequest = true; // this can only be meant to query the server
        } else if (serverRuntimeContext.getComponentStanzaProcessor(to) != null) {
            isComponentInfoRequest = true; // this is a query to a component
        } else if (!to.isNodeSet()) {
            isServerInfoRequest = serviceEntity.equals(to);
            if (!isServerInfoRequest) {
                return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.ITEM_NOT_FOUND, stanza,
                        StanzaErrorType.CANCEL,
                        "server does not handle info query requests for " + to.getFullQualifiedName(),
                        getErrorLanguage(serverRuntimeContext, sessionContext), null);
View Full Code Here

            return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.INTERNAL_SERVER_ERROR,
                    stanza, StanzaErrorType.CANCEL, "cannot retrieve IQ-get-items result from internal components",
                    getErrorLanguage(serverRuntimeContext, sessionContext), null);
        }

        Entity to = stanza.getTo();
        boolean isServerInfoRequest = false;
        boolean isComponentInfoRequest = false;
        if (to == null) {
            isServerInfoRequest = true; // this can only be meant to query the server
        } else if (!to.isNodeSet()) {
            isServerInfoRequest = serverRuntimeContext.getServerEnitity().equals(to);
            isComponentInfoRequest = serverRuntimeContext.getComponentStanzaProcessor(to) != null;
            if (!isServerInfoRequest && !isComponentInfoRequest) {
                return ServerErrorResponses.getInstance().getStanzaError(StanzaErrorCondition.ITEM_NOT_FOUND, stanza,
                        StanzaErrorType.CANCEL,
                        "server does not handle items query requests for " + to.getFullQualifiedName(),
                        getErrorLanguage(serverRuntimeContext, sessionContext), null);
            }
        }

        XMLElement queryElement = stanza.getFirstInnerElement();
View Full Code Here

                            sessionContext.getXMLLang(), null)
            );
            return errorResponseContainer;*/
        }

        Entity to = stanza.getTo();
        if (sessionContext != null && sessionContext.isServerToServer() && to == null) {
            // "to" MUST be present for jabber:server
            return new ResponseStanzaContainerImpl(ServerErrorResponses.getInstance().getStreamError(
                    StreamErrorCondition.IMPROPER_ADDRESSING, stanza.getXMLLang(), "missing to attribute", null));
        }
View Full Code Here

     * @param stanza
     * @param sessionContext
     * @return The JID of the sender, either from the stanza or the context. A bare JID is returned if no, or more than one resource is bound.
     */
    public static Entity extractSenderJID(XMPPCoreStanza stanza, SessionContext sessionContext) {
        Entity from = stanza.getFrom();
        if (from == null) {
            from = new EntityImpl(sessionContext.getInitiatingEntity(), sessionContext.getServerRuntimeContext()
                    .getResourceRegistry().getUniqueResourceForSession(sessionContext));
        }
        return from;
View Full Code Here

     * @param stanza
     * @param sessionContext
     * @return The JID of the sender, either from the stanza or the context. If there is no, or multiple resources bound, it returns null.
     */
    public static Entity extractUniqueSenderJID(XMPPCoreStanza stanza, SessionContext sessionContext) {
        Entity from = stanza.getFrom();
        if (from != null) {
            return from;
        }

        // Use the information stored within the context
        Entity initiatingEntity = sessionContext.getInitiatingEntity();
        if (initiatingEntity == null) {
            throw new RuntimeException("no 'from' attribute, and initiating entity not set");
        }

        String resourceId = sessionContext.getServerRuntimeContext().getResourceRegistry().getUniqueResourceForSession(
                sessionContext);
        if (resourceId == null) {
            logger
                    .warn(
                            "no 'from' attribute, and cannot uniquely determine sending resource for initiating entity {} in session {}",
                            initiatingEntity.getFullQualifiedName(), sessionContext.getSessionId());
            return null;
        }

        return new EntityImpl(initiatingEntity, resourceId);
    }
View Full Code Here

        OpenStorageProviderRegistry storageProviderRegistry = new OpenStorageProviderRegistry();
        storageProviderRegistry.add(rosterManager);
        ((DefaultServerRuntimeContext) sessionContext.getServerRuntimeContext())
                .setStorageProviderRegistry(storageProviderRegistry);

        Entity client = EntityImpl.parse("tester@vysper.org");
        sessionContext.setInitiatingEntity(client);
        initiatingUser = TestUser.createForSession(sessionContext, client);

        // set up more resources for the same session
        anotherInterestedNotAvailUser = TestUser.createForSession(sessionContext, client);
View Full Code Here

TOP

Related Classes of org.apache.vysper.xmpp.addressing.Entity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.