org.jivesoftware.openfire.XMPPServer Java Examples
The following examples show how to use
org.jivesoftware.openfire.XMPPServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StanzaHandler.java From Openfire with Apache License 2.0 | 6 votes |
private String getStreamHeader() { StringBuilder sb = new StringBuilder(200); sb.append("<?xml version='1.0' encoding='"); sb.append(CHARSET); sb.append("'?>"); if (connection.isFlashClient()) { sb.append("<flash:stream xmlns:flash=\"http://www.jabber.com/streams/flash\" "); } else { sb.append("<stream:stream "); } sb.append("xmlns:stream=\"http://etherx.jabber.org/streams\" xmlns=\""); sb.append(getNamespace()); sb.append("\" from=\""); sb.append(XMPPServer.getInstance().getServerInfo().getXMPPDomain()); sb.append("\" id=\""); sb.append(session.getStreamID()); sb.append("\" xml:lang=\""); sb.append(session.getLanguage().toLanguageTag()); sb.append("\" version=\""); sb.append(Session.MAJOR_VERSION).append('.').append(Session.MINOR_VERSION); sb.append("\">"); return sb.toString(); }
Example #2
Source File: IQDiscoInfoHandler.java From Openfire with Apache License 2.0 | 6 votes |
/** * Removes a feature from the information returned whenever a disco for information is * made against the server. * * @param namespace the namespace of the feature to be removed. */ public void removeServerFeature(String namespace) { if (localServerFeatures.remove(namespace)) { Lock lock = CacheFactory.getLock(namespace, serverFeatures); try { lock.lock(); HashSet<NodeID> nodeIDs = serverFeatures.get(namespace); if (nodeIDs != null) { nodeIDs.remove(XMPPServer.getInstance().getNodeID()); if (nodeIDs.isEmpty()) { serverFeatures.remove(namespace); } else { serverFeatures.put(namespace, nodeIDs); } } } finally { lock.unlock(); } } }
Example #3
Source File: IQPEPHandler.java From Openfire with Apache License 2.0 | 6 votes |
@Override public void run() { // Send the last published items for the contacts on availableSessionJID's roster. try { final XMPPServer server = XMPPServer.getInstance(); final Roster roster = server.getRosterManager().getRoster(availableSessionJID.getNode()); for (final RosterItem item : roster.getRosterItems()) { if (server.isLocal(item.getJid()) && (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_TO)) { PEPService pepService = pepServiceManager.getPEPService(item.getJid().asBareJID()); if (pepService != null) { pepService.sendLastPublishedItems(availableSessionJID); } } } } catch (UserNotFoundException e) { // Do nothing } }
Example #4
Source File: IdentityStore.java From Openfire with Apache License 2.0 | 6 votes |
/** * Generates an alias that is currently unused in this store. * * @return An alias (never null). * @throws CertificateStoreConfigException if a unique alias could not be generated */ protected synchronized String generateUniqueAlias() throws CertificateStoreConfigException { final String domain = XMPPServer.getInstance().getServerInfo().getXMPPDomain(); int index = 1; String alias = domain + "_" + index; try { while ( store.containsAlias( alias ) ) { index = index + 1; alias = domain + "_" + index; } return alias; } catch ( KeyStoreException e ) { throw new CertificateStoreConfigException( "Unable to generate a unique alias for this identity store.", e ); } }
Example #5
Source File: GetNewMemberRoomsRequest.java From Openfire with Apache License 2.0 | 6 votes |
@Override public void run() { rooms = new ArrayList<>(); // Get all services that have local occupants and include them in the reply for (MultiUserChatService mucService : XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatServices()) { // Get rooms that have local occupants and include them in the reply for (MUCRoom room : mucService.getChatRooms()) { LocalMUCRoom localRoom = (LocalMUCRoom) room; Collection<MUCRole> localOccupants = new ArrayList<>(); for (MUCRole occupant : room.getOccupants()) { if (occupant.isLocal()) { localOccupants.add(occupant); } } if (!localOccupants.isEmpty()) { rooms.add(new RoomInfo(localRoom, localOccupants)); } } } }
Example #6
Source File: MultiUserChatServiceImpl.java From Openfire with Apache License 2.0 | 6 votes |
@Override public void start() { XMPPServer.getInstance().addServerListener( this ); // Run through the users every 5 minutes after a 5 minutes server startup delay (default values) userTimeoutTask = new UserTimeoutTask(); TaskEngine.getInstance().schedule(userTimeoutTask, user_timeout, user_timeout); // Remove unused rooms from memory long cleanupFreq = JiveGlobals.getLongProperty("xmpp.muc.cleanupFrequency.inMinutes", CLEANUP_FREQUENCY) * 60 * 1000; TaskEngine.getInstance().schedule(new CleanupTask(), cleanupFreq, cleanupFreq); // Set us up to answer disco item requests XMPPServer.getInstance().getIQDiscoItemsHandler().addServerItemsProvider(this); XMPPServer.getInstance().getIQDiscoInfoHandler().setServerNodeInfoProvider(this.getServiceDomain(), this); Log.info(LocaleUtils.getLocalizedString("startup.starting.muc", Collections.singletonList(getServiceDomain()))); // Load all the persistent rooms to memory for (final LocalMUCRoom room : MUCPersistenceManager.loadRoomsFromDB(this, this.getCleanupDate(), router)) { localMUCRoomManager.addRoom(room.getName().toLowerCase(),room); } }
Example #7
Source File: MultiUserChatServiceImpl.java From Openfire with Apache License 2.0 | 6 votes |
/** * Accessor uses the "double-check idiom" for proper lazy instantiation. * @return An Archiver instance, never null. */ @Override public Archiver getArchiver() { Archiver result = this.archiver; if (result == null) { synchronized (this) { result = this.archiver; if (result == null) { result = new ConversationLogEntryArchiver("MUC Service " + this.getAddress().toString(), logMaxConversationBatchSize, logMaxBatchInterval, logBatchGracePeriod); XMPPServer.getInstance().getArchiveManager().add(result); this.archiver = result; } } } return result; }
Example #8
Source File: InMemoryPubSubPersistenceProvider.java From Openfire with Apache License 2.0 | 6 votes |
@Override public PEPService loadPEPServiceFromDB(JID jid) { final PubSubService.UniqueIdentifier id = new PubSubService.UniqueIdentifier( jid.toString() ); final Lock lock = serviceIdToNodesCache.getLock( id ); lock.lock(); try { if ( serviceIdToNodesCache.containsKey( id ) ) { final PEPService pepService = new PEPService( XMPPServer.getInstance(), jid ); pepService.initialize(); // The JDBC variant stores subscriptions in the database. The in-memory variant cannot rely on this. // Subscriptions have to be repopulated from the roster instead. XMPPServer.getInstance().getIQPEPHandler().addSubscriptionForRosterItems( pepService ); return pepService; } else { return null; } } finally { lock.unlock(); } }
Example #9
Source File: PublishedItem.java From Openfire with Apache License 2.0 | 6 votes |
/** * Returns the {@link LeafNode} where this item was published. * * @return the leaf node where this item was published. */ public LeafNode getNode() { if (node == null) { synchronized (this) { if (node == null) { if (XMPPServer.getInstance().getPubSubModule().getServiceID().equals(serviceId)) { node = (LeafNode) XMPPServer.getInstance().getPubSubModule().getNode(nodeId); } else { PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager(); JID service = new JID( serviceId ); node = serviceMgr.hasCachedService(service) ? (LeafNode) serviceMgr.getPEPService(service).getNode(nodeId) : null; } } } } return node; }
Example #10
Source File: GetBasicStatistics.java From Openfire with Apache License 2.0 | 6 votes |
@Override public void run() { SessionManager manager = SessionManager.getInstance(); values = new HashMap<>(); values.put(NODE, CacheFactory.getClusterMemberID()); // Collect number of authenticated users values.put(CLIENT, manager.getUserSessionsCount(true)); // Collect number of incoming server connections values.put(INCOMING, manager.getIncomingServerSessionsCount(true)); // Collect number of outgoing server connections values.put(OUTGOING, XMPPServer.getInstance().getRoutingTable().getServerSessionsCount()); // Calculate free and used memory Runtime runtime = Runtime.getRuntime(); double freeMemory = (double) runtime.freeMemory() / (1024 * 1024); double maxMemory = (double) runtime.maxMemory() / (1024 * 1024); double totalMemory = (double) runtime.totalMemory() / (1024 * 1024); double usedMemory = totalMemory - freeMemory; values.put(MEMORY_CURRENT, usedMemory); values.put(MEMORY_MAX, maxMemory); }
Example #11
Source File: IQDiscoItemsHandler.java From Openfire with Apache License 2.0 | 6 votes |
/** * Removes a disco item for a component that has been removed from the server. * * @param jid the jid of the component being removed. */ public void removeComponentItem(String jid) { if (serverItems == null) { // Safety check return; } Lock lock = CacheFactory.getLock(jid, serverItems); try { lock.lock(); ClusteredServerItem item = serverItems.get(jid); if (item != null && item.nodes.remove(XMPPServer.getInstance().getNodeID())) { // Update the cache with latest info if (item.nodes.isEmpty()) { serverItems.remove(jid); } else { serverItems.put(jid, item); } } } finally { lock.unlock(); } // Remove locally added server item localServerItems.remove(jid); }
Example #12
Source File: PacketTransporterImpl.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void initialize(XMPPServer server) { super.initialize(server); xmppServer = server; deliverer = server.getPacketDeliverer(); transportHandler = server.getTransportHandler(); }
Example #13
Source File: GroupJID.java From Openfire with Apache License 2.0 | 5 votes |
/** * Construct a JID representing a Group. * * @param name A group name for the local domain */ public GroupJID(String name) { super(encodeNode(name), XMPPServer.getInstance().getServerInfo().getXMPPDomain(), StringUtils.hash(name), true); groupName = name; }
Example #14
Source File: IQPrivateHandler.java From Openfire with Apache License 2.0 | 5 votes |
@Override public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException { IQ replyPacket = IQ.createResultIQ(packet); Element child = packet.getChildElement(); Element dataElement = child.elementIterator().next(); if ( !XMPPServer.getInstance().isLocal( packet.getFrom()) || !UserManager.getInstance().isRegisteredUser( packet.getFrom()) ) { replyPacket.setChildElement(packet.getChildElement().createCopy()); replyPacket.setError(PacketError.Condition.service_unavailable); replyPacket.getError().setText( "Service available only to locally registered users." ); return replyPacket; } if (dataElement != null) { if (IQ.Type.get.equals(packet.getType())) { Element dataStored = privateStorage.get(packet.getFrom().getNode(), dataElement); dataStored.setParent(null); child.remove(dataElement); child.setParent(null); replyPacket.setChildElement(child); child.add(dataStored); } else { if (privateStorage.isEnabled()) { privateStorage.add(packet.getFrom().getNode(), dataElement); } else { replyPacket.setChildElement(packet.getChildElement().createCopy()); replyPacket.setError(PacketError.Condition.service_unavailable); } } } else { replyPacket.setChildElement("query", "jabber:iq:private"); } return replyPacket; }
Example #15
Source File: MultiUserChatServiceImpl.java From Openfire with Apache License 2.0 | 5 votes |
private void stop() { XMPPServer.getInstance().getIQDiscoItemsHandler().removeServerItemsProvider(this); XMPPServer.getInstance().getIQDiscoInfoHandler().removeServerNodeInfoProvider(this.getServiceDomain()); // Remove the route to this service routingTable.removeComponentRoute(getAddress()); broadcastShutdown(); XMPPServer.getInstance().removeServerListener( this ); if (archiver != null) { XMPPServer.getInstance().getArchiveManager().remove(archiver); } }
Example #16
Source File: ExternalComponentManager.java From Openfire with Apache License 2.0 | 5 votes |
/** * @param enabled enables or disables the service * @deprecated Obtain and use the corresponding {@link org.jivesoftware.openfire.spi.ConnectionListener} instead. * @throws ModificationNotAllowedException if the status of the service cannot be changed */ @Deprecated public static void setServiceEnabled(boolean enabled) throws ModificationNotAllowedException { // Alert listeners about this event for (ExternalComponentManagerListener listener : listeners) { try { listener.serviceEnabled(enabled); } catch (Exception e) { Log.warn("An exception occurred while dispatching a 'serviceEnabled' event!", e); } } ConnectionManager connectionManager = XMPPServer.getInstance().getConnectionManager(); connectionManager.enableComponentListener(enabled); }
Example #17
Source File: JigasiWrapper.java From openfire-ofmeet-plugin with Apache License 2.0 | 5 votes |
/** * Attemt to create an XMPP user that will represent the SIP contact that is pulled into a Meet. */ private static void ensureJigasiUser() { final OFMeetConfig config = new OFMeetConfig(); final String userId = config.getJigasiXmppUserId().get(); // Ensure that the user exists. final UserManager userManager = XMPPServer.getInstance().getUserManager(); if ( !userManager.isRegisteredUser( userId ) ) { Log.info( "No pre-existing jigasi user '{}' detected. Generating one.", userId ); if ( UserManager.getUserProvider().isReadOnly() ) { Log.info( "The user provider on this system is read only. Cannot create a Jigasi user account." ); return; } String password = config.getJigasiXmppPassword().get(); if ( password == null || password.isEmpty() ) { password = StringUtils.randomString( 40 ); } try { userManager.createUser( userId, password, "Jigasi User (generated)", null ); config.getJigasiXmppPassword().set( password ); } catch ( Exception e ) { Log.error( "Unable to provision a jigasi user.", e ); } } }
Example #18
Source File: RemoteMUCRole.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void send(Packet packet) { if (this.isRemoteFmuc()) { // Sending stanzas to individual occupants that are on remote FMUC nodes defeats the purpose of FMUC, which is to reduce message. This reduction is based on sending data just once, and have it 'fan out' on the remote node (as opposed to sending each occupant on that node a distinct stanza from this node). Log.warn( "Sending data directly to an entity ({}) on a remote FMUC node. Instead of individual messages, we expect data to be sent just once (and be fanned out locally by the remote node).", this, new Throwable() ); // Check if stanza needs to be enriched with FMUC metadata. augmentOutboundStanzaWithFMUCData(packet); } XMPPServer.getInstance().getRoutingTable().routePacket(userAddress, packet, false); }
Example #19
Source File: OpenfireLBSPlugin.java From openfireLBS with Apache License 2.0 | 5 votes |
@Override public void initializePlugin(PluginManager manager, File pluginDirectory) { try { openfireDBConn = DbConnectionManager.getConnection(); } catch (SQLException e) { e.printStackTrace(); } server = XMPPServer.getInstance(); server.getIQRouter().addHandler(new LocationHandler(MODULE_NAME_LOCATION)); }
Example #20
Source File: RoutingTableImpl.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void joinedCluster() { // Upon joining a cluster, the server can get a new ID. Here, all old IDs are replaced with the new identity. final NodeID defaultNodeID = server.getDefaultNodeID(); final NodeID nodeID = server.getNodeID(); if ( !defaultNodeID.equals( nodeID ) ) // In more recent versions of Openfire, the ID does not change. { CacheUtil.replaceValueInCache( serversCache, defaultNodeID, nodeID ); CacheUtil.replaceValueInMultivaluedCache( componentsCache, defaultNodeID, nodeID ); CacheUtil.replaceValueInCacheByMapping( usersCache, clientRoute -> { if ( clientRoute.getNodeID().equals( defaultNodeID ) ) { clientRoute.setNodeID( nodeID ); } return clientRoute; } ); CacheUtil.replaceValueInCacheByMapping( anonymousUsersCache, clientRoute -> { if ( clientRoute.getNodeID().equals( defaultNodeID ) ) { clientRoute.setNodeID( nodeID ); } return clientRoute; } ); } // Broadcast presence of local sessions to remote sessions when subscribed to presence // Probe presences of remote sessions when subscribed to presence of local session // Send pending subscription requests to local sessions from remote sessions // Deliver offline messages sent to local sessions that were unavailable in other nodes // Send available presences of local sessions to other resources of the same user PresenceUpdateHandler presenceUpdateHandler = XMPPServer.getInstance().getPresenceUpdateHandler(); for (LocalClientSession session : localRoutingTable.getClientRoutes()) { // Simulate that the local session has just became available session.setInitialized(false); // Simulate that current session presence has just been received presenceUpdateHandler.process(session.getPresence()); } }
Example #21
Source File: MUCRoomTask.java From Openfire with Apache License 2.0 | 5 votes |
public LocalMUCRoom getRoom() { MultiUserChatService mucService = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(subdomain); if (mucService == null) { throw new IllegalArgumentException("MUC service not found for subdomain: "+subdomain); } LocalMUCRoom room = (LocalMUCRoom) mucService.getChatRoom(roomName); if (room == null) { throw new IllegalArgumentException("Room not found: " + roomName); } return room; }
Example #22
Source File: IQOfflineMessagesHandler.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void initialize(XMPPServer server) { super.initialize(server); infoHandler = server.getIQDiscoInfoHandler(); itemsHandler = server.getIQDiscoItemsHandler(); messageStore = server.getOfflineMessageStore(); userManager = server.getUserManager(); routingTable = server.getRoutingTable(); }
Example #23
Source File: GetNumberConnectedUsers.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void run() { count = 0; for (MultiUserChatService mucService : XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatServices()) { count += mucService.getNumberConnectedUsers(true); } }
Example #24
Source File: IQPEPHandler.java From Openfire with Apache License 2.0 | 5 votes |
@Override public boolean hasInfo(String name, String node, JID senderJID) { if (node == null) return true; JID recipientJID = XMPPServer.getInstance().createJID(name, null, true).asBareJID(); PEPService pepService = pepServiceManager.getPEPService(recipientJID); return pepService.getNode(node) != null; }
Example #25
Source File: ServiceAddedEvent.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void run() { // If it's registered already, no need to create it. Most likely this is because the service // is provided by an internal component that registered at startup. This scenario, however, // should really never occur. if (!XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(subdomain)) { MultiUserChatService service = new MultiUserChatServiceImpl(subdomain, description, isHidden); XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(service, false); } }
Example #26
Source File: FileTransferProxy.java From Openfire with Apache License 2.0 | 5 votes |
@Override public void stop() { super.stop(); XMPPServer.getInstance().getIQDiscoItemsHandler() .removeComponentItem(getAddress().toString()); routingTable.removeComponentRoute(getAddress()); connectionManager.disable(); }
Example #27
Source File: PubSubServiceInfo.java From Openfire with Apache License 2.0 | 5 votes |
public PubSubServiceInfo(PubSubService pubSubService) { if (pubSubService == null) { throw new IllegalArgumentException("Argument 'pubSubService' cannot be null."); } this.pubSubService = pubSubService; xmppServer = XMPPServer.getInstance(); pubSubModule = xmppServer.getPubSubModule(); groupManager = GroupManager.getInstance(); userManager = xmppServer.getUserManager(); }
Example #28
Source File: AdminManager.java From Openfire with Apache License 2.0 | 5 votes |
/** * Adds a new account to the list of Admin accounts, based off a username, which will be converted * into a JID. * * @param username Username of account to add to list of admins. */ public void addAdminAccount(String username) { if (adminList == null) { loadAdminList(); } JID userJID = XMPPServer.getInstance().createJID(username, null); if (adminList.contains(userJID)) { // Already have them. return; } // Add new admin to cache. adminList.add(userJID); // Store updated list of admins with provider. provider.setAdmins(adminList); }
Example #29
Source File: AdminManager.java From Openfire with Apache License 2.0 | 5 votes |
/** * Removes an account from the list of Admin accounts, based off username, which will be converted * to a JID. * * @param username Username of user to remove from admin list. */ public void removeAdminAccount(String username) { if (adminList == null) { loadAdminList(); } JID userJID = XMPPServer.getInstance().createJID(username, null); if (!adminList.contains(userJID)) { return; } // Remove user from admin list cache. adminList.remove(userJID); // Store updated list of admins with provider. provider.setAdmins(adminList); }
Example #30
Source File: AdminManager.java From Openfire with Apache License 2.0 | 5 votes |
/** * Returns true if the user is an admin. * * @param username Username of user to check whether they are an admin or not. * @param allowAdminIfEmpty Allows the "admin" user to log in if the adminList is empty. * @return True or false if user is an admin. */ public boolean isUserAdmin(String username, boolean allowAdminIfEmpty) { if (adminList == null) { loadAdminList(); } if (allowAdminIfEmpty && adminList.isEmpty()) { return "admin".equals(username); } JID userJID = XMPPServer.getInstance().createJID(username, null); return adminList.contains(userJID); }