Search in sources :

Example 6 with Registration

use of net.sf.kraken.registration.Registration 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 7 with Registration

use of net.sf.kraken.registration.Registration 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)

Example 8 with Registration

use of net.sf.kraken.registration.Registration in project Openfire by igniterealtime.

the class BaseTransport method processPacket.

/**
     * Handles all incoming presence stanzas.
     *
     * @param packet The presence packet to be processed.
     * @return list of packets that will be sent back to the presence requester.
     */
private List<Packet> processPacket(Presence packet) {
    Log.debug("Received presence packet: " + packet.toXML());
    List<Packet> reply = new ArrayList<Packet>();
    JID from = packet.getFrom();
    JID to = packet.getTo();
    if (to == null) {
        // Well clearly it's for us or it wouldn't have gotten here...
        packet.setTo(getJID());
        to = getJID();
    }
    if (packet.getType() == Presence.Type.error) {
        // We don't want to do anything with this.  Ignore it.
        return reply;
    }
    try {
        if (to.getNode() == null) {
            Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(from, this.transportType);
            if (registrations.isEmpty()) {
                // User is not registered with us.
                Log.debug("Unable to find registration.");
                Presence p = new Presence();
                p.setTo(from);
                p.setFrom(to);
                p.setError(PacketError.Condition.forbidden);
                p.setType(Presence.Type.unavailable);
                reply.add(p);
                return reply;
            }
            if (JiveGlobals.getBooleanProperty("plugin.gateway." + getType() + ".registrationstrict", false) && !permissionManager.hasAccess(from)) {
                Log.debug("Attempt to log in by restricted account: " + from);
                Presence p = new Presence();
                p.setTo(from);
                p.setFrom(to);
                p.setError(PacketError.Condition.forbidden);
                p.setType(Presence.Type.unavailable);
                reply.add(p);
                return reply;
            }
            Registration registration = registrations.iterator().next();
            // This packet is to the transport itself.
            if (packet.getType() == null) {
                // A user's resource has come online.
                TransportSession<B> session;
                Lock l = CacheFactory.getLock(registration.getJID() + "@" + transportType.toString() + "ns", sessionRouter.sessionLocations);
                try {
                    l.lock();
                    session = sessionManager.getSession(from);
                    if (session.hasResource(from.getResource())) {
                        Log.debug("An existing resource has changed status: " + from);
                        if (session.getPriority(from.getResource()) != packet.getPriority()) {
                            session.updatePriority(from.getResource(), packet.getPriority());
                        }
                        if (session.isHighestPriority(from.getResource())) {
                            // Well, this could represent a status change.
                            session.updateStatus(getPresenceType(packet), packet.getStatus());
                        }
                    } else {
                        Log.debug("A new resource has come online: " + from);
                        // This is a new resource, lets send them what we know.
                        session.addResource(from.getResource(), packet.getPriority());
                        // Tell the new resource what the state of their buddy list is.
                        session.getBuddyManager().sendAllAvailablePresences(from);
                        // If this priority is the highest, treat it's status as golden
                        if (session.isHighestPriority(from.getResource())) {
                            session.updateStatus(getPresenceType(packet), packet.getStatus());
                        }
                    }
                    // Attach the session
                    session.attachSession();
                } catch (NotFoundException e) {
                    Log.debug("A new session has come online: " + from);
                    session = this.registrationLoggedIn(registration, from, getPresenceType(packet), packet.getStatus(), packet.getPriority());
                    sessionManager.storeSession(from, session);
                } finally {
                    l.unlock();
                }
            } else if (packet.getType() == Presence.Type.unavailable) {
                // A user's resource has gone offline.
                TransportSession<B> session;
                try {
                    session = sessionManager.getSession(from);
                    String resource = from.getResource();
                    if (session.hasResource(resource)) {
                        if (session.getResourceCount() > 1) {
                            // Just one of the resources, lets adjust accordingly.
                            if (session.isHighestPriority(resource)) {
                                Log.debug("A high priority resource (of multiple) has gone offline: " + from);
                                // Ooh, the highest resource went offline, drop to next highest.
                                session.removeResource(resource);
                                // Lets ask the next highest resource what it's presence is.
                                Presence p = new Presence(Presence.Type.probe);
                                p.setTo(session.getJIDWithHighestPriority());
                                p.setFrom(this.getJID());
                                sendPacket(p);
                            } else {
                                Log.debug("A low priority resource (of multiple) has gone offline: " + from);
                                // Meh, lower priority, big whoop.
                                session.removeResource(resource);
                            }
                        } else {
                            Log.debug("A final resource has gone offline: " + from);
                            // No more resources, byebye.
                            this.registrationLoggedOut(session);
                            sessionManager.removeSession(from);
                        }
                    }
                } catch (NotFoundException e) {
                    Log.debug("Ignoring unavailable presence for inactive seession.");
                }
            } else if (packet.getType() == Presence.Type.probe) {
                // Client is asking for presence status.
                TransportSession<B> session;
                try {
                    session = sessionManager.getSession(from);
                    session.sendPresence(from);
                } catch (NotFoundException e) {
                    Log.debug("Ignoring probe presence for inactive session.");
                }
            } else {
                Log.debug("Ignoring this packet:" + packet.toString());
            // Anything else we will ignore for now.
            }
        } else {
            // This packet is to a user at the transport.
            try {
                TransportSession<B> session = sessionManager.getSession(from);
                if (packet.getType() == Presence.Type.probe) {
                    // Presence probe, lets try to answer appropriately.
                    if (session.isLoggedIn()) {
                        try {
                            TransportBuddy buddy = session.getBuddyManager().getBuddy(to);
                            buddy.sendPresence(from);
                        } catch (NotFoundException e) {
                            // User was not found so send an error presence
                            Presence p = new Presence();
                            p.setTo(from);
                            p.setFrom(to);
                            // TODO: this causes some ugliness in some clients
                            //                                p.setError(PacketError.Condition.forbidden);
                            // If the user tries to check on a buddy before we are totally logged in
                            // and have the full list, this gets thrown for legit contacts.
                            // We'll send unavailable for now.
                            p.setType(Presence.Type.unavailable);
                            sendPacket(p);
                        }
                    }
                } else if (packet.getType() == Presence.Type.subscribe) {
                    // For the time being, we are going to lie to the end user that the subscription has worked.
                    Presence p = new Presence();
                    p.setType(Presence.Type.subscribed);
                    p.setTo(from);
                    p.setFrom(to);
                    sendPacket(p);
                } else if (packet.getType() == Presence.Type.unsubscribe) {
                    // For the time being, we are going to lie to the end user that the unsubscription has worked.
                    Presence p = new Presence();
                    p.setType(Presence.Type.unsubscribed);
                    p.setTo(from);
                    p.setFrom(to);
                    sendPacket(p);
                } else if (packet.getType() == Presence.Type.subscribed) {
                    // let the legacy domain know that the contact was accepted.
                    session.acceptAddContact(packet.getTo());
                } else {
                // Anything else we will ignore for now.
                }
            } catch (NotFoundException e) {
                // Well we just don't care then.
                Log.debug("User not found while processing " + "presence stanza: " + packet.toXML(), e);
            }
        }
    } catch (Exception e) {
        Log.debug("Exception while processing packet: ", e);
    }
    return reply;
}
Also used : TransportBuddy(net.sf.kraken.roster.TransportBuddy) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) TransportSession(net.sf.kraken.session.TransportSession) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) NotFoundException(org.jivesoftware.util.NotFoundException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Lock(java.util.concurrent.locks.Lock) Registration(net.sf.kraken.registration.Registration)

Example 9 with Registration

use of net.sf.kraken.registration.Registration in project Openfire by igniterealtime.

the class XMLRPCConduit method deleteRegistration.

/**
     * Deletes a registration.
     *
     * @param password Auth password for making changes
     * @param user Username or full JID of user who is getting an account deleted.
     * @param transportType Type of transport to add user to.
     * @return Error message or "Success" on success.
     */
public String deleteRegistration(String password, String user, String transportType) {
    if (!verifyPassword(password)) {
        return "Authorization failed!";
    }
    JID jid;
    if (user.contains("@")) {
        jid = new JID(user);
    } else {
        jid = new JID(user, XMPPServer.getInstance().getServerInfo().getXMPPDomain(), null);
    }
    Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(jid, TransportType.valueOf(transportType));
    if (registrations.isEmpty()) {
        // User is not registered with us.
        return "Unable to find registration to delete.";
    }
    Registration registration = registrations.iterator().next();
    String results = configManager.deleteRegistration((int) registration.getRegistrationID());
    if (results == null) {
        return "Success";
    } else {
        return results;
    }
}
Also used : JID(org.xmpp.packet.JID) Registration(net.sf.kraken.registration.Registration)

Aggregations

Registration (net.sf.kraken.registration.Registration)9 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)5 NotFoundException (org.jivesoftware.util.NotFoundException)4 JID (org.xmpp.packet.JID)4 KrakenPlugin (net.sf.kraken.KrakenPlugin)3 PluginManager (org.jivesoftware.openfire.container.PluginManager)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 TransportSession (net.sf.kraken.session.TransportSession)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Lock (java.util.concurrent.locks.Lock)1 BaseTransport (net.sf.kraken.BaseTransport)1 RegistrationHandler (net.sf.kraken.registration.RegistrationHandler)1 TransportBuddy (net.sf.kraken.roster.TransportBuddy)1 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)1 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)1