/* (non-Javadoc) * @see org.jivesoftware.openfire.roster.RosterItemProvider#getUsernames(java.lang.String) */ public Iterator<String> getUsernames(String jid) { List<String> answer = new ArrayList<String>(); Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(LOAD_USERNAMES); pstmt.setString(1, jid); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { answer.add(rs.getString(1)); } } catch (SQLException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } try { if (con != null) { con.close(); } } catch (Exception e) { Log.error(e); } } return answer.iterator(); }
public void deleteVCard(String username) { Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(DELETE_PROPERTIES); pstmt.setString(1, username); pstmt.executeUpdate(); } catch (SQLException e) { Log.error(e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } try { if (con != null) { con.close(); } } catch (Exception e) { Log.error(e); } } }
void checkHealth() { // Check that the sending operation is still active if (writeStarted > -1 && System.currentTimeMillis() - writeStarted > JiveGlobals.getIntProperty("xmpp.session.sending-limit", 60000)) { // Close the socket if (Log.isDebugEnabled()) { Log.debug( "Closing connection: " + this + " that started sending data at: " + new Date(writeStarted)); } forceClose(); } else { // Check if the connection has been idle. A connection is considered idle if the client // has not been receiving data for a period. Sending data to the client is not // considered as activity. if (idleTimeout > -1 && socketReader != null && System.currentTimeMillis() - socketReader.getLastActive() > idleTimeout) { // Close the socket if (Log.isDebugEnabled()) { Log.debug("Closing connection that has been idle: " + this); } forceClose(); } } }
public void updateVCard(String username, Element vCardElement) throws NotFoundException { if (loadVCard(username) == null) { // The user already has a vCard throw new NotFoundException("Username " + username + " does not have a vCard"); } Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(UPDATE_PROPERTIES); pstmt.setString(1, vCardElement.asXML()); pstmt.setString(2, username); pstmt.executeUpdate(); } catch (SQLException e) { Log.error(e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } try { if (con != null) { con.close(); } } catch (Exception e) { Log.error(e); } } }
/* * (non-Javadoc) * * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent) */ @Override protected void append(LoggingEvent event) { final Level l = event.getLevel(); final String message = (event.getMessage() != null ? event.getMessage().toString() : ""); Throwable throwable = null; if (event.getThrowableInformation() != null) { throwable = event.getThrowableInformation().getThrowable(); } switch (l.toInt()) { case Priority.OFF_INT: // Logging turned off - do nothing. break; case Priority.FATAL_INT: case Priority.ERROR_INT: Log.error(message, throwable); break; case Priority.WARN_INT: Log.warn(message, throwable); break; case Priority.INFO_INT: Log.info(message, throwable); break; default: // DEBUG and below (trace, all) Log.debug(message, throwable); break; } }
public void createVCard(String username, Element vCardElement) throws AlreadyExistsException { if (loadVCard(username) != null) { // The user already has a vCard throw new AlreadyExistsException("Username " + username + " already has a vCard"); } Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(INSERT_PROPERTY); pstmt.setString(1, username); pstmt.setString(2, vCardElement.asXML()); pstmt.executeUpdate(); } catch (SQLException e) { Log.error(e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } try { if (con != null) { con.close(); } } catch (Exception e) { Log.error(e); } } }
/** * Insert the groups into the given roster item. * * @param rosterID The roster ID of the item the groups belong to * @param iter An iterator over the group names to insert */ private void insertGroups(long rosterID, Iterator<String> iter, Connection con) throws SQLException { PreparedStatement pstmt = null; try { pstmt = con.prepareStatement(CREATE_ROSTER_ITEM_GROUPS); pstmt.setLong(1, rosterID); for (int i = 0; iter.hasNext(); i++) { pstmt.setInt(2, i); pstmt.setString(3, iter.next()); try { pstmt.executeUpdate(); } catch (SQLException e) { Log.error(e); } } } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } } }
/* (non-Javadoc) * @see org.jivesoftware.openfire.roster.RosterItemProvider#getItemCount(java.lang.String) */ public int getItemCount(String username) { int count = 0; Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(COUNT_ROSTER_ITEMS); pstmt.setString(1, username); ResultSet rs = pstmt.executeQuery(); if (rs.next()) { count = rs.getInt(1); } } catch (SQLException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } try { if (con != null) { con.close(); } } catch (Exception e) { Log.error(e); } } return count; }
private static Collection<ExternalComponentConfiguration> getConfigurations( Permission permission) { Collection<ExternalComponentConfiguration> answer = new ArrayList<ExternalComponentConfiguration>(); java.sql.Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(LOAD_CONFIGURATIONS); pstmt.setString(1, permission.toString()); ResultSet rs = pstmt.executeQuery(); ExternalComponentConfiguration configuration; while (rs.next()) { configuration = new ExternalComponentConfiguration(rs.getString(1)); configuration.setSecret(rs.getString(2)); configuration.setPermission(permission); answer.add(configuration); } rs.close(); } catch (SQLException sqle) { Log.error(sqle); } finally { try { if (pstmt != null) pstmt.close(); } catch (Exception e) { Log.error(e); } try { if (con != null) con.close(); } catch (Exception e) { Log.error(e); } } return answer; }
/** * Returns a media proxy session with the specified ID. * * @param sid the session ID. * @return the session or <tt>null</tt> if the session doesn't exist. */ public MediaProxySession getSession(String sid) { MediaProxySession proxySession = sessions.get(sid); if (proxySession != null) { if (Log.isDebugEnabled()) { Log.debug("MediaProxy: SID: " + sid + " agentSID: " + proxySession.getSID()); return proxySession; } } return null; }
public void run() { try { Log.debug("Trying to configure Clearspace."); doConfigClearspace(); updateClearspaceClientSettings(); } catch (UnauthorizedException e) { Log.warn( "Unauthorization problem trying to configure Clearspace, trying again in 1 minute", e); // TODO: Mark that there is an authorization problem } catch (Exception e) { Log.warn("Unknown problem trying to configure Clearspace, trying again in 1 minute", e); } }
private synchronized void doConfigClearspace() throws UnauthorizedException { Log.debug("Starting Clearspace configuration."); List<String> bindInterfaces = getServerInterfaces(); if (bindInterfaces.size() == 0) { // We aren't up and running enough to tell Clearspace what interfaces to bind to. Log.debug("No bind interfaces found to config Clearspace"); throw new IllegalStateException("There are no binding interfaces."); } try { XMPPServerInfo serverInfo = XMPPServer.getInstance().getServerInfo(); String path = IM_URL_PREFIX + "configureComponent/"; // Creates the XML with the data Document groupDoc = DocumentHelper.createDocument(); Element rootE = groupDoc.addElement("configureComponent"); Element domainE = rootE.addElement("domain"); domainE.setText(serverInfo.getXMPPDomain()); for (String bindInterface : bindInterfaces) { Element hostsE = rootE.addElement("hosts"); hostsE.setText(bindInterface); } Element portE = rootE.addElement("port"); portE.setText(String.valueOf(ExternalComponentManager.getServicePort())); Log.debug( "Trying to configure Clearspace with: Domain: " + serverInfo.getXMPPDomain() + ", hosts: " + bindInterfaces.toString() + ", port: " + port); executeRequest(POST, path, rootE.asXML()); // Done, Clearspace was configured correctly, clear the task Log.debug("Clearspace was configured, stopping the task."); TaskEngine.getInstance().cancelScheduledTask(configClearspaceTask); configClearspaceTask = null; } catch (UnauthorizedException ue) { throw ue; } catch (Exception e) { // It is not supported exception, wrap it into an UnsupportedOperationException throw new UnsupportedOperationException("Unexpected error", e); } }
/** * Returns the configuration for an external component. * * @param subdomain the subdomain of the external component. * @return the configuration for an external component. */ public static ExternalComponentConfiguration getConfiguration(String subdomain) { ExternalComponentConfiguration configuration = null; java.sql.Connection con = null; PreparedStatement pstmt = null; try { con = DbConnectionManager.getConnection(); pstmt = con.prepareStatement(LOAD_CONFIGURATION); pstmt.setString(1, subdomain); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { configuration = new ExternalComponentConfiguration(subdomain); configuration.setSecret(rs.getString(1)); configuration.setPermission(Permission.valueOf(rs.getString(2))); } rs.close(); } catch (SQLException sqle) { Log.error(sqle); } finally { try { if (pstmt != null) pstmt.close(); } catch (Exception e) { Log.error(e); } try { if (con != null) con.close(); } catch (Exception e) { Log.error(e); } } return configuration; }
private synchronized void startClearspaceConfig() { // If the task is running, stop it if (configClearspaceTask != null) { configClearspaceTask.cancel(); Log.debug("Stopping previous configuration Clearspace task."); } // Create and schedule a confi task every minute configClearspaceTask = new ConfigClearspaceTask(); // Wait some time to start the task until Openfire has binding address TaskEngine.getInstance() .schedule(configClearspaceTask, JiveConstants.SECOND * 30, JiveConstants.MINUTE); Log.debug("Starting configuration Clearspace task in 10 seconds."); }
public void authenticate(String username, String password) throws UnauthorizedException { 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. Return authentication failed. throw new UnauthorizedException(); } } try { // Some native authentication mechanisms appear to not handle high load // very well. Therefore, synchronize access to Shaj to throttle auth checks. synchronized (this) { if (!Shaj.checkPassword(domain, username, password)) { throw new UnauthorizedException(); } } } catch (UnauthorizedException ue) { throw ue; } catch (Exception e) { throw new UnauthorizedException(e); } // See if the user exists in the database. If not, automatically create them. UserManager userManager = UserManager.getInstance(); try { userManager.getUser(username); } catch (UserNotFoundException unfe) { try { Log.debug("Automatically creating new user account for " + username); // Create user; use a random password for better safety in the future. // Note that we have to go to the user provider directly -- because the // provider is read-only, UserManager will usually deny access to createUser. UserProvider provider = UserManager.getUserProvider(); if (!(provider instanceof NativeUserProvider)) { Log.error( "Error: not using NativeUserProvider so authentication with " + "NativeAuthProvider will likely fail. Using: " + provider.getClass().getName()); } UserManager.getUserProvider().createUser(username, StringUtils.randomString(8), null, null); } catch (UserAlreadyExistsException uaee) { // Ignore. } } }
public void deliver(Packet packet) throws UnauthorizedException, PacketException { if (isClosed()) { deliverer.deliver(packet); } else { try { // Invoke the interceptors before we send the packet InterceptorManager.getInstance().invokeInterceptors(packet, session, false, false); boolean errorDelivering = false; synchronized (writer) { try { xmlSerializer.write(packet.getElement()); if (flashClient) { writer.write('\0'); } xmlSerializer.flush(); } catch (IOException e) { Log.debug("Error delivering packet" + "\n" + this.toString(), e); errorDelivering = true; } } if (errorDelivering) { close(); // Retry sending the packet again. Most probably if the packet is a // Message it will be stored offline deliverer.deliver(packet); } else { // Invoke the interceptors after we have sent the packet InterceptorManager.getInstance().invokeInterceptors(packet, session, false, true); session.incrementServerPacketCount(); } } catch (PacketRejectedException e) { // An interceptor rejected the packet so do nothing } } }
static { String algorithm = JiveGlobals.getProperty("xmpp.socket.ssl.algorithm", "TLS"); String storeType = JiveGlobals.getProperty("xmpp.socket.ssl.storeType", "jks"); // Get the keystore location. The default location is security/keystore keyStoreLocation = JiveGlobals.getProperty( "xmpp.socket.ssl.keystore", "resources" + File.separator + "security" + File.separator + "keystore"); keyStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + keyStoreLocation; // Get the keystore password. The default password is "changeit". keypass = JiveGlobals.getProperty("xmpp.socket.ssl.keypass", "changeit"); keypass = keypass.trim(); // Get the truststore location; default at security/truststore trustStoreLocation = JiveGlobals.getProperty( "xmpp.socket.ssl.truststore", "resources" + File.separator + "security" + File.separator + "truststore"); trustStoreLocation = JiveGlobals.getHomeDirectory() + File.separator + trustStoreLocation; // Get the truststore passwprd; default is "changeit". trustpass = JiveGlobals.getProperty("xmpp.socket.ssl.trustpass", "changeit"); trustpass = trustpass.trim(); try { keyStore = KeyStore.getInstance(storeType); keyStore.load(new FileInputStream(keyStoreLocation), keypass.toCharArray()); trustStore = KeyStore.getInstance(storeType); trustStore.load(new FileInputStream(trustStoreLocation), trustpass.toCharArray()); sslFactory = (SSLJiveServerSocketFactory) SSLJiveServerSocketFactory.getInstance(algorithm, keyStore, trustStore); } catch (Exception e) { Log.error( "SSLConfig startup problem.\n" + " storeType: [" + storeType + "]\n" + " keyStoreLocation: [" + keyStoreLocation + "]\n" + " keypass: [" + keypass + "]\n" + " trustStoreLocation: [" + trustStoreLocation + "]\n" + " trustpass: [" + trustpass + "]", e); keyStore = null; trustStore = null; sslFactory = null; } }
/** * Retrieves the last n conversations from the system that were created after the given * conversationID. * * @param count the count of conversations to return. * @param mostRecentConversationID the last conversationID that has been retrieved. * @return a List of Map objects. */ public List<Map<String, Long>> getNLatestConversations(int count, long mostRecentConversationID) { // TODO Fix plugin name 2 lines below and missing classes List<Map<String, Long>> cons = new ArrayList<Map<String, Long>>(); MonitoringPlugin plugin = (MonitoringPlugin) XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME); ConversationManager conversationManager = (ConversationManager) plugin.getModule(ConversationManager.class); Collection<Conversation> conversations = conversationManager.getConversations(); List<Conversation> lConversations = Arrays.asList(conversations.toArray(new Conversation[conversations.size()])); Collections.sort(lConversations, conversationComparator); int counter = 0; for (Iterator<Conversation> i = lConversations.iterator(); i.hasNext() && counter < count; ) { Conversation con = i.next(); if (mostRecentConversationID == con.getConversationID()) { break; } else { Map mCon = new HashMap(); mCon.put("conversationid", con.getConversationID()); String users[]; int usersIdx = 0; if (con.getRoom() == null) { users = new String[con.getParticipants().size()]; for (JID jid : con.getParticipants()) { String identifier = jid.toBareJID(); try { identifier = UserNameManager.getUserName(jid, jid.toBareJID()); } catch (UserNotFoundException e) { // Ignore } users[usersIdx++] = StringUtils.abbreviate(identifier, 20); } } else { users = new String[2]; users[0] = LocaleUtils.getLocalizedString( "dashboard.group_conversation", MonitoringConstants.NAME); try { users[1] = "(<i>" + LocaleUtils.getLocalizedString("muc.room.summary.room") + ": <a href='../../muc-room-occupants.jsp?roomName=" + URLEncoder.encode(con.getRoom().getNode(), "UTF-8") + "'>" + con.getRoom().getNode() + "</a></i>)"; } catch (UnsupportedEncodingException e) { Log.error(e.getMessage(), e); } } mCon.put("users", users); mCon.put("lastactivity", formatTimeLong(con.getLastActivity())); mCon.put("messages", con.getMessageCount()); cons.add(0, mCon); counter++; } } return cons; }
public void close() { boolean wasClosed = false; synchronized (this) { if (!isClosed()) { try { if (session != null) { session.setStatus(Session.STATUS_CLOSED); } synchronized (writer) { try { // Register that we started sending data on the connection writeStarted(); writer.write("</stream:stream>"); if (flashClient) { writer.write('\0'); } writer.flush(); } catch (IOException e) { } finally { // Register that we finished sending data on the connection writeFinished(); } } } catch (Exception e) { Log.error( LocaleUtils.getLocalizedString("admin.error.close") + "\n" + this.toString(), e); } closeConnection(); wasClosed = true; } } if (wasClosed) { notifyCloseListeners(); } }
public void sendNewPostMessage(User recipient, Post post) { // Short-circuit message creation if (!userIsPresent(recipient.getGuid())) return; String title = post.getTitle(); String url = post.getUrl() != null ? post.getUrl().toExternalForm() : null; if (url == null) { // this particular jabber message protocol has no point without an url Log.debug("no url found on post, not sending xmpp message"); return; } Viewpoint viewpoint = new UserViewpoint(recipient); PostView postView = postingBoard.getPostView(viewpoint, post); Set<EntityView> referenced = postingBoard.getReferencedEntities(viewpoint, post); Message message = new Message(); message.setType(Message.Type.normal); message.setBody(String.format("%s\n%s", title, url)); addNewPostExtension(message, postView, referenced); sendMessage(recipient.getGuid(), message); }
public void deliverRawText(String text) { if (!isClosed()) { boolean errorDelivering = false; synchronized (writer) { try { // Register that we started sending data on the connection writeStarted(); writer.write(text); if (flashClient) { writer.write('\0'); } writer.flush(); } catch (IOException e) { Log.debug("Error delivering raw text" + "\n" + this.toString(), e); errorDelivering = true; } finally { // Register that we finished sending data on the connection writeFinished(); } } if (errorDelivering) { close(); } } }
public void deleteUser(String username) { if (isReadOnly()) { // Reject the operation since the provider is read-only throw new UnsupportedOperationException(); } Connection con = null; PreparedStatement pstmt = null; boolean abortTransaction = false; try { // Delete all of the users's extended properties con = DbConnectionManager.getTransactionConnection(); pstmt = con.prepareStatement(DELETE_USER_PROPS); pstmt.setString(1, username); pstmt.execute(); pstmt.close(); // Delete the actual user entry pstmt = con.prepareStatement(DELETE_USER); pstmt.setString(1, username); pstmt.execute(); } catch (Exception e) { Log.error(e); abortTransaction = true; } finally { DbConnectionManager.closeTransactionConnection(pstmt, con, abortTransaction); } }
/** * The packet is a typical 'set' or 'get' update targeted at the server. Notice that the set could * be a roster removal in which case we have to generate a local roster removal update as well as * a new roster removal to send to the the roster item's owner. * * @param packet The packet that triggered this update * @return Either a response to the roster update or null if the packet is corrupt and the session * was closed down */ private IQ manageRoster(org.xmpp.packet.Roster packet) throws UnauthorizedException, UserAlreadyExistsException, SharedGroupException { IQ returnPacket = null; JID sender = packet.getFrom(); IQ.Type type = packet.getType(); try { if ((sender.getNode() == null || !RosterManager.isRosterServiceEnabled() || !userManager.isRegisteredUser(sender.getNode())) && IQ.Type.get == type) { // If anonymous user asks for his roster or roster service is disabled then // return an empty roster IQ reply = IQ.createResultIQ(packet); reply.setChildElement("query", "jabber:iq:roster"); return reply; } if (!localServer.isLocal(sender)) { // Sender belongs to a remote server so discard this IQ request Log.warn("Discarding IQ roster packet of remote user: " + packet); return null; } Roster cachedRoster = userManager.getUser(sender.getNode()).getRoster(); if (IQ.Type.get == type) { returnPacket = cachedRoster.getReset(); returnPacket.setType(IQ.Type.result); returnPacket.setTo(sender); returnPacket.setID(packet.getID()); // Force delivery of the response because we need to trigger // a presence probe from all contacts deliverer.deliver(returnPacket); returnPacket = null; } else if (IQ.Type.set == type) { for (org.xmpp.packet.Roster.Item item : packet.getItems()) { if (item.getSubscription() == org.xmpp.packet.Roster.Subscription.remove) { removeItem(cachedRoster, packet.getFrom(), item); } else { if (cachedRoster.isRosterItem(item.getJID())) { // existing item RosterItem cachedItem = cachedRoster.getRosterItem(item.getJID()); cachedItem.setAsCopyOf(item); cachedRoster.updateRosterItem(cachedItem); } else { // new item cachedRoster.createRosterItem(item); } } } returnPacket = IQ.createResultIQ(packet); } } catch (UserNotFoundException e) { throw new UnauthorizedException(e); } return returnPacket; }
private void updateClearspaceSharedSecret(String newSecret) { try { String path = IM_URL_PREFIX + "updateSharedSecret/"; // Creates the XML with the data Document groupDoc = DocumentHelper.createDocument(); Element rootE = groupDoc.addElement("updateSharedSecret"); rootE.addElement("newSecret").setText(newSecret); executeRequest(POST, path, groupDoc.asXML()); } catch (UnauthorizedException ue) { Log.error("Error updating the password of Clearspace", ue); } catch (Exception e) { Log.error("Error updating the password of Clearspace", e); } }
protected void handleStateChange(ClientConnEvent e) { Log.debug("OSCAR bos service state change from " + e.getOldState() + " to " + e.getNewState()); if (e.getNewState() == ClientFlapConn.STATE_NOT_CONNECTED && e.getOldState() == ClientFlapConn.STATE_CONNECTED && getMainSession().isLoggedIn()) { getMainSession().bosDisconnected(); } }
public Collection<User> findUsers(Set<String> fields, String query) throws UnsupportedOperationException { if (fields.isEmpty()) { return Collections.emptyList(); } if (!getSearchFields().containsAll(fields)) { throw new IllegalArgumentException("Search fields " + fields + " are not valid."); } if (query == null || "".equals(query)) { return Collections.emptyList(); } // SQL LIKE queries don't map directly into a keyword/wildcard search like we want. // Therefore, we do a best approximiation by replacing '*' with '%' and then // surrounding the whole query with two '%'. This will return more data than desired, // but is better than returning less data than desired. query = "%" + query.replace('*', '%') + "%"; if (query.endsWith("%%")) { query = query.substring(0, query.length() - 1); } List<String> usernames = new ArrayList<String>(50); Connection con = null; Statement stmt = null; ResultSet rs = null; try { con = DbConnectionManager.getConnection(); stmt = con.createStatement(); StringBuilder sql = new StringBuilder(); sql.append("SELECT username FROM jiveUser WHERE"); boolean first = true; if (fields.contains("Username")) { sql.append(" username LIKE '").append(StringUtils.escapeForSQL(query)).append("'"); first = false; } if (fields.contains("Name")) { if (!first) { sql.append(" AND"); } sql.append(" name LIKE '").append(StringUtils.escapeForSQL(query)).append("'"); first = false; } if (fields.contains("Email")) { if (!first) { sql.append(" AND"); } sql.append(" email LIKE '").append(StringUtils.escapeForSQL(query)).append("'"); } rs = stmt.executeQuery(sql.toString()); while (rs.next()) { usernames.add(rs.getString(1)); } } catch (SQLException e) { Log.error(e); } finally { DbConnectionManager.closeConnection(rs, stmt, con); } return new UserCollection(usernames.toArray(new String[usernames.size()])); }
/* (non-Javadoc) * @see org.jivesoftware.openfire.roster.RosterItemProvider#updateItem(java.lang.String, org.jivesoftware.openfire.roster.RosterItem) */ public void updateItem(String username, RosterItem item) throws UserNotFoundException { Connection con = null; PreparedStatement pstmt = null; long rosterID = item.getID(); try { con = DbConnectionManager.getConnection(); // Update existing roster item pstmt = con.prepareStatement(UPDATE_ROSTER_ITEM); pstmt.setInt(1, item.getSubStatus().getValue()); pstmt.setInt(2, item.getAskStatus().getValue()); pstmt.setInt(3, item.getRecvStatus().getValue()); pstmt.setString(4, item.getNickname()); pstmt.setLong(5, rosterID); pstmt.executeUpdate(); // Close now the statement (do not wait to be GC'ed) pstmt.close(); // Delete old group list pstmt = con.prepareStatement(DELETE_ROSTER_ITEM_GROUPS); pstmt.setLong(1, rosterID); pstmt.executeUpdate(); insertGroups(rosterID, item.getGroups().iterator(), con); } catch (SQLException e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); } finally { try { if (pstmt != null) { pstmt.close(); } } catch (Exception e) { Log.error(e); } try { if (con != null) { con.close(); } } catch (Exception e) { Log.error(e); } } }
private void updateClearspaceClientSettings() { String xmppBoshSslPort = "0"; String xmppBoshPort = "0"; String xmppPort = String.valueOf(XMPPServer.getInstance().getConnectionManager().getClientListenerPort()); if (JiveGlobals.getBooleanProperty( HttpBindManager.HTTP_BIND_ENABLED, HttpBindManager.HTTP_BIND_ENABLED_DEFAULT)) { int boshSslPort = HttpBindManager.getInstance().getHttpBindSecurePort(); int boshPort = HttpBindManager.getInstance().getHttpBindUnsecurePort(); try { if (HttpBindManager.getInstance().isHttpsBindActive() && LocalClientSession.getTLSPolicy() != org.jivesoftware.openfire.Connection.TLSPolicy.disabled) { xmppBoshSslPort = String.valueOf(boshSslPort); } } catch (Exception e) { // Exception while working with certificate Log.debug( "Error while checking SSL certificate. Instructing Clearspace not to use SSL port."); } if (HttpBindManager.getInstance().isHttpBindActive() && boshPort > 0) { xmppBoshPort = String.valueOf(boshPort); } } try { String path = CHAT_URL_PREFIX + "updateClientSettings/"; // Creates the XML with the data Document groupDoc = DocumentHelper.createDocument(); Element rootE = groupDoc.addElement("updateClientSettings"); rootE.addElement("boshSslPort").setText(xmppBoshSslPort); rootE.addElement("boshPort").setText(xmppBoshPort); rootE.addElement("tcpPort").setText(xmppPort); executeRequest(POST, path, groupDoc.asXML()); } catch (UnauthorizedException ue) { Log.error("Error updating the client settings of Clearspace", ue); } catch (Exception e) { Log.error("Error updating the client settings of Clearspace", e); } }
@Override public IQ handleIQ(IQ packet) throws UnauthorizedException { Log.debug("handling IQ packet " + packet); IQ reply = IQ.createResultIQ(packet); Element iq = packet.getChildElement(); String method = iq.attributeValue("name"); List<String> args = new ArrayList<String>(); // TODO Don't look this up each time // We currently do this to avoid problems during development // from reloading Jive - later we probably want to move this to // constructor XMPPMethods methods = EJBUtil.defaultLookup(XMPPMethods.class); SimpleAnnotatedInvoker xmppInvoker = new SimpleAnnotatedInvoker(XMPPRemoted.class, methods, new PersonArgumentPrepender()); for (Object argObj : iq.elements()) { Node arg = (Node) argObj; Log.debug("parsing expected arg node " + arg); if (arg.getNodeType() == Node.ELEMENT_NODE) { String argValue = arg.getText(); Log.debug("Adding arg value" + argValue); args.add(argValue); } } try { Log.debug( "invoking method " + method + " with (" + args.size() + ") args " + Arrays.toString(args.toArray())); @SuppressWarnings("unused") String replyStr = xmppInvoker.invoke(method, args, packet.getFrom()); // Don't do anything with this yet } catch (Exception e) { Log.debug("Caught exception during client method invocation", e); } return reply; }
/** Stop every running sessions. */ void stopProxy() { for (MediaProxySession session : getSessions()) { try { session.clearAgentListeners(); session.stopAgent(); } catch (Exception e) { Log.error("Error cleaning up media proxy sessions", e); } } sessions.clear(); }