Java Code Examples for org.jivesoftware.openfire.XMPPServer#getInstance()

The following examples show how to use org.jivesoftware.openfire.XMPPServer#getInstance() . 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: OpenfireLBSPlugin.java    From openfireLBS with Apache License 2.0 6 votes vote down vote up
@Override
public void destroyPlugin() {
	server = XMPPServer.getInstance();

	if (locationHandler != null) {
		server.getIQRouter().removeHandler(locationHandler);
		locationHandler = null;
	}

	if (openfireDBConn != null) {
		try {
			openfireDBConn.close();
			openfireDBConn = null;
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
 
Example 2
Source File: LocaleUtils.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the <code>ResourceBundle</code> that is used with this plugin.
 *
 * @param pluginName the name of the plugin.
 * @return the ResourceBundle used with this plugin.
 * @throws Exception thrown if an exception occurs.
 */
public static ResourceBundle getPluginResourceBundle(String pluginName) throws Exception {
    final Locale locale = JiveGlobals.getLocale();

    String i18nFile = getI18nFile(pluginName);

    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located.");
    }

    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    return ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
}
 
Example 3
Source File: InMemoryPubSubPersistenceProvider.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: IQPEPHandler.java    From Openfire with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: FileTransferProxy.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private void startProxy() {
    connectionManager.processConnections(bindInterface, getProxyPort());
    routingTable.addComponentRoute(getAddress(), this);
    XMPPServer server = XMPPServer.getInstance();

    server.getIQDiscoItemsHandler().addServerItemsProvider(this);
}
 
Example 6
Source File: OpenfireLBSPlugin.java    From openfireLBS with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: LocaleUtils.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an internationalized string loaded from a resource bundle from
 * the passed in plugin, using the passed in Locale.
 * 
 * If the plugin name is {@code null}, the key will be looked up using the
 * standard resource bundle.
 * 
 * If the locale is {@code null}, the Jive Global locale will be used.
 * 
 * @param key
 *            the key to use for retrieving the string from the appropriate
 *            resource bundle.
 * @param pluginName
 *            the name of the plugin to load the require resource bundle
 *            from.
 * @param arguments
 *            a list of objects to use which are formatted, then inserted
 *            into the pattern at the appropriate places.
 * @param locale
 *            the locale to use for retrieving the appropriate
 *            locale-specific string.
 * @param fallback
 *            if {@code true}, the global locale used by Openfire will be
 *            used if the requested locale is not available)
 * @return the localized string.
 */
public static String getLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) {
    if (pluginName == null) {
        return getLocalizedString(key, arguments);
    }

    if (locale == null) {
        locale = JiveGlobals.getLocale();
    }
    String i18nFile = getI18nFile(pluginName);

    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located: " + pluginName);
    }

    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
        return getLocalizedString(key, locale, arguments, bundle);
    }
    catch (MissingResourceException mre) {
        Locale jivesLocale = JiveGlobals.getLocale();
        if (fallback && !jivesLocale.equals(locale)) {
            Log.info("Could not find the requested locale. Falling back to default locale.", mre);
            return getLocalizedString(key, pluginName, arguments, jivesLocale, false);
        }
        
        Log.error(mre.getMessage(), mre);
        return key;
    }
}
 
Example 8
Source File: WebManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * @return the XMPP server object -- can get many config items from here.
 */
public XMPPServer getXMPPServer() {
    final XMPPServer xmppServer = XMPPServer.getInstance();
    if (xmppServer == null) {
        // Show that the server is down
        showServerDown();
        return null;
    }
    return xmppServer;
}
 
Example 9
Source File: AdminConsole.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the version string displayed in the admin console.
 *
 * @return the version string.
 */
public static synchronized String getVersionString() {
    Element globalVersion = (Element)generatedModel.selectSingleNode(
            "//adminconsole/global/version");
    if (globalVersion != null) {
        String pluginName = globalVersion.attributeValue("plugin");
        return getAdminText(globalVersion.getText(), pluginName);
    }
    else {
        // Default to the Openfire version if none has been provided via XML.
        XMPPServer xmppServer = XMPPServer.getInstance();
        return xmppServer.getServerInfo().getVersion().getVersionString();
    }
}
 
