Search in sources :

Example 56 with UserNotFoundException

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

the class JustMarriedPlugin method changeName.

public static boolean changeName(String currentUserName, String newUserName, boolean deleteOldUser, String newEmail, String newRealName) {
    UserManager userManager = UserManager.getInstance();
    try {
        User currentUser = userManager.getUser(currentUserName);
        // Old user found, create new one
        String password = AuthFactory.getPassword(currentUserName);
        String newName = (newRealName == null || newRealName.length() == 0) ? currentUser.getName() : newRealName;
        String newMail = (newEmail == null || newEmail.length() == 0) ? currentUser.getEmail() : newEmail;
        User newUser = userManager.createUser(newUserName, password, currentUser.getName(), newMail);
        newUser.setName(newName);
        newUser.setNameVisible(currentUser.isNameVisible());
        newUser.setEmailVisible(currentUser.isEmailVisible());
        newUser.setCreationDate(currentUser.getCreationDate());
        copyRoster(currentUser, newUser, currentUserName);
        copyProperties(currentUser, newUser);
        copyToGroups(currentUserName, newUserName);
        copyVCard(currentUserName, newUserName);
        if (deleteOldUser) {
            deleteUser(currentUser);
        }
    } catch (UserNotFoundException e) {
        Log.error("Could not find user " + currentUserName, e);
        return false;
    } catch (UserAlreadyExistsException e) {
        Log.error("Could not create user " + newUserName, e);
        return false;
    }
    return true;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) UserManager(org.jivesoftware.openfire.user.UserManager) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException)

Example 57 with UserNotFoundException

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

the class BaseTransport method notifyRosterOffline.

/**
     * Sends offline packets for an entire roster to the target user.
     *
     * This function will run through the roster of the specified user and send offline
     * presence packets for each roster item.   This is typically used when a user logs
     * off so that all of the associated roster items appear offline.  This does not send
     * the unavailable presence for the transport itself.
     *
     * @param jid JID of user whose roster we want to clean up.
     * @throws UserNotFoundException if the user is not found.
     * @deprecated Use net.sf.kraken.roster.TransportBuddyManager#sendOfflineForAllAvailablePresences(JID)
     */
