Search in sources :

Example 1 with KrakenPlugin

use of net.sf.kraken.KrakenPlugin in project Openfire by igniterealtime.

the class TransportSessionRouter method leftCluster.

/**
     * @see org.jivesoftware.openfire.cluster.ClusterEventListener#leftCluster(byte[])
     */
public void leftCluster(byte[] leavingNodeID) {
    KrakenPlugin plugin = getPlugin();
    // TODO: Is this correct?  Lets say another node updates an entry before I get to it, will I see the update?
    for (Map.Entry<String, byte[]> entry : sessionLocations.entrySet()) {
        if (Arrays.equals(entry.getValue(), leavingNodeID)) {
            Lock l = CacheFactory.getLock(entry.getKey() + "lc", sessionLocations);
            try {
                l.lock();
                String jid = entry.getKey().substring(0, entry.getKey().lastIndexOf("@"));
                String trType = entry.getKey().substring(entry.getKey().lastIndexOf("@") + 1);
                Log.debug("Kraken: Node handling session " + jid + " on " + trType + " lost, taking over session...");
                sessionLocations.remove(jid + "@" + trType);
                TransportInstance trInstance = plugin.getTransportInstance(trType);
                if (trInstance != null) {
                    BaseTransport<? extends TransportBuddy> transport = trInstance.getTransport();
                    if (transport != null) {
                        Collection<ClientSession> sessions = XMPPServer.getInstance().getSessionManager().getSessions(new JID(jid).getNode());
                        for (ClientSession session : sessions) {
                            transport.processPacket(session.getPresence());
                        }
                    }
                }
            } finally {
                l.unlock();
            }
        }
    }
}
Also used : JID(org.xmpp.packet.JID) ClientSession(org.jivesoftware.openfire.session.ClientSession) TransportInstance(net.sf.kraken.TransportInstance) KrakenPlugin(net.sf.kraken.KrakenPlugin) Map(java.util.Map) Lock(java.util.concurrent.locks.Lock)

Example 2 with KrakenPlugin

use of net.sf.kraken.KrakenPlugin in project Openfire by igniterealtime.

the class ConfigManager method saveSettings.

/**
     * Saves settings from options screen.
     *
     * @param transportName Name of the transport to have it's options saved (type of transport)
     * @param options Options passed from options form.
     */