Example 10
Source File: PEPServiceManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
public PEPService create(JID owner) {
    // Return an error if the packet is from an anonymous, unregistered user
    // or remote user
    if (!XMPPServer.getInstance().isLocal(owner)
            || !UserManager.getInstance().isRegisteredUser(owner.getNode())) {
        throw new IllegalArgumentException(
                "Request must be initiated by a local, registered user, but is not: "
                        + owner);
    }

    PEPService pepService = null;
    final JID bareJID = owner.asBareJID();
    final Lock lock = pepServices.getLock(bareJID);
    lock.lock();
    try {

        if (pepServices.get(bareJID) != null) {
            pepService = pepServices.get(bareJID).get();
        }

        if (pepService == null) {
            pepService = new PEPService(XMPPServer.getInstance(), bareJID);
            pepServices.put(bareJID, CacheableOptional.of(pepService));
            pepService.initialize();

            if (Log.isDebugEnabled()) {
                Log.debug("PEPService created for : " + bareJID);
            }
        }
    } finally {
        lock.unlock();
    }

    return pepService;
}
 
Example 11
Source File: GcmPlugin.java    From Openfire-GCM with Apache License 2.0 5 votes vote down vote up
public void initializePlugin(PluginManager manager, File pluginDirectory) {
	Log.info("GCM Plugin started");
	
	initConf();
	mServer = XMPPServer.getInstance();
	mPresenceManager = mServer.getPresenceManager();
	mUserManager = mServer.getUserManager();
	mGson = new Gson();
	
	interceptorManager.addInterceptor(this);
}
 
Example 12
Source File: UpdateManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Recreate the list of plugins that need to be updated based on the list of
 * available plugins at igniterealtime.org.
 */
private void buildPluginsUpdateList() {
    // Reset list of plugins that need to be updated
    pluginUpdates = new ArrayList<>();
    XMPPServer server = XMPPServer.getInstance();
    Version currentServerVersion = XMPPServer.getInstance().getServerInfo().getVersion();
    // Compare local plugins versions with latest ones
    for ( final PluginMetadata plugin : server.getPluginManager().getMetadataExtractedPlugins().values() )
    {
        final AvailablePlugin latestPlugin = availablePlugins.get( plugin.getName() );

        if (latestPlugin == null)
        {
            continue;
        }

        final Version latestPluginVersion = latestPlugin.getVersion();

        if ( latestPluginVersion.isNewerThan( plugin.getVersion() ) )
        {
            // Check if the update can run in the current version of the server
            final Version pluginMinServerVersion = latestPlugin.getMinServerVersion();
            if ( pluginMinServerVersion != null && pluginMinServerVersion.isNewerThan( currentServerVersion ))
            {
                continue;
            }

            final Version pluginPriorToServerVersion = latestPlugin.getPriorToServerVersion();
            if ( pluginPriorToServerVersion != null && !pluginPriorToServerVersion.isNewerThan( currentServerVersion ))
            {
                continue;
            }

            final Update update = new Update( plugin.getName(), latestPlugin.getVersion().getVersionString(), latestPlugin.getChangelog().toExternalForm(), latestPlugin.getDownloadURL().toExternalForm() );
            pluginUpdates.add(update);
        }
    }
}
 
Example 13
Source File: UpdateManager.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private String getServerUpdateRequest() {
    XMPPServer server = XMPPServer.getInstance();
    Element xmlRequest = docFactory.createDocument().addElement("version");
    // Add current openfire version
    Element openfire = xmlRequest.addElement("openfire");
    openfire.addAttribute("current", server.getServerInfo().getVersion().getVersionString());
    return xmlRequest.asXML();
}
 
