public String getNickname() { return presence.getFrom().getResource().trim(); }
/** * Returns true if the specified address belongs to a preauthenticated session. Preauthenticated * sessions are only available to the local cluster node when running inside of a cluster. * * @param address the address of the session. * @return true if the specified address belongs to a preauthenticated session. */ public boolean isPreAuthenticatedSession(JID address) { return serverName.equals(address.getDomain()) && localSessionManager.getPreAuthenticatedSessions().containsKey(address.getResource()); }
/** * Construct a JID representing a Group from a regular JID. This constructor is * private because it is used only from within this class after the source JID * has been validated. * * @param source A full JID representing a group * @see GroupJID#fromString */ private GroupJID(JID source) { // skip stringprep for the new group JID, since it has already been parsed super(source.getNode(), source.getDomain(), source.getResource(), true); }
/** * Returns the session responsible for this JID data. The returned Session may have never sent * an available presence (thus not have a route) or could be a Session that hasn't * authenticated yet (i.e. preAuthenticatedSessions). * * @param from the sender of the packet. * @return the <code>Session</code> associated with the JID. */ public ClientSession getSession(JID from) { // Return null if the JID is null or belongs to a foreign server. If the server is // shutting down then serverName will be null so answer null too in this case. if (from == null || serverName == null || !serverName.equals(from.getDomain())) { return null; } // Initially Check preAuthenticated Sessions if (from.getResource() != null) { ClientSession session = localSessionManager.getPreAuthenticatedSessions().get(from.getResource()); if (session != null) { return session; } } if (from.getResource() == null || from.getNode() == null) { return null; } return routingTable.getClientRoute(from); }
@Override public int compareTo(JID jid) { // Comparison order is domain, node, resource. int compare = getDomain().compareTo(jid.getDomain()); if (compare == 0) { String otherNode = jid.getNode(); compare = otherNode == null ? 1 : getGroupName().compareTo(otherNode); } if (compare == 0) { compare = jid.getResource() == null ? 0 : -1; } return compare; }
/** * Returns true if a component is associated to the specified address. Components * registered with this JVM or other cluster nodes are going to be considered. * * @param componentJID the address of the component. This is the complete domain. * @return true if a component is associated to the specified address. */ public boolean hasComponent(JID componentJID) { synchronized (routables) { if (componentJID.getNode() != null || componentJID.getResource() != null) { return false; } // if (componentJID.getDomain().lastIndexOf("." + serverDomain) == -1) { // componentJID = new JID(componentJID.getDomain() + "." + serverDomain); // } return routingTable.hasComponentRoute(componentJID); } }
/** * Creates the digest needed for a byte stream. It is the SHA1(sessionID + * initiator + target). * * @param sessionID The sessionID of the stream negotiation * @param initiator The initiator of the stream negotiation * @param target The target of the stream negotiation * @return SHA-1 hash of the three parameters */ public static String createDigest(final String sessionID, final JID initiator, final JID target) { return StringUtils.hash(sessionID + initiator.getNode() + "@" + initiator.getDomain() + "/" + initiator.getResource() + target.getNode() + "@" + target.getDomain() + "/" + target.getResource(), "SHA-1"); }
/** * Returns true if the provided JID belongs to a user that is part of the group. * * @param user the JID address of the user to check. * @return true if the specified user is a group user. */ public boolean isUser(JID user) { // Make sure that we are always checking bare JIDs if (user != null && user.getResource() != null) { user = user.asBareJID(); } return user != null && (members.contains(user) || administrators.contains(user)); }
/** * Returns a JID from the given JID. If the JID represents a group, * returns an instance of this class. Otherwise returns the given JID. * * @param jid A JID, possibly representing a group * @return A new GroupJID if the given JID represents a group, or the given JID */ public static JID fromJID(JID jid) { if (jid instanceof GroupJID || jid.getResource() == null || jid.getNode() == null) { return jid; } else { return (isGroup(jid)) ? new GroupJID(jid) : jid; } }
/** * A JID is considered local if: * 1) is null or * 2) has no domain or domain is empty * or * if it's not a full JID and it was sent to the server itself. * * @param recipientJID address to check. * @return true if the specified address belongs to the local server. */ private boolean isLocalServer(JID recipientJID) { // Check if no address was specified in the IQ packet boolean implicitServer = recipientJID == null || recipientJID.getDomain() == null || "".equals(recipientJID.getDomain()); if (!implicitServer) { // We found an address. Now check if it's a bare or full JID if (recipientJID.getNode() == null || recipientJID.getResource() == null) { // Address is a bare JID so check if it was sent to the server itself return serverName.equals(recipientJID.getDomain()); } // Address is a full JID. IQ packets sent to full JIDs are not handle by the server return false; } return true; }
/** * Creates a new <tt>ClientSession</tt> with the specified streamID. * * @param conn the connection to create the session from. * @param id the streamID to use for the new session. * @param language The language to use for the new session. * @return a newly created session. */ public LocalClientSession createClientSession(Connection conn, StreamID id, Locale language) { if (serverName == null) { throw new IllegalStateException("Server not initialized"); } LocalClientSession session = new LocalClientSession(serverName, conn, id, language); conn.init(session); // Register to receive close notification on this session so we can // remove and also send an unavailable presence if it wasn't // sent before conn.registerCloseListener(clientSessionListener, session); // Add to pre-authenticated sessions. localSessionManager.getPreAuthenticatedSessions().put(session.getAddress().getResource(), session); // Increment the counter of user sessions connectionsCounter.incrementAndGet(); return session; }
/** * Returns true if the specified user is allowed to administer the node. Node * administrator are allowed to retrieve the node configuration, change the node * configuration, purge the node, delete the node and get the node affiliations and * subscriptions. * * @param user the user to check if he is an admin. * @return true if the specified user is allowed to administer the node. */ public boolean isAdmin(JID user) { if (getOwners().contains(user) || service.isServiceAdmin(user)) { return true; } // Check if we should try again but using the bare JID if (user.getResource() != null) { user = user.asBareJID(); return isAdmin(user); } return false; }
/** * Sends a message with a given subject and body to one or more user sessions related to the * specified address. If address is null or the address's node is null then the message will be * sent to all the user sessions. But if the address includes a node but no resource then * the message will be sent to all the user sessions of the requeted user (defined by the node). * Finally, if the address is a full JID then the message will be sent to the session associated * to the full JID. If no session is found then the message is not sent. * * @param address the address that defines the sessions that will receive the message. * @param subject the subject to broadcast. * @param body the body to broadcast. */ public void sendServerMessage(JID address, String subject, String body) { Message packet = createServerMessage(subject, body); if (address == null || address.getNode() == null || !userManager.isRegisteredUser(address)) { broadcast(packet); } else if (address.getResource() == null || address.getResource().length() < 1) { userBroadcast(address.getNode(), packet); } else { routingTable.routePacket(address, packet, true); } }
jid.getResource() != null && StringUtils.isBase32(node) && StringUtils.hash(groupName = decodeNode(node)).equals(jid.getResource());
/** * Creates a new ConversationLogEntry that registers that a given message was sent to a given * room on a given date. * * @param date the date when the message was sent to the room. * @param room the room that received the message. * @param message the message to log as part of the conversation in the room. * @param sender the real XMPPAddress of the sender (e.g. john@example.org). */ public ConversationLogEntry(Date date, MUCRoom room, Message message, JID sender) { this.date = date; this.subject = message.getSubject(); this.body = message.getBody(); this.stanza = message.toString(); this.sender = sender; this.roomID = room.getID(); this.nickname = message.getFrom().getResource(); }
/** * Creates a new <tt>ClientSession</tt> with the specified streamID. * * @param connection the connection to create the session from. * @param id the streamID to use for the new session. * @return a newly created session. */ public HttpSession createClientHttpSession(StreamID id, HttpConnection connection, Locale language) throws UnauthorizedException, UnknownHostException { if (serverName == null) { throw new UnauthorizedException("Server not initialized"); } PacketDeliverer backupDeliverer = server.getPacketDeliverer(); HttpSession session = new HttpSession(backupDeliverer, serverName, id, connection, language); Connection conn = session.getConnection(); conn.init(session); conn.registerCloseListener(clientSessionListener, session); localSessionManager.getPreAuthenticatedSessions().put(session.getAddress().getResource(), session); connectionsCounter.incrementAndGet(); return session; }
/** * Returns true if the specified packet must only be route to available client sessions. * * @param packet the packet to route. * @param fromServer true if the packet was created by the server. * @return true if the specified packet must only be route to available client sessions. */ private boolean routeOnlyAvailable(Packet packet, boolean fromServer) { if (fromServer) { // Packets created by the server (no matter their FROM value) must always be delivered no // matter the available presence of the user return false; } boolean onlyAvailable = true; JID from = packet.getFrom(); boolean hasSender = from != null; if (packet instanceof IQ) { onlyAvailable = hasSender && !(serverName.equals(from.getDomain()) && from.getResource() == null) && !componentsCache.containsKey(from.getDomain()); } else if (packet instanceof Message || packet instanceof Presence) { onlyAvailable = !hasSender || (!serverName.equals(from.toString()) && !componentsCache.containsKey(from.getDomain())); } return onlyAvailable; }
@Override public void sendPrivatePacket(Packet packet, MUCRole senderRole) throws NotFoundException, ForbiddenException { switch (senderRole.getRole()) { // intended fall-through case none: throw new ForbiddenException(); default: case visitor: if (canSendPrivateMessage().equals( "participants" )) throw new ForbiddenException(); case participant: if (canSendPrivateMessage().equals( "moderators" )) throw new ForbiddenException(); case moderator: if (canSendPrivateMessage().equals( "none" )) throw new ForbiddenException(); } String resource = packet.getTo().getResource(); List<MUCRole> occupants = occupantsByNickname.get(resource.toLowerCase()); if (occupants == null || occupants.size() == 0) { throw new NotFoundException(); } for (MUCRole occupant : occupants) { packet.setFrom(senderRole.getRoleAddress()); occupant.send(packet); if(packet instanceof Message) { Message message = (Message) packet; MUCEventDispatcher.privateMessageRecieved(occupant.getUserAddress(), senderRole.getUserAddress(), message); } } }
/** * Initialize the session as an anonymous login. This automatically upgrades the session's * status to authenticated and enables many features that are not available until * authenticated (obtaining managers for example).<p> */ public void setAnonymousAuth() { // Anonymous users have a full JID. Use the random resource as the JID's node String resource = getAddress().getResource(); setAddress(new JID(resource, getServerName(), resource, true)); setStatus(Session.STATUS_AUTHENTICATED); authToken = AuthToken.generateAnonymousToken(); // Add session to the session manager. The session will be added to the routing table as well sessionManager.addSession(this); }
for (MUCRole occupant : getOccupantsByNickname(presence.getFrom().getResource())) { occupant.send(presence);