Search in sources :

Example 31 with UserNotFoundException

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

the class BookmarkInterceptor method addBookmarkElement.

/**
     * Adds a Bookmark to the users defined list of bookmarks.
     *
     * @param jid      the users jid.
     * @param bookmark the bookmark to be added.
     * @param element  the storage element to append to.
     */
private void addBookmarkElement(JID jid, Bookmark bookmark, Element element) {
    final UserManager userManager = UserManager.getInstance();
    try {
        userManager.getUser(jid.getNode());
    } catch (UserNotFoundException e) {
        return;
    }
    // do not add duplicate bookmarks.
    if (bookmark.getType() == Bookmark.Type.url) {
        Element urlBookmarkElement = urlExists(element, bookmark.getValue());
        if (urlBookmarkElement == null) {
            urlBookmarkElement = element.addElement("url");
            urlBookmarkElement.addAttribute("name", bookmark.getName());
            urlBookmarkElement.addAttribute("url", bookmark.getValue());
            // Add an RSS attribute to the bookmark if it's defined. RSS isn't an
            // official part of the Bookmark JEP, but we define it as a logical
            // extension.
            boolean rss = Boolean.valueOf(bookmark.getProperty("rss"));
            if (rss) {
                urlBookmarkElement.addAttribute("rss", Boolean.toString(rss));
            }
        }
        appendSharedElement(urlBookmarkElement);
    } else // Otherwise it's a conference bookmark.
    {
        try {
            Element conferenceElement = conferenceExists(element, bookmark.getValue());
            // reply.
            if (conferenceElement == null) {
                conferenceElement = element.addElement("conference");
                conferenceElement.addAttribute("name", bookmark.getName());
                boolean autojoin = Boolean.valueOf(bookmark.getProperty("autojoin"));
                conferenceElement.addAttribute("autojoin", Boolean.toString(autojoin));
                conferenceElement.addAttribute("jid", bookmark.getValue());
                boolean nameasnick = Boolean.valueOf(bookmark.getProperty("nameasnick"));
                if (nameasnick) {
                    User currentUser = userManager.getUser(jid.getNode());
                    Element nick = conferenceElement.addElement("nick");
                    nick.addText(currentUser.getName());
                }
            }
            appendSharedElement(conferenceElement);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) UserManager(org.jivesoftware.openfire.user.UserManager) Element(org.dom4j.Element) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 32 with UserNotFoundException

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

the class ImageServlet method getImage.

/**
     * Returns the image bytes of the encoded image.
     *
     * @param imageName the name of the image.
     * @param workgroupName the name of the workgroup.
     * @return the image bytes found, otherwise null.
     */
public byte[] getImage(String imageName, String workgroupName) {
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    JID workgroupJID = new JID(workgroupName);
    Workgroup workgroup;
    try {
        workgroup = workgroupManager.getWorkgroup(workgroupJID);
    } catch (UserNotFoundException e) {
        Log.error(e.getMessage(), e);
        return null;
    }
    ChatSettings chatSettings = chatSettingsManager.getChatSettings(workgroup);
    ChatSetting setting = chatSettings.getChatSetting(imageName);
    String encodedValue = setting.getValue();
    if (encodedValue == null) {
        return null;
    }
    return StringUtils.decodeBase64(encodedValue);
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) ChatSettings(org.jivesoftware.openfire.fastpath.settings.chat.ChatSettings) JID(org.xmpp.packet.JID) ChatSetting(org.jivesoftware.openfire.fastpath.settings.chat.ChatSetting) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager)

Example 33 with UserNotFoundException

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

the class DeleteWorkgroup method execute.

@Override
public void execute(SessionData data, Element command) {
    Element note = command.addElement("note");
    // Get requested group
    WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
    // Load the workgroup
    try {
        Workgroup workgroup = workgroupManager.getWorkgroup(new JID(data.getData().get("workgroup").get(0)));
        workgroupManager.deleteWorkgroup(workgroup);
    } catch (UserNotFoundException e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Workgroup not found");
        return;
    } catch (Exception e) {
        // Group not found
        note.addAttribute("type", "error");
        note.setText("Error executing the command");
        return;
    }
    note.addAttribute("type", "info");
    note.setText("Operation finished successfully");
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) Workgroup(org.jivesoftware.xmpp.workgroup.Workgroup) WorkgroupManager(org.jivesoftware.xmpp.workgroup.WorkgroupManager) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 34 with UserNotFoundException

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

the class DefaultAuthProvider method getUserInfo.

private UserInfo getUserInfo(String username, boolean recurse) throws UnsupportedOperationException, UserNotFoundException {
    if (!isScramSupported()) {
        // Reject the operation since the provider  does not support SCRAM
        throw new UnsupportedOperationException();
    }
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(TEST_PASSWORD);
        pstmt.setString(1, username);
        rs = pstmt.executeQuery();
        if (!rs.next()) {
            throw new UserNotFoundException(username);
        }
        UserInfo userInfo = new UserInfo();
        userInfo.plainText = rs.getString(1);
        userInfo.encrypted = rs.getString(2);
        userInfo.iterations = rs.getInt(3);
        userInfo.salt = rs.getString(4);
        userInfo.storedKey = rs.getString(5);
        userInfo.serverKey = rs.getString(6);
        if (userInfo.encrypted != null) {
            try {
                userInfo.plainText = AuthFactory.decryptPassword(userInfo.encrypted);
            } catch (UnsupportedOperationException uoe) {
            // Ignore and return plain password instead.
            }
        }
        if (!recurse) {
            if (userInfo.plainText != null) {
                boolean scramOnly = JiveGlobals.getBooleanProperty("user.scramHashedPasswordOnly");
                if (scramOnly || userInfo.salt == null) {
                    // If we have a password here, but we're meant to be scramOnly, we should reset it.
                    setPassword(username, userInfo.plainText);
                    // RECURSE
                    return getUserInfo(username, true);
                }
            }
        }
        // Good to go.
        return userInfo;
    } catch (SQLException sqle) {
        Log.error("User SQL failure:", sqle);
        throw new UserNotFoundException(sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 35 with UserNotFoundException

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

the class JDBCAuthProvider method setPasswordValue.

private void setPasswordValue(String username, String password) throws UserNotFoundException {
    Connection con = null;
    PreparedStatement pstmt = null;
    if (username.contains("@")) {
        // Check that the specified domain matches the server's domain
        int index = username.indexOf("@");
        String domain = username.substring(index + 1);
        if (domain.equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
            username = username.substring(0, index);
        } else {
            // Unknown domain.
            throw new UserNotFoundException();
        }
    }
    try {
        con = getConnection();
        pstmt = con.prepareStatement(setPasswordSQL);
        pstmt.setString(2, username);
        password = hashPassword(password);
        pstmt.setString(1, password);
        pstmt.executeQuery();
    } catch (SQLException e) {
        Log.error("Exception in JDBCAuthProvider", e);
        throw new UserNotFoundException();
    } finally {
        DbConnectionManager.closeConnection(pstmt, con);
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

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