@Deprecated
public void notifyRosterOffline(JID jid) throws UserNotFoundException {
    try {
        Roster roster = rosterManager.getRoster(jid.getNode());
        for (RosterItem ri : roster.getRosterItems()) {
            if (ri.getJid().getNode() != null && ri.getJid().getDomain().equals(this.jid.getDomain())) {
                Presence p = new Presence(Presence.Type.unavailable);
                p.setTo(jid);
                p.setFrom(ri.getJid());
                sendPacket(p);
            }
        }
    } catch (UserNotFoundException e) {
        throw new UserNotFoundException("Unable to find roster.");
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Roster(org.jivesoftware.openfire.roster.Roster)

Example 58 with UserNotFoundException

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

the class JustMarriedController method changeName.

/**
	 * Change name.
	 *
	 * @param currentUserName
	 *            the current user name
	 * @param newUserName
	 *            the new user name
	 * @param deleteOldUser
	 *            the delete old user
	 * @param newEmail
	 *            the new email
	 * @param newRealName
	 *            the new real name
	 * @return true, if successful
	 * @throws ServiceException
	 *             the service exception
	 */
public static boolean changeName(String currentUserName, String newUserName, boolean deleteOldUser, String newEmail, String newRealName) throws ServiceException {
    UserManager userManager = UserManager.getInstance();
    try {
        User currentUser = userManager.getUser(currentUserName);
        // Old user found, create new one
        String password = AuthFactory.getPassword(currentUserName);
        String newName = (newRealName == null || newRealName.length() == 0) ? currentUser.getName() : newRealName;
        String newMail = (newEmail == null || newEmail.length() == 0) ? currentUser.getEmail() : newEmail;
        User newUser = userManager.createUser(newUserName, password, currentUser.getName(), newMail);
        newUser.setName(newName);
        newUser.setNameVisible(currentUser.isNameVisible());
        newUser.setEmailVisible(currentUser.isEmailVisible());
        newUser.setCreationDate(currentUser.getCreationDate());
        copyRoster(currentUser, newUser, currentUserName);
        copyProperties(currentUser, newUser);
        copyToGroups(currentUserName, newUserName);
        copyVCard(currentUserName, newUserName);
        if (deleteOldUser) {
            deleteUser(currentUser);
        }
    } catch (UserNotFoundException e) {
        throw new ServiceException("Could not find user", currentUserName, ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
    } catch (UserAlreadyExistsException e) {
        throw new ServiceException("Could not create new user", newUserName, ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
    }
    return true;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserManager(org.jivesoftware.openfire.user.UserManager) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException)

Example 59 with UserNotFoundException

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

the class JustMarriedController method addNewUserToOthersRoster.

/**
	 * Adds the new user to others roster.
	 *
	 * @param newUser
	 *            the new user
	 * @param otherItem
	 *            the other item
	 * @param currentUser
	 *            the current user
	 * @throws ServiceException
	 *             the service exception
	 */
private static void addNewUserToOthersRoster(User newUser, RosterItem otherItem, String currentUser) throws ServiceException {
    otherItem.getJid();
    UserManager userManager = UserManager.getInstance();
    // Is this user registered with our OF server?
    String username = otherItem.getJid().getNode();
    if (username != null && username.length() > 0 && userManager.isRegisteredUser(username) && XMPPServer.getInstance().isLocal(XMPPServer.getInstance().createJID(currentUser, null))) {
        try {
            User otherUser = userManager.getUser(username);
            Roster otherRoster = otherUser.getRoster();
            RosterItem oldUserOnOthersRoster = otherRoster.getRosterItem(XMPPServer.getInstance().createJID(currentUser, null));
            try {
                if (!oldUserOnOthersRoster.isOnlyShared()) {
                    RosterItem justCreated = otherRoster.createRosterItem(XMPPServer.getInstance().createJID(newUser.getUsername(), null), oldUserOnOthersRoster.getNickname(), oldUserOnOthersRoster.getGroups(), true, true);
                    justCreated.setAskStatus(oldUserOnOthersRoster.getAskStatus());
                    justCreated.setRecvStatus(oldUserOnOthersRoster.getRecvStatus());
                    justCreated.setSubStatus(oldUserOnOthersRoster.getSubStatus());
                    otherRoster.updateRosterItem(justCreated);
                }
            } catch (UserAlreadyExistsException e) {
                throw new ServiceException("Could not create roster item for user ", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
            } catch (SharedGroupException e) {
                throw new ServiceException("Could not create roster item, because it is a contact from a shared group", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.BAD_REQUEST, e);
            }
        } catch (UserNotFoundException e) {
            throw new ServiceException("Could not create roster item for user " + newUser.getUsername() + "  because it is a contact from a shared group.", newUser.getUsername(), ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) User(org.jivesoftware.openfire.user.User) Roster(org.jivesoftware.openfire.roster.Roster) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserManager(org.jivesoftware.openfire.user.UserManager) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

Example 60 with UserNotFoundException

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

the class JustMarriedController method copyRoster.

/**
	 * Copy roster.
	 *
	 * @param currentUser
	 *            the current user
	 * @param newUser
	 *            the new user
	 * @param currentUserName
	 *            the current user name
	 * @throws ServiceException
	 *             the service exception
	 */
private static void copyRoster(User currentUser, User newUser, String currentUserName) throws ServiceException {
    Roster newRoster = newUser.getRoster();
    Roster currentRoster = currentUser.getRoster();
    for (RosterItem item : currentRoster.getRosterItems()) {
        try {
            List<String> groups = item.getGroups();
            RosterItem justCreated = newRoster.createRosterItem(item.getJid(), item.getNickname(), groups, true, true);
            justCreated.setAskStatus(item.getAskStatus());
            justCreated.setRecvStatus(item.getRecvStatus());
            justCreated.setSubStatus(item.getSubStatus());
            for (Group gr : item.getSharedGroups()) {
                justCreated.addSharedGroup(gr);
            }
            for (Group gr : item.getInvisibleSharedGroups()) {
                justCreated.addInvisibleSharedGroup(gr);
            }
            newRoster.updateRosterItem(justCreated);
            addNewUserToOthersRoster(newUser, item, currentUserName);
        } catch (UserAlreadyExistsException e) {
            throw new ServiceException("Could not create roster item for user ", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
        } catch (SharedGroupException e) {
            throw new ServiceException("Could not create roster item, because it is a contact from a shared group", newUser.getUsername(), ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.BAD_REQUEST, e);
        } catch (UserNotFoundException e) {
            throw new ServiceException("Could not update roster item for user " + newUser.getUsername() + " because it was not properly created.", newUser.getUsername(), ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) RosterItem(org.jivesoftware.openfire.roster.RosterItem) Group(org.jivesoftware.openfire.group.Group) Roster(org.jivesoftware.openfire.roster.Roster) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) SharedGroupException(org.jivesoftware.openfire.SharedGroupException)

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