Exemplo n.º 1
0
  public static Survey buildSurvey(MavLinkDrone drone, Survey survey) {
    org.droidplanner.services.android.core.mission.Mission droneMission =
        drone == null ? null : drone.getMission();
    SurveyImpl updatedSurveyImpl = (SurveyImpl) ProxyUtils.getMissionItemImpl(droneMission, survey);

    return (Survey) ProxyUtils.getProxyMissionItem(updatedSurveyImpl);
  }
Exemplo n.º 2
0
  public static StructureScanner buildStructureScanner(MavLinkDrone drone, StructureScanner item) {
    org.droidplanner.services.android.core.mission.Mission droneMission =
        drone == null ? null : drone.getMission();
    StructureScannerImpl updatedScan =
        (StructureScannerImpl) ProxyUtils.getMissionItemImpl(droneMission, item);

    StructureScanner proxyScanner = (StructureScanner) ProxyUtils.getProxyMissionItem(updatedScan);
    return proxyScanner;
  }
Exemplo n.º 3
0
  @Test
  public void testAddNewViaHeader() {
    String hostname = ProxyUtils.getHostName();

    HttpMessage httpMessage =
        new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/endpoint");
    ProxyUtils.addVia(httpMessage);

    List<String> viaHeaders = httpMessage.headers().getAll(HttpHeaders.Names.VIA);
    assertThat(viaHeaders, hasSize(1));

    String expectedViaHeader = "1.1 " + hostname;
    assertEquals(expectedViaHeader, viaHeaders.get(0));
  }
Exemplo n.º 4
0
  /**
   * Creates a new proxy server.
   *
   * @param port The port the server should run on.
   * @param responseFilters The {@link Map} of request domains to match with associated {@link
   *     HttpFilter}s for filtering responses to those requests.
   * @param chainProxyManager The proxy to send requests to if chaining proxies. Typically <code>
   *     null</code>.
   * @param ksm The key manager if running the proxy over SSL.
   * @param requestFilter Optional filter for modifying incoming requests. Often <code>null</code>.
   * @param clientChannelFactory The factory for creating outgoing channels to external sites.
   * @param timer The global timer for timing out idle connections.
   * @param serverChannelFactory The factory for creating listening channels for incoming
   *     connections.
   */
  public DefaultHttpProxyServer(
      final int port,
      final HttpResponseFilters responseFilters,
      final ChainProxyManager chainProxyManager,
      final KeyStoreManager ksm,
      final HttpRequestFilter requestFilter,
      final ClientSocketChannelFactory clientChannelFactory,
      final Timer timer,
      final ServerSocketChannelFactory serverChannelFactory,
      final ProxyCacheManager cacheManager) {
    this.port = port;
    this.responseFilters = responseFilters;
    this.ksm = ksm;
    this.requestFilter = requestFilter;
    this.chainProxyManager = chainProxyManager;
    this.clientChannelFactory = clientChannelFactory;
    this.timer = timer;
    this.serverChannelFactory = serverChannelFactory;
    if (cacheManager == null) {
      this.cacheManager = ProxyUtils.loadCacheManager();
    } else {
      this.cacheManager = cacheManager;
    }
    Thread.setDefaultUncaughtExceptionHandler(
        new UncaughtExceptionHandler() {
          public void uncaughtException(final Thread t, final Throwable e) {
            log.error("Uncaught throwable", e);
          }
        });

    // Use our thread names so users know there are LittleProxy threads.
    ThreadRenamingRunnable.setThreadNameDeterminer(ThreadNameDeterminer.CURRENT);
    this.serverBootstrap = new ServerBootstrap(serverChannelFactory);
  }
