Search in sources :

Example 51 with UserNotFoundException

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

the class ChatSettingsCreator method createBotSettings.

/**
     * Adds the default bot settings to the database.
     *
     * @param workgroupJID - the JID of the workgroup to setup.
     */
private void createBotSettings(JID workgroupJID) {
    try {
        // Enable the workgroup chatbot by default
        Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(workgroupJID);
        workgroup.chatbotEnabled(true);
        for (KeyEnum key : botMap.keySet()) {
            String value = botMap.get(key);
            createChatSetting(workgroupJID, key, ChatSettings.SettingType.bot_settings, value);
        }
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
    } catch (UnauthorizedException e) {
        Log.error(e.getMessage(), e);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UnauthorizedException(org.jivesoftware.xmpp.workgroup.UnauthorizedException) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup)

Example 52 with UserNotFoundException

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

the class BaseTransport method start.

/**
     * Handles startup of the transport.
     */
public void start() {
    RosterEventDispatcher.addListener(this);
    UserEventDispatcher.addListener(this);
    SessionEventDispatcher.addListener(this);
    VCardEventDispatcher.addListener(this);
    InterceptorManager.getInstance().addInterceptor(this);
    if (!JiveGlobals.getBooleanProperty("plugin.gateway.tweak.noprobeonstart", false)) {
        // TODO: Do we need to account for local vs other node sessions?
        for (ClientSession session : SessionManager.getInstance().getSessions()) {
            try {
                JID jid = XMPPServer.getInstance().createJID(session.getUsername(), null);
                if (RegistrationManager.getInstance().isRegistered(jid, getType())) {
                    Presence p = new Presence(Presence.Type.probe);
                    p.setFrom(this.getJID());
                    p.setTo(jid);
                    sendPacket(p);
                }
            } catch (UserNotFoundException e) {
            // Not a valid user for the gateway then
            }
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Example 53 with UserNotFoundException

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

the class BaseTransport method syncLegacyRoster.

/**
     * Sync a user's roster with their legacy contact list.
     *
     * Given a collection of transport buddies, syncs up the user's
     * roster by fixing any nicknames, group assignments, adding and removing
     * roster items, and generally trying to make the jabber roster list
     * assigned to the transport's JID look at much like the legacy buddy
     * list as possible.  This is a very extensive operation.  You do not
     * want to do this very often.  Typically once right after the person
     * has logged into the legacy service.
     *
     * @param userjid JID of user who's roster we are syncing with.
     * @param legacyitems List of TransportBuddy's to be synced.
     * @throws UserNotFoundException if userjid not found.
     */
public void syncLegacyRoster(JID userjid, Collection<B> legacyitems) throws UserNotFoundException {
    Log.debug("Syncing Legacy Roster: " + legacyitems);
    try {
        Roster roster = rosterManager.getRoster(userjid.getNode());
        // Lets lock down the roster from update notifications if there's an active session.
        try {
            TransportSession<B> session = sessionManager.getSession(userjid.getNode());
            session.lockRoster();
        } catch (NotFoundException e) {
        // No active session?  Then no problem.
        }
        // First thing first, we want to build ourselves an easy mapping.
        Map<JID, TransportBuddy> legacymap = new HashMap<JID, TransportBuddy>();
        for (TransportBuddy buddy : legacyitems) {
            //                Log.debug("ROSTERSYNC: Mapping "+buddy.getName());
            legacymap.put(buddy.getJID(), buddy);
        }
        // Now, lets go through the roster and see what matches up.
        for (RosterItem ri : roster.getRosterItems()) {
            if (!ri.getJid().getDomain().equals(this.jid.getDomain())) {
                // Not our contact to care about.
                continue;
            }
            if (ri.getJid().getNode() == null) {
                // This is a transport instance, lets leave it alone.
                continue;
            }
            JID jid = new JID(ri.getJid().toBareJID());
            if (legacymap.containsKey(jid)) {
                Log.debug("ROSTERSYNC: We found, updating " + jid.toString());
                // Ok, matched a legacy to jabber roster item
                // Lets update if there are differences
                TransportBuddy buddy = legacymap.get(jid);
                try {
                    if (buddy.getAskType() != null && buddy.getSubType() != null) {
                        this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroups(), buddy.getSubType(), buddy.getAskType());
                    } else {
                        this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroups());
                    }
                } catch (UserNotFoundException e) {
                    Log.debug("Failed updating roster item", e);
                }
                legacymap.remove(jid);
            } else {
                Log.debug("ROSTERSYNC: We did not find, removing " + jid.toString());
                // This person is apparantly no longer in the legacy roster.
                try {
                    this.removeFromRoster(userjid, jid);
                } catch (UserNotFoundException e) {
                    Log.debug("Failed removing roster item", e);
                }
            }
        }
        // Ok, we should now have only new items from the legacy roster
        for (TransportBuddy buddy : legacymap.values()) {
            Log.debug("ROSTERSYNC: We have new, adding " + buddy.getName());
            try {
                this.addOrUpdateRosterItem(userjid, buddy.getName(), buddy.getNickname(), buddy.getGroups());
            } catch (UserNotFoundException e) {
                Log.debug("Failed adding new roster item", e);
            }
        }
        // All done, lets unlock the roster.
        try {
            TransportSession<B> session = sessionManager.getSession(userjid.getNode());
            session.unlockRoster();
        } catch (NotFoundException e) {
        // No active session?  Then no problem.
        }
    } catch (UserNotFoundException e) {
        throw new UserNotFoundException("Could not find roster for " + userjid.toString());
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Roster(org.jivesoftware.openfire.roster.Roster) TransportBuddy(net.sf.kraken.roster.TransportBuddy) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 54 with UserNotFoundException

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

the class OpenfireLoginService method login.

public UserIdentity login(String userName, Object credential) {
    UserIdentity identity = null;
    if (identities.containsKey(userName)) {
        identity = identities.get(userName);
        if (authTokens.containsKey(userName) == false) {
            Log.debug("UserIdentity login " + userName + " ");
            try {
                if (AdminManager.getInstance().isUserAdmin(userName, true)) {
                    AuthToken authToken = AuthFactory.authenticate(userName, (String) credential);
                    authTokens.put(userName, authToken);
                } else {
                    Log.error("access denied, not admin user " + userName);
                    return null;
                }
            } catch (UnauthorizedException e) {
                Log.error("access denied, bad password " + userName);
                return null;
            } catch (Exception e) {
                Log.error("access denied " + userName);
                return null;
            }
        }
    } else {
        Log.debug("UserIdentity login " + userName + " ");
        try {
            userManager.getUser(userName);
        } catch (UserNotFoundException e) {
            //Log.error( "user not found " + userName, e );
            return null;
        }
        try {
            if (AdminManager.getInstance().isUserAdmin(userName, true)) {
                AuthToken authToken = AuthFactory.authenticate(userName, (String) credential);
                authTokens.put(userName, authToken);
            } else {
                Log.error("access denied, not admin user " + userName);
                return null;
            }
        } catch (UnauthorizedException e) {
            Log.error("access denied, bad password " + userName);
            return null;
        } catch (Exception e) {
            Log.error("access denied " + userName);
            return null;
        }
        Principal userPrincipal = new KnownUser(userName, credential);
        Subject subject = new Subject();
        subject.getPrincipals().add(userPrincipal);
        subject.getPrivateCredentials().add(credential);
        subject.getPrincipals().add(new RolePrincipal("jmxweb"));
        subject.setReadOnly();
        identity = _identityService.newUserIdentity(subject, userPrincipal, new String[] { "jmxweb" });
        identities.put(userName, identity);
    }
    return identity;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) UserIdentity(org.eclipse.jetty.server.UserIdentity) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) AuthToken(org.jivesoftware.openfire.auth.AuthToken) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException) IOException(java.io.IOException) UnauthorizedException(org.jivesoftware.openfire.auth.UnauthorizedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) Principal(java.security.Principal) Subject(javax.security.auth.Subject)

Example 55 with UserNotFoundException

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

the class JustMarriedPlugin method addNewUserToOthersRoster.

private static void addNewUserToOthersRoster(User newUser, RosterItem otherItem, String currentUser) {
    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) {
                Log.error("Could not create roster item for user " + newUser.getUsername(), e);
            } catch (SharedGroupException e) {
                Log.error(e);
            }
        } catch (UserNotFoundException e) {
            Log.error("Could not create roster item for user " + newUser.getUsername() + " because it is a contact from a shared group", 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) UserManager(org.jivesoftware.openfire.user.UserManager) 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