public void saveSettings(String transportName, HashMap<String, String> options) {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
    Document optConfig = plugin.getOptionsConfig(TransportType.valueOf(transportName));
    Element leftPanel = optConfig.getRootElement().element("leftpanel");
    if (leftPanel != null && leftPanel.nodeCount() > 0) {
        for (Object nodeObj : leftPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element rightPanel = optConfig.getRootElement().element("rightpanel");
    if (rightPanel != null && rightPanel.nodeCount() > 0) {
        for (Object nodeObj : rightPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
    Element bottomPanel = optConfig.getRootElement().element("bottompanel");
    if (bottomPanel != null && bottomPanel.nodeCount() > 0) {
        for (Object nodeObj : bottomPanel.elements("item")) {
            Element node = (Element) nodeObj;
            saveOptionSetting(node, options);
        }
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Element(org.dom4j.Element) KrakenPlugin(net.sf.kraken.KrakenPlugin) Document(org.dom4j.Document)

Example 3 with KrakenPlugin

use of net.sf.kraken.KrakenPlugin in project Openfire by igniterealtime.

the class ConfigManager method logoutSession.

/**
     * Logs out session via the web interface.
     *
     *
     * @param registrationID ID number associated with registration to log off.
     * @return registration ID on success, -1 on failure (-1 so that js cb_logoutSession knows which Div to edit)
    */
public Integer logoutSession(Integer registrationID) {
    try {
        PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
        KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
        Registration registration = new Registration(registrationID);
        if (!plugin.getTransportInstance(registration.getTransportType().toString()).isEnabled()) {
            return -1;
        }
        JID jid = registration.getJID();
        TransportSession session = plugin.getTransportInstance(registration.getTransportType().toString()).getTransport().getSessionManager().getSession(jid);
        plugin.getTransportInstance(registration.getTransportType().toString()).getTransport().registrationLoggedOut(session);
        return registrationID;
    } catch (NotFoundException e) {
        return -1;
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) JID(org.xmpp.packet.JID) Registration(net.sf.kraken.registration.Registration) NotFoundException(org.jivesoftware.util.NotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) TransportSession(net.sf.kraken.session.TransportSession) KrakenPlugin(net.sf.kraken.KrakenPlugin)

Example 4 with KrakenPlugin

use of net.sf.kraken.KrakenPlugin in project Openfire by igniterealtime.

the class ConfigManager method updateRegistration.

/**
     * Updates a registration via the web interface.
     *
     *
     * @param registrationID ID number associated with registration to modify.
     * @param legacyUsername User's updated username on the legacy service.
     * @param legacyPassword User's updated password on the legacy service, null if no change.
     * @param legacyNickname User's updated nickname on the legacy service.
     * @return Error message or null on success.
     */
public String updateRegistration(Integer registrationID, String legacyUsername, String legacyPassword, String legacyNickname) {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
    try {
        Registration reg = new Registration(registrationID);
        if (!plugin.getTransportInstance(reg.getTransportType().toString()).isEnabled()) {
            return LocaleUtils.getLocalizedString("gateway.web.registrations.notenabled", "kraken");
        }
        reg.setUsername(legacyUsername);
        if (legacyPassword != null) {
            reg.setPassword(legacyPassword);
        }
        reg.setNickname(legacyNickname);
        return null;
    } catch (NotFoundException e) {
        // Ok, nevermind.
        Log.error("Not found while editing id " + registrationID, e);
        return LocaleUtils.getLocalizedString("gateway.web.registrations.regnotfound", "kraken");
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Registration(net.sf.kraken.registration.Registration) NotFoundException(org.jivesoftware.util.NotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) KrakenPlugin(net.sf.kraken.KrakenPlugin)

Example 5 with KrakenPlugin

use of net.sf.kraken.KrakenPlugin in project Openfire by igniterealtime.

the class ConfigManager method deleteRegistration.

/**
     * Deletes a registration via the web interface.
     *
     * @param registrationID ID number associated with registration to delete.
     * @return Error message or null on success.
     */
public String deleteRegistration(Integer registrationID) {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    KrakenPlugin plugin = (KrakenPlugin) pluginManager.getPlugin("kraken");
    try {
        Registration reg = new Registration(registrationID);
        if (!plugin.getTransportInstance(reg.getTransportType().toString()).isEnabled()) {
            return LocaleUtils.getLocalizedString("gateway.web.registrations.notenabled", "kraken");
        }
        final BaseTransport transport = plugin.getTransportInstance(reg.getTransportType().toString()).getTransport();
        new RegistrationHandler(transport).deleteRegistration(reg.getJID());
        return null;
    } catch (NotFoundException e) {
        // Ok, nevermind.
        Log.error("Not found while deleting id " + registrationID, e);
        return LocaleUtils.getLocalizedString("gateway.web.registrations.xmppnotfound", "kraken");
    } catch (UserNotFoundException e) {
        // Ok, nevermind.
        Log.error("Not found while deleting id " + registrationID, e);
        return LocaleUtils.getLocalizedString("gateway.web.registrations.regnotfound", "kraken");
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Registration(net.sf.kraken.registration.Registration) RegistrationHandler(net.sf.kraken.registration.RegistrationHandler) NotFoundException(org.jivesoftware.util.NotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) BaseTransport(net.sf.kraken.BaseTransport) KrakenPlugin(net.sf.kraken.KrakenPlugin)

Aggregations

KrakenPlugin (net.sf.kraken.KrakenPlugin)8 PluginManager (org.jivesoftware.openfire.container.PluginManager)7 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 Registration (net.sf.kraken.registration.Registration)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 JID (org.xmpp.packet.JID)3 BaseTransport (net.sf.kraken.BaseTransport)2 RegistrationHandler (net.sf.kraken.registration.RegistrationHandler)2 Map (java.util.Map)1 Lock (java.util.concurrent.locks.Lock)1 TransportInstance (net.sf.kraken.TransportInstance)1 TransportSession (net.sf.kraken.session.TransportSession)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 ClientSession (org.jivesoftware.openfire.session.ClientSession)1