Exemplo n.º 5
0
  public static CameraProxy getCameraProxy(MavLinkDrone drone, List<CameraDetail> cameraDetails) {
    final CameraDetail camDetail;
    final FootPrint currentFieldOfView;
    final List<FootPrint> proxyPrints = new ArrayList<>();

    if (drone == null) {
      camDetail = new CameraDetail();
      currentFieldOfView = new FootPrint();
    } else {
      Camera droneCamera = drone.getCamera();

      camDetail = ProxyUtils.getCameraDetail(droneCamera.getCamera());

      List<Footprint> footprints = droneCamera.getFootprints();
      for (Footprint footprint : footprints) {
        proxyPrints.add(CommonApiUtils.getProxyCameraFootPrint(footprint));
      }

      Gps droneGps = (Gps) drone.getAttribute(AttributeType.GPS);
      currentFieldOfView =
          droneGps != null && droneGps.isValid()
              ? CommonApiUtils.getProxyCameraFootPrint(droneCamera.getCurrentFieldOfView())
              : new FootPrint();
    }

    return new CameraProxy(camDetail, currentFieldOfView, proxyPrints, cameraDetails);
  }
  /**
   * {@inheritDoc}
   *
   * @see org.springframework.security.access.method.MethodSecurityMetadataSource#getAttributes(
   *     java.lang.reflect.Method, java.lang.Class)
   */
  public Collection<ConfigAttribute> getAttributes(final Method m, final Class<?> tc) {

    Method method = ProxyUtils.unproxy(m);
    Class<?> targetClass = ProxyUtils.unproxy(tc);

    DefaultCacheKey cacheKey = new DefaultCacheKey(method, targetClass);
    synchronized (_cache) {
      Collection<ConfigAttribute> cached = _cache.get(cacheKey);
      // Check for canonical value indicating there is no config attribute,
      if (cached == NULL_CONFIG_ATTRIBUTE) {
        return null;
      }

      if (cached != null) {
        return cached;
      }

      // No cached value, so query the sources to find a result
      Collection<ConfigAttribute> attributes = null;
      for (MethodSecurityMetadataSource s : _methodSecurityMetadataSources) {
        attributes = s.getAttributes(method, targetClass);
        if (attributes != null && !attributes.isEmpty()) {
          break;
        }
      }

      // Put it in the cache.
      if (attributes == null) {
        _cache.put(cacheKey, NULL_CONFIG_ATTRIBUTE);
        return null;
      }

      if (logger.isDebugEnabled()) {
        logger.debug("Adding security method [" + cacheKey + "] with attributes " + attributes);
      }

      _cache.put(cacheKey, attributes);

      return attributes;
    }
  }
Exemplo n.º 7
0
 @Test
 public void testParseHostAndPort() throws Exception {
   assertEquals("www.test.com:80", ProxyUtils.parseHostAndPort("http://www.test.com:80/test"));
   assertEquals("www.test.com:80", ProxyUtils.parseHostAndPort("https://www.test.com:80/test"));
   assertEquals("www.test.com:443", ProxyUtils.parseHostAndPort("https://www.test.com:443/test"));
   assertEquals("www.test.com:80", ProxyUtils.parseHostAndPort("www.test.com:80/test"));
   assertEquals("www.test.com", ProxyUtils.parseHostAndPort("http://www.test.com"));
   assertEquals("www.test.com", ProxyUtils.parseHostAndPort("www.test.com"));
   assertEquals("httpbin.org:443", ProxyUtils.parseHostAndPort("httpbin.org:443/get"));
 }
Exemplo n.º 8
0
  public static void setMission(MavLinkDrone drone, Mission mission, boolean pushToDrone) {
    if (drone == null) return;

    org.droidplanner.services.android.core.mission.Mission droneMission = drone.getMission();
    droneMission.clearMissionItems();

    List<MissionItem> itemsList = mission.getMissionItems();
    for (MissionItem item : itemsList) {
      droneMission.addMissionItem(ProxyUtils.getMissionItemImpl(droneMission, item));
    }

    if (pushToDrone) droneMission.sendMissionToAPM();
  }
Exemplo n.º 9
0
  public static Mission getMission(MavLinkDrone drone) {
    Mission proxyMission = new Mission();
    if (drone == null) return proxyMission;

    org.droidplanner.services.android.core.mission.Mission droneMission = drone.getMission();
    List<org.droidplanner.services.android.core.mission.MissionItem> droneMissionItems =
        droneMission.getComponentItems();

    proxyMission.setCurrentMissionItem((short) drone.getMissionStats().getCurrentWP());
    if (!droneMissionItems.isEmpty()) {
      for (org.droidplanner.services.android.core.mission.MissionItem item : droneMissionItems) {
        proxyMission.addMissionItem(ProxyUtils.getProxyMissionItem(item));
      }
    }

    return proxyMission;
  }
Exemplo n.º 10
0
  /** @return the nested diagnostic context string for this step's log file */
  @SuppressWarnings("unchecked")
  private String getNestedDiagnosticContext() {
    Step unProxiedStep = (Step) ProxyUtils.getTargetIfProxied(step);
    Class stepClass = unProxiedStep.getClass();
    ModuleService module =
        SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(stepClass);

    String nestedDiagnosticContext =
        StringUtils.substringAfter(module.getModuleConfiguration().getNamespaceCode(), "-")
                .toLowerCase()
            + File.separator
            + step.getName()
            + "-"
            + dateTimeService.toDateTimeStringForFilename(dateTimeService.getCurrentDate());

    return nestedDiagnosticContext;
  }
