Пример #1
0
  @Test
  public void testAttributes() throws Exception {
    DKIMSignature signed = new DKIMSignature();
    signed.setAttribute("path", "/hello/world");
    signed.setTimestamp();
    signed.addHeader("Visa");
    signed.addHeader("Visa");
    MultivaluedMapImpl<String, String> headers = new MultivaluedMapImpl<String, String>();
    headers.add("Visa", "v1");
    headers.add("Visa", "v2");
    headers.add("Visa", "v3");
    signed.sign(headers, null, keys.getPrivate());

    String signedHeader = signed.toString();

    System.out.println(signedHeader);

    DKIMSignature verified = new DKIMSignature(signedHeader);

    HashMap<String, String> requiredAttributes = new HashMap<String, String>();
    requiredAttributes.put("path", "/hello/world");

    Verification verification = new Verification();
    verification.getRequiredAttributes().put("path", "/hello/world");

    MultivaluedMap<String, String> verifiedHeaders =
        verification.verify(verified, headers, null, keys.getPublic());
    Assert.assertEquals(verifiedHeaders.size(), 1);
    List<String> visas = verifiedHeaders.get("Visa");
    Assert.assertNotNull(visas);
    Assert.assertEquals(visas.size(), 2);
    System.out.println(visas);
    Assert.assertEquals(visas.get(0), "v3");
    Assert.assertEquals(visas.get(1), "v2");
  }
Пример #2
0
 @Test
 public void testQueryParamsDecoded() throws URISyntaxException {
   MultivaluedMap<String, String> map =
       createContext("http://example.org/app/resource?foo1=%7Bbar1%7D&foo2=%7Bbar2%7D", "GET")
           .getQueryParameters(true);
   assertEquals(2, map.size());
   assertEquals("{bar1}", map.getFirst("foo1"));
   assertEquals("{bar2}", map.getFirst("foo2"));
   try {
     map.remove("foo1");
     fail("UnsupportedOperationException expected - returned list should not be modifiable.");
   } catch (UnsupportedOperationException ex) {
     // passed
   }
 }
 private void setQueryParameters(ContainerRequestContext requestContext, Exchange exchange) {
   final MultivaluedMap<String, String> queryParameters =
       requestContext.getUriInfo().getQueryParameters();
   if (queryParameters != null && queryParameters.size() > 0) {
     final Map<String, String> map = new HashMap<>();
     for (MultivaluedMap.Entry<String, List<String>> entry : queryParameters.entrySet()) {
       map.put(
           entry.getKey(),
           (entry.getValue() != null && entry.getValue().size() > 0
               ? entry.getValue().get(0)
               : null));
     }
     exchange.getIn().setHeader(Exchange.HTTP_QUERY, map);
   }
 }
Пример #4
0
  /** Migrated Jersey 1.x {@code com.sun.jersey.impl.PathSegmentsHttpRequestTest}. */
  @Test
  public void testGetPathSegmentsMultipleMatrix() {
    final UriInfo ui = createContext("/p;x=1;x=2;x=3", "GET");
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(1, segments.size());

    final Iterator<PathSegment> psi = segments.iterator();
    PathSegment segment;

    segment = psi.next();
    MultivaluedMap<String, String> m = segment.getMatrixParameters();
    List<String> values = m.get("x");
    for (int i = 0; i < m.size(); i++) {
      assertEquals(Integer.valueOf(i + 1).toString(), values.get(i));
    }
  }
 @Override
 public int size() {
   return delegate.size();
 }
Пример #6
0
 /** Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}. */
 @Test
 public void testGetQueryParametersInterspersedAmpersand() throws Exception {
   final UriInfo ui = createContext("/widgets/10?a=1&&b=2", "GET");
   MultivaluedMap<String, String> p = ui.getQueryParameters();
   assertEquals(p.size(), 2);
 }
Пример #7
0
 /** Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}. */
 @Test
 public void testGetQueryParametersMultipleAmpersand() throws Exception {
   final UriInfo ui = createContext("/widgets/10?&&%20=%20&&&", "GET");
   MultivaluedMap<String, String> p = ui.getQueryParameters();
   assertEquals(p.size(), 1);
 }
