Search in sources :

Example 26 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class PseudoRosterManager method getPseudoRoster.

/**
     * Retrieves a pseudo roster based off of a registration.
     *
     * @param jid To retrieve the roster for.
     * @param type TransportType the roster is for.
     * @return A Pseudo roster
     * @throws UserNotFoundException if the user is not actually registered.
     */
public PseudoRoster getPseudoRoster(JID jid, TransportType type) throws UserNotFoundException {
    Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(jid, type);
    if (registrations.isEmpty()) {
        // User is not registered with us.
        throw new UserNotFoundException("Unable to find registration.");
    }
    Registration registration = registrations.iterator().next();
    return getPseudoRoster(registration);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Registration(net.sf.kraken.registration.Registration)

Example 27 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class RegistrationHandler method handleDeregister.

/**
     * Processes an IQ-register request that is expressing the wish to
     * deregister from a gateway.
     *
     * @param packet the IQ-register stanza.
     */
private void handleDeregister(final IQ packet) {
    final IQ result = IQ.createResultIQ(packet);
    if (packet.getChildElement().elements().size() != 1) {
        Log.debug("Cannot process this stanza - exactly one" + " childelement of <remove> expected:" + packet.toXML());
        final IQ error = IQ.createResultIQ(packet);
        error.setError(Condition.bad_request);
        parent.sendPacket(error);
        return;
    }
    final JID from = packet.getFrom();
    final JID to = packet.getTo();
    // Tell the end user the transport went byebye.
    final Presence unavailable = new Presence(Presence.Type.unavailable);
    unavailable.setTo(from);
    unavailable.setFrom(to);
    this.parent.sendPacket(unavailable);
    try {
        deleteRegistration(from);
    } catch (UserNotFoundException e) {
        Log.debug("Error cleaning up contact list of: " + from);
        result.setError(Condition.registration_required);
    }
    parent.sendPacket(result);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) IQ(org.xmpp.packet.IQ) Presence(org.xmpp.packet.Presence)

Example 28 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class RegistrationHandler method addNewRegistration.

/**
     * Adds a registration with this transport, or updates an existing one.
     *
     * @param jid          JID of user to add registration to.
     * @param username     Legacy username of registration.
     * @param password     Legacy password of registration.
     * @param nickname     Legacy nickname of registration.
     * @param noRosterItem True if the transport is not to show up in the user's roster.
     * @throws UserNotFoundException    if registration or roster not found.
     * @throws IllegalAccessException   if jid is not from this server.
     * @throws IllegalArgumentException if username is not valid for this transport type.
     */
public void addNewRegistration(JID jid, String username, String password, String nickname, Boolean noRosterItem) throws UserNotFoundException, IllegalAccessException {
    Log.debug("Adding or updating registration for : " + jid.toString() + " / " + username);
    if (!XMPPServer.getInstance().isLocal(jid)) {
        throw new IllegalAccessException("Domain of jid registering does not match domain of server.");
    }
    if (!parent.isUsernameValid(username)) {
        throw new IllegalArgumentException("Username specified is not valid for this transport type.");
    }
    final Collection<Registration> registrations = RegistrationManager.getInstance().getRegistrations(jid, parent.transportType);
    boolean foundReg = false;
    boolean triggerRestart = false;
    for (final Registration registration : registrations) {
        if (!registration.getUsername().equals(username)) {
            Log.debug("Deleting existing registration before" + " creating a new one: " + registration);
            RegistrationManager.getInstance().deleteRegistration(registration);
        } else {
            Log.debug("Existing registration found that can be updated: " + registration);
            if ((registration.getPassword() != null && password == null) || (registration.getPassword() == null && password != null) || (registration.getPassword() != null && password != null && !registration.getPassword().equals(password))) {
                Log.debug("Updating password for existing registration: " + registration);
                registration.setPassword(password);
                triggerRestart = true;
            }
            if ((registration.getNickname() != null && nickname == null) || (registration.getNickname() == null && nickname != null) || (registration.getNickname() != null && nickname != null && !registration.getNickname().equals(nickname))) {
                Log.debug("Updating nickname for existing registration: " + registration);
                registration.setNickname(nickname);
                triggerRestart = true;
            }
            foundReg = true;
        }
        // if a change was made to the registration, restart it.
        if (triggerRestart) {
            try {
                Log.debug("An existing registration was " + "updated. Restarting the related session: " + registration);
                final TransportSession relatedSession = parent.sessionManager.getSession(registration.getJID().getNode());
                parent.registrationLoggedOut(relatedSession);
            } catch (NotFoundException e) {
            // No worries, move on.
            }
        }
    }
    if (!foundReg) {
        RegistrationManager.getInstance().createRegistration(jid, parent.transportType, username, password, nickname);
        triggerRestart = true;
    }
    if (triggerRestart) {
        Log.debug("Clean up any leftover roster items " + "from other transports for: " + jid);
        try {
            parent.cleanUpRoster(jid, !noRosterItem);
        } catch (UserNotFoundException ee) {
            throw new UserNotFoundException("Unable to find roster.");
        }
    }
    if (!noRosterItem) {
        try {
            Log.debug("Adding Transport roster item to the roster of: " + jid);
            parent.addOrUpdateRosterItem(jid, parent.getJID(), parent.getDescription(), "Transports");
        } catch (UserNotFoundException e) {
            throw new UserNotFoundException("User not registered with server.");
        }
    } else {
        Log.debug("Not adding Transport roster item to the roster of: " + jid + " (as this was explicitly requested).");
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) TransportSession(net.sf.kraken.session.TransportSession)

Example 29 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class YahooSession method syncUsers.

/**
     * Syncs up the yahoo roster with the jabber roster.
     */
public void syncUsers() {
    // Run through the entire list of users and set up our sync group.
    for (Object userObj : yahooSession.getRoster().toArray()) {
        YahooUser user = (YahooUser) userObj;
        PseudoRosterItem rosterItem = pseudoRoster.getItem(user.getId());
        String nickname = null;
        if (rosterItem != null) {
            nickname = rosterItem.getNickname();
        }
        if (nickname == null) {
            nickname = user.getId();
        }
        getBuddyManager().storeBuddy(new YahooBuddy(this.getBuddyManager(), user, nickname, user.getGroupIds(), rosterItem));
    }
    // Lets try the actual sync.
    try {
        getTransport().syncLegacyRoster(getJID(), getBuddyManager().getBuddies());
    } catch (UserNotFoundException e) {
        Log.debug("Unable to sync yahoo contact list for " + getJID());
    }
    getBuddyManager().activate();
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) YahooUser(org.openymsg.network.YahooUser) PseudoRosterItem(net.sf.kraken.pseudoroster.PseudoRosterItem)

Example 30 with UserNotFoundException

use of org.jivesoftware.openfire.user.UserNotFoundException in project Openfire by igniterealtime.

the class Conversation method getMessages.

/**
	 * Returns the archived messages in the conversation. If message archiving is not enabled, this method will always return an empty collection.
	 * This method will only return messages that have already been batch-archived to the database; in other words, it does not provide a real-time
	 * view of new messages.
	 * 
	 * @return the archived messages in the conversation.
	 */
public List<ArchivedMessage> getMessages() {
    if (room == null && !conversationManager.isMessageArchivingEnabled()) {
        return Collections.emptyList();
    } else if (room != null && !conversationManager.isRoomArchivingEnabled()) {
        return Collections.emptyList();
    }
    List<ArchivedMessage> messages = new ArrayList<ArchivedMessage>();
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(LOAD_MESSAGES);
        pstmt.setLong(1, getConversationID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            JID fromJID = new JID(rs.getString(1));
            String fromJIDResource = rs.getString(2);
            if (fromJIDResource != null && !"".equals(fromJIDResource)) {
                fromJID = new JID(rs.getString(1) + "/" + fromJIDResource);
            }
            JID toJID = new JID(rs.getString(3));
            String toJIDResource = rs.getString(4);
            if (toJIDResource != null && !"".equals(toJIDResource)) {
                toJID = new JID(rs.getString(3) + "/" + toJIDResource);
            }
            Date date = new Date(rs.getLong(5));
            String body = DbConnectionManager.getLargeTextField(rs, 6);
            messages.add(new ArchivedMessage(conversationID, fromJID, toJID, date, body, false));
        }
    } catch (SQLException sqle) {
        Log.error(sqle.getMessage(), sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    // Add messages of users joining or leaving the group chat conversation
    if (room != null) {
        for (Map.Entry<String, UserParticipations> entry : participants.entrySet()) {
            JID user = new JID(entry.getKey());
            boolean anonymous = false;
            String name;
            try {
                name = UserNameManager.getUserName(user);
            } catch (UserNotFoundException e) {
                name = user.toBareJID();
                anonymous = true;
            }
            for (ConversationParticipation participation : entry.getValue().getParticipations()) {
                if (participation.getJoined() == null) {
                    Log.warn("Found muc participant with no join date in conversation: " + conversationID);
                    continue;
                }
                JID jid = new JID(room + "/" + participation.getNickname());
                String joinBody;
                String leftBody;
                if (anonymous) {
                    joinBody = LocaleUtils.getLocalizedString("muc.conversation.joined.anonymous", MonitoringConstants.NAME, Arrays.asList(participation.getNickname()));
                    leftBody = LocaleUtils.getLocalizedString("muc.conversation.left.anonymous", MonitoringConstants.NAME, Arrays.asList(participation.getNickname()));
                } else {
                    joinBody = LocaleUtils.getLocalizedString("muc.conversation.joined", MonitoringConstants.NAME, Arrays.asList(participation.getNickname(), name));
                    leftBody = LocaleUtils.getLocalizedString("muc.conversation.left", MonitoringConstants.NAME, Arrays.asList(participation.getNickname(), name));
                }
                messages.add(new ArchivedMessage(conversationID, user, jid, participation.getJoined(), joinBody, true));
                if (participation.getLeft() != null) {
                    messages.add(new ArchivedMessage(conversationID, user, jid, participation.getLeft(), leftBody, true));
                }
            }
        }
        // Sort messages by sent date
        Collections.sort(messages, new Comparator<ArchivedMessage>() {

            public int compare(ArchivedMessage o1, ArchivedMessage o2) {
                return o1.getSentDate().compareTo(o2.getSentDate());
            }
        });
    }
    return messages;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) ResultSet(java.sql.ResultSet) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)118 JID (org.xmpp.packet.JID)50 Element (org.dom4j.Element)28 Roster (org.jivesoftware.openfire.roster.Roster)27 RosterItem (org.jivesoftware.openfire.roster.RosterItem)26 User (org.jivesoftware.openfire.user.User)25 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)23 IQ (org.xmpp.packet.IQ)15 ArrayList (java.util.ArrayList)14 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)12 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)11 Group (org.jivesoftware.openfire.group.Group)10 UserManager (org.jivesoftware.openfire.user.UserManager)10 Workgroup (org.jivesoftware.xmpp.workgroup.Workgroup)10 Presence (org.xmpp.packet.Presence)10 NotFoundException (org.jivesoftware.util.NotFoundException)9 SQLException (java.sql.SQLException)8 List (java.util.List)8 IOException (java.io.IOException)7 Connection (java.sql.Connection)7