Exemplo n.º 11
0
 /**
  * Creates a new proxy server.
  *
  * @param port The port the server should run on.
  * @param responseFilters The {@link Map} of request domains to match with associated {@link
  *     HttpFilter}s for filtering responses to those requests.
  * @param chainProxyManager The proxy to send requests to if chaining proxies. Typically <code>
  *     null</code>.
  * @param ksm The key manager if running the proxy over SSL.
  * @param requestFilter Optional filter for modifying incoming requests. Often <code>null</code>.
  * @param clientChannelFactory The factory for creating outgoing channels to external sites.
  * @param timer The global timer for timing out idle connections.
  * @param serverChannelFactory The factory for creating listening channels for incoming
  *     connections.
  */
 public DefaultHttpProxyServer(
     final int port,
     final HttpResponseFilters responseFilters,
     final ChainProxyManager chainProxyManager,
     final KeyStoreManager ksm,
     final HttpRequestFilter requestFilter,
     final ClientSocketChannelFactory clientChannelFactory,
     final Timer timer,
     final ServerSocketChannelFactory serverChannelFactory) {
   this(
       port,
       responseFilters,
       chainProxyManager,
       ksm,
       requestFilter,
       clientChannelFactory,
       timer,
       serverChannelFactory,
       ProxyUtils.loadCacheManager());
 }
Exemplo n.º 12
0
  @Test
  public void testCommaSeparatedHeaderValues() {
    DefaultHttpMessage message;
    List<String> commaSeparatedHeaders;

    // test the empty headers case
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, empty());

    // two headers present, but no values
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "");
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, empty());

    // a single header value
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "chunked");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, contains("chunked"));

    // a single header value with extra spaces
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, " chunked  , ");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, contains("chunked"));

    // two comma-separated values in one header line
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "compress, gzip");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, contains("compress", "gzip"));

    // two comma-separated values in one header line with a spurious ',' and space. see RFC 7230
    // section 7
    // for information on empty list items (not all of which are valid header-values).
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "compress, gzip, ,");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, contains("compress", "gzip"));

    // two values in two separate header lines
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip");
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "chunked");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, contains("gzip", "chunked"));

    // multiple comma-separated values in two separate header lines
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip, compress");
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "deflate, gzip");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(commaSeparatedHeaders, contains("gzip", "compress", "deflate", "gzip"));

    // multiple comma-separated values in multiple header lines with spurious spaces, commas,
    // and tabs (horizontal tabs are defined as optional whitespace in RFC 7230 section 3.2.3)
    message = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, " gzip,compress,");
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "\tdeflate\t,  gzip, ");
    message.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, ",gzip,,deflate,\t, ,");
    commaSeparatedHeaders =
        ProxyUtils.getAllCommaSeparatedHeaderValues(HttpHeaders.Names.TRANSFER_ENCODING, message);
    assertThat(
        commaSeparatedHeaders, contains("gzip", "compress", "deflate", "gzip", "gzip", "deflate"));
  }
Exemplo n.º 13
0
  @Test
  public void testIsResponseSelfTerminating() {
    HttpResponse httpResponse;
    boolean isResponseSelfTerminating;

    // test cases from the scenarios listed in RFC 2616, section 4.4
    // #1: 1.Any response message which "MUST NOT" include a message-body (such as the 1xx, 204, and
    // 304 responses and any response to a HEAD request) is always terminated by the first empty
    // line after the header fields, regardless of the entity-header fields present in the message.
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(true, isResponseSelfTerminating);

    // #2: 2.If a Transfer-Encoding header field (section 14.41) is present and has any value other
    // than "identity", then the transfer-length is defined by use of the "chunked" transfer-coding
    // (section 3.6), unless the message is terminated by closing the connection.
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "chunked");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(true, isResponseSelfTerminating);

    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip, chunked");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(true, isResponseSelfTerminating);

    // chunked encoding is not last, so not self terminating
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "chunked, gzip");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(false, isResponseSelfTerminating);

    // four encodings on two lines, chunked is not last, so not self terminating
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip, chunked");
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "deflate, gzip");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(false, isResponseSelfTerminating);

    // three encodings on two lines, chunked is last, so self terminating
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip");
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "deflate,chunked");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(true, isResponseSelfTerminating);

    // #3: 3.If a Content-Length header field (section 14.13) is present, its decimal value in
    // OCTETs represents both the entity-length and the transfer-length.
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.CONTENT_LENGTH, "15");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(true, isResponseSelfTerminating);

    // continuing #3: If a message is received with both a Transfer-Encoding header field and a
    // Content-Length header field, the latter MUST be ignored.

    // chunked is last Transfer-Encoding, so message is self-terminating
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip, chunked");
    httpResponse.headers().add(HttpHeaders.Names.CONTENT_LENGTH, "15");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(true, isResponseSelfTerminating);

    // chunked is not last Transfer-Encoding, so message is not self-terminating, since
    // Content-Length is ignored
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, "gzip");
    httpResponse.headers().add(HttpHeaders.Names.CONTENT_LENGTH, "15");
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(false, isResponseSelfTerminating);

    // without any of the above conditions, the message should not be self-terminating
    // (multipart/byteranges is ignored, see note in method javadoc)
    httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    isResponseSelfTerminating = ProxyUtils.isResponseSelfTerminating(httpResponse);
    assertEquals(false, isResponseSelfTerminating);
  }