Exemplo n.º 1
0
  /**
   * Blocks an external component from connecting to the local server. If the component was
   *
   * <p>connected when the permission was revoked then the connection of the entity will be closed.
   *
   * @param subdomain the subdomain of the external component that is not allowed to connect.
   */
  public static void blockAccess(String subdomain) {

    // Remove any previous configuration for this external component

    deleteConfiguration(subdomain);

    // Update the database with the new revoked permission

    ExternalComponentConfiguration config = new ExternalComponentConfiguration(subdomain);

    config.setPermission(Permission.blocked);

    addConfiguration(config);

    // Check if the component was connected and proceed to close the connection

    String domain = subdomain + "." + XMPPServer.getInstance().getServerInfo().getDefaultName();

    Session session = SessionManager.getInstance().getComponentSession(domain);

    if (session != null) {

      session.getConnection().close();
    }
  }
Exemplo n.º 2
0
 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
     }
   }
 }
Exemplo n.º 3
0
 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();
   }
 }
Exemplo n.º 4
0
 /**
  * Forces the connection to be closed immediately no matter if closing the socket takes a long
  * time. This method should only be called from {@link SocketSendingTracker} when sending data
  * over the socket has taken a long time and we need to close the socket, discard the connection
  * and its session.
  */
 private void forceClose() {
   if (session != null) {
     // Set that the session is closed. This will prevent threads from trying to
     // deliver packets to this session thus preventing future locks.
     session.setStatus(Session.STATUS_CLOSED);
   }
   closeConnection();
   // Notify the close listeners so that the SessionManager can send unavailable
   // presences if required.
   notifyCloseListeners();
 }
Exemplo n.º 5
0
 public boolean isClosed() {
   if (session == null) {
     return socket.isClosed();
   }
   return session.getStatus() == Session.STATUS_CLOSED;
 }