Пример #8
0
 /** Migrated Jersey 1.x {@code com.sun.jersey.impl.QueryParametersHttpRequestTest}. */
 @Test
 public void testGetQueryParametersEmpty() throws Exception {
   final UriInfo ui = createContext("/widgets/10", "GET");
   MultivaluedMap<String, String> p = ui.getQueryParameters();
   assertEquals(p.size(), 0);
 }
Пример #9
0
  /**
   * Create a new RequestScope.
   *
   * @param path the URL path
   * @param jsonApiDocument the document for this request
   * @param transaction the transaction for this request
   * @param user the user making this request
   * @param dictionary the entity dictionary
   * @param mapper converts JsonApiDocuments to raw JSON
   * @param auditLogger logger for this request
   * @param queryParams the query parameters
   * @param securityMode the current security mode
   * @param permissionExecutorGenerator the user-provided function that will generate a
   *     permissionExecutor
   */
  public RequestScope(
      String path,
      JsonApiDocument jsonApiDocument,
      DataStoreTransaction transaction,
      User user,
      EntityDictionary dictionary,
      JsonApiMapper mapper,
      AuditLogger auditLogger,
      MultivaluedMap<String, String> queryParams,
      SecurityMode securityMode,
      Function<RequestScope, PermissionExecutor> permissionExecutorGenerator,
      MultipleFilterDialect filterDialect,
      boolean useFilterExpressions) {
    this.path = path;
    this.jsonApiDocument = jsonApiDocument;
    this.transaction = transaction;
    this.user = user;
    this.dictionary = dictionary;
    this.mapper = mapper;
    this.auditLogger = auditLogger;
    this.securityMode = securityMode;
    this.filterDialect = filterDialect;

    this.expressionsByType = new HashMap<>();
    this.globalFilterExpression = null;
    this.objectEntityCache = new ObjectEntityCache();
    this.newPersistentResources = new LinkedHashSet<>();
    this.dirtyResources = new LinkedHashSet<>();
    this.commitTriggers = new LinkedHashSet<>();
    this.useFilterExpressions = useFilterExpressions;

    this.permissionExecutor =
        (permissionExecutorGenerator == null)
            ? new ActivePermissionExecutor(this)
            : permissionExecutorGenerator.apply(this);

    this.queryParams =
        (queryParams == null || queryParams.size() == 0)
            ? Optional.empty()
            : Optional.of(queryParams);

    if (this.queryParams.isPresent()) {

      /* Extract any query param that starts with 'filter' */
      MultivaluedMap filterParams = getFilterParams(queryParams);

      String errorMessage = "";
      if (!filterParams.isEmpty()) {

        /* First check to see if there is a global, cross-type filter */
        try {
          globalFilterExpression = filterDialect.parseGlobalExpression(path, filterParams);
        } catch (ParseException e) {
          errorMessage = e.getMessage();
        }

        /* Next check to see if there is are type specific filters */
        try {
          expressionsByType.putAll(filterDialect.parseTypedExpression(path, filterParams));
        } catch (ParseException e) {

          /* If neither dialect parsed, report the last error found */
          if (globalFilterExpression == null) {

            if (errorMessage.isEmpty()) {
              errorMessage = e.getMessage();
            } else if (!errorMessage.equals(e.getMessage())) {

              /* Combine the two different messages together */
              errorMessage = errorMessage + "\n" + e.getMessage();
            }

            throw new InvalidPredicateException(errorMessage);
          }
        }
      }

      this.sparseFields = parseSparseFields(queryParams);
      this.sorting = Sorting.parseQueryParams(queryParams);
      this.pagination = Pagination.parseQueryParams(queryParams);
    } else {
      this.sparseFields = Collections.emptyMap();
      this.sorting = Sorting.getDefaultEmptyInstance();
      this.pagination = Pagination.getDefaultPagination();
    }

    if (transaction instanceof RequestScopedTransaction) {
      ((RequestScopedTransaction) transaction).setRequestScope(this);
    }
  }
Пример #10
0
 public int size() {
   return delegate.size();
 }