Example 14
Source File: DefaultPubSubPersistenceProvider.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public PEPService loadPEPServiceFromDB(JID jid) {
    PEPService pepService = null;

    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        // Get all PEP services
        pstmt = con.prepareStatement(GET_PEP_SERVICE);
        pstmt.setString(1, jid.toString());
        rs = pstmt.executeQuery();
        // Restore old PEPService
        while (rs.next()) {
            String serviceID = rs.getString(1);
            if ( !jid.toString().equals( serviceID )) {
                log.warn( "Loading a PEP service for {} that has a different name: {}", jid, serviceID );
            }
            // Create a new PEPService
            pepService = new PEPService(XMPPServer.getInstance(), jid);
        }
    } catch (SQLException sqle) {
        log.error(sqle.getMessage(), sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }

    return pepService;
}
 
Example 15
Source File: RosterAccess.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
    // Let node owners and sysadmins always subscribe to the node
    if (node.isAdmin(owner)) {
        return true;
    }
    for (JID nodeOwner : node.getOwners()) {
        if (nodeOwner.equals(owner)) {
            return true;
        }
    }
    // Check that the subscriber is a local user
    XMPPServer server = XMPPServer.getInstance();
    if (server.isLocal(owner)) {
        GroupManager gMgr = GroupManager.getInstance();
        Collection<String> nodeGroups = node.getRosterGroupsAllowed();
        for (String groupName : nodeGroups) {
            try {
                Group group = gMgr.getGroup(groupName);
                // access allowed if the node group is visible to the subscriber
                if (server.getRosterManager().isGroupVisible(group, owner)) {
                    return true;
                }
            } catch (GroupNotFoundException gnfe){ 
                // ignore
            }
        }
    }
    else {
        // Subscriber is a remote user. This should never happen.
        Log.warn("Node with access model Roster has a remote user as subscriber: {}", node.getUniqueIdentifier());
    }
    return false;
}
 
Example 16
Source File: PresenceAccess.java    From Openfire with Apache License 2.0 5 votes vote down vote up
@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
    // Let node owners and sysadmins always subcribe to the node
    if (node.isAdmin(owner)) {
        return true;
    }
    XMPPServer server = XMPPServer.getInstance();
    for (JID nodeOwner : node.getOwners()) {
        // Give access to the owner of the roster :)
        if (nodeOwner.equals(owner)) {
            return true;
        }
        // Check that the node owner is a local user
        if (server.isLocal(nodeOwner)) {
            try {
                Roster roster = server.getRosterManager().getRoster(nodeOwner.getNode());
                RosterItem item = roster.getRosterItem(owner);
                // Check that the subscriber is subscribe to the node owner's presence
                return item != null && (RosterItem.SUB_BOTH == item.getSubStatus() ||
                        RosterItem.SUB_FROM == item.getSubStatus());
            }
            catch (UserNotFoundException e) {
                // Do nothing
            }
        }
        else {
            // Owner of the node is a remote user. This should never happen.
            Log.warn("Node with access model Presence has a remote user as owner: {}",node.getUniqueIdentifier());
        }
    }
    return false;
}
 
Example 17
Source File: PubSubServiceInfo.java    From Openfire with Apache License 2.0 5 votes vote down vote up
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 18
Source File: PacketCopier.java    From Openfire with Apache License 2.0 5 votes vote down vote up
private PacketCopier() {
    // Add the new instance as a listener of component events. We need to react when
    // a component is no longer valid
    InternalComponentManager.getInstance().addListener(this);
    XMPPServer server = XMPPServer.getInstance();
    serverName = server.getServerInfo().getXMPPDomain();
    routingTable = server.getRoutingTable();

    // Add new instance to the PacketInterceptors list
    InterceptorManager.getInstance().addInterceptor(this);

    // Create a new task and schedule it with the new timeout
    packetsTask = new ProcessPacketsTask();
    TaskEngine.getInstance().schedule(packetsTask, 5000, 5000);
}
 
Example 19
Source File: UserManager.java    From Openfire with Apache License 2.0 4 votes vote down vote up
private UserManager() {
    this(XMPPServer.getInstance());
}
 
Example 20
Source File: SocketPacketWriteHandler.java    From Openfire with Apache License 2.0 4 votes vote down vote up
public SocketPacketWriteHandler(RoutingTable routingTable) {
    this.routingTable = routingTable;
    this.server = XMPPServer.getInstance();
}