Пример #1
0
  /**
   * Stop all forwards giving the resource ID of the <i>SSL-Tunnel</i> that started them.
   *
   * @param launchSession launch session
   * @throws NoPermissionException if not allowed
   * @throws CoreException on any other error
   */
  public void stopTunnels(LaunchSession launchSession) throws NoPermissionException, CoreException {
    if (!DefaultAgentManager.getInstance().hasActiveAgent(launchSession.getSession())) {
      throw new TunnelException(TunnelException.INTERNAL_ERROR, (Throwable) null, "No agent.");
    }

    Tunnel tunnel = (Tunnel) launchSession.getResource();
    launchSession.checkAccessRights(null, agent.getSession());
    MultiplexedConnection agent =
        DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession());

    try {
      if (tunnel.getType() == TransportType.LOCAL_TUNNEL_ID) {
        Collection<Tunnel> l = new ArrayList<Tunnel>();
        l.add(tunnel);
        stopLocalTunnels(agent, l);
      } else if (tunnel.getType() == TransportType.REMOTE_TUNNEL_ID) {
        Collection<Tunnel> l = new ArrayList<Tunnel>();
        l.add(tunnel);
        stopRemoteTunnels(agent, l);
      } else {
        throw new TunnelException(
            TunnelException.INTERNAL_ERROR,
            (Throwable) null,
            "Unknown tunnel type " + tunnel.getType());
      }

      CoreServlet.getServlet()
          .fireCoreEvent(
              new ResourceAccessEvent(
                  this,
                  TunnelsEventConstants.TUNNEL_CLOSED,
                  launchSession.getResource(),
                  launchSession.getPolicy(),
                  launchSession.getSession(),
                  CoreEvent.STATE_SUCCESSFUL));

    } catch (TunnelException te) {
      CoreServlet.getServlet()
          .fireCoreEvent(
              new ResourceAccessEvent(
                  this,
                  TunnelsEventConstants.TUNNEL_CLOSED,
                  launchSession.getResource(),
                  launchSession.getPolicy(),
                  launchSession.getSession(),
                  te));
      throw te;
    } finally {
      LaunchSessionFactory.getInstance().removeLaunchSession(launchSession);
    }
  }
Пример #2
0
  /**
   * Start port forwards for the <i>SSL Tunnel</i> specified by the provided resource ID.
   *
   * @param launchSession launch session
   * @throws NoPermissionException if not allowed
   * @throws TunnelException on any other other
   * @throws PolicyException on any other determininig policy
   */
  public void startTunnel(LaunchSession launchSession)
      throws NoPermissionException, TunnelException, PolicyException {

    if (!DefaultAgentManager.getInstance().hasActiveAgent(launchSession.getSession())) {
      throw new TunnelException(TunnelException.INTERNAL_ERROR, (Throwable) null, "No agent.");
    } else {
      Tunnel tunnel = (Tunnel) launchSession.getResource();
      launchSession.checkAccessRights(null, agent.getSession());
      AgentTunnel agent =
          DefaultAgentManager.getInstance().getAgentBySession(launchSession.getSession());

      try {
        if (tunnel.getType() == TransportType.LOCAL_TUNNEL_ID) {
          startLocalTunnel(agent, tunnel, launchSession);
        } else if (tunnel.getType() == TransportType.REMOTE_TUNNEL_ID) {
          startRemoteTunnel(agent, tunnel, launchSession);
        } else {
          throw new TunnelException(
              TunnelException.INTERNAL_ERROR,
              (Throwable) null,
              "Unknown tunnel type " + tunnel.getType());
        }

        // Fire event
        CoreServlet.getServlet()
            .fireCoreEvent(
                new ResourceAccessEvent(
                    this,
                    TunnelsEventConstants.TUNNEL_OPENED,
                    launchSession.getResource(),
                    launchSession.getPolicy(),
                    launchSession.getSession(),
                    CoreEvent.STATE_SUCCESSFUL));
      } catch (TunnelException te) {

        // Fire event
        CoreServlet.getServlet()
            .fireCoreEvent(
                new ResourceAccessEvent(
                    this,
                    TunnelsEventConstants.TUNNEL_OPENED,
                    launchSession.getResource(),
                    launchSession.getPolicy(),
                    launchSession.getSession(),
                    te));

        throw te;
      }
    }
  }