示例#1
0
  public String getRemoteAccessIps() {
    if (remoteAccessForward == null) {
      return "";
    } else {
      HashSet<String> ips = new HashSet<String>();
      List<Map<String, String>> stats = remoteAccessForward.getRemoteAccessStats();
      for (Map<String, String> s : stats) {
        String ip = s.get("remote_ip");
        String host = s.get("remote_dns");
        if (host == null) {
          ips.add(ip);
        } else {
          ips.add(ip + " (" + host + ")");
        }
      }

      StringBuilder b = new StringBuilder();
      for (String ip : ips) {
        b.append(ip + ", ");
      }
      if (b.length() > 2) {
        return b.toString().substring(0, b.length() - 2);
      } else {
        return "";
      }
    }
  }
示例#2
0
 private synchronized void disableRemoteAccess() {
   if (remoteAccessForward != null) {
     System.out.println("disabling remote accesss");
     try {
       authenticatedServer.stop();
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
     remoteAccessForward.stop();
     remoteAccessForward = null;
   }
   coreInterface.setRemoteAccess(remoteAccessForward);
 }
示例#3
0
  private synchronized void enableRemoteAccess() throws Exception {

    if (remoteAccessForward == null) {
      logger.fine("enabling remote access");
      Connector connector = new SelectChannelConnector();
      connector.setHost(LOCALHOST);
      connector.setPort(Constants.LOCAL_WEB_SERVER_PORT_AUTH);

      authenticatedServer = new Server();
      authenticatedServer.addConnector(connector);

      // sets the thread pool (just so it is deamon=true)
      QueuedThreadPool threadPool = new QueuedThreadPool();
      threadPool.setMinThreads(5);
      // threadPool.setMaxThreads(10);
      threadPool.setName("Auth Jetty thread pool");
      threadPool.setDaemon(true);
      authenticatedServer.setThreadPool(threadPool);

      Constraint constraint = new Constraint();
      constraint.setName(Constraint.__BASIC_AUTH);
      constraint.setRoles(new String[] {"remote_user"});
      constraint.setAuthenticate(true);

      ConstraintMapping cm = new ConstraintMapping();
      cm.setConstraint(constraint);
      cm.setPathSpec("/*");

      SecurityHandler securityHandler = new SecurityHandler();
      securityHandler.setUserRealm(
          new ExtraSaltHashUserRealm(
              RemoteAccessConfig.usesMD5Sha1Password(),
              "OneSwarm Remote",
              RemoteAccessConfig.REMOTE_ACCESS_FILE.getCanonicalPath()));
      securityHandler.setConstraintMappings(new ConstraintMapping[] {cm});

      ContextHandlerCollection contexts = new ContextHandlerCollection();

      authenticatedServer.setHandler(contexts);
      Context root = new Context(contexts, "/", Context.NO_SESSIONS);

      root.addFilter(new FilterHolder(new GzipFilter()), "/*", Handler.ALL);

      MultiHandler mh = new MultiHandler(coreInterface, true);

      if (System.getProperty("com.sun.management.jmxremote") != null) {
        RequestLogHandler requestLogHandler = new RequestLogHandler();

        NCSARequestLog requestLog = new NCSARequestLog("/tmp/jetty-yyyy_mm_dd.remoterequest.log");
        requestLog.setRetainDays(1);
        requestLog.setAppend(false);
        requestLog.setExtended(true);
        requestLog.setLogTimeZone("GMT");
        requestLogHandler.setRequestLog(requestLog);

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[] {mh, requestLogHandler});
        root.setHandler(handlers);
      } else {
        root.setHandler(mh);
      }

      root.addHandler(securityHandler);

      // make sure that the class loader can find all classes in the
      // osgwtui
      // plugin dir...
      root.setClassLoader(pluginInterface.getPluginClassLoader());

      authenticatedServer.start();

      remoteAccessForward = new RemoteAccessForward();
      remoteAccessForward.start();
      logger.fine("remote access enabled");
    }
    coreInterface.setRemoteAccess(remoteAccessForward);
  }