Tabnine Logo
org.glassfish.jersey.server.filter
Code IndexAdd Tabnine to your IDE (free)

How to use org.glassfish.jersey.server.filter

Best Java code snippets using org.glassfish.jersey.server.filter (Showing top 20 results out of 315)

origin: jersey/jersey

private static Map<String, MediaType> extractMediaTypeMappings(final Object mappings) {
  // parse and validate mediaTypeMappings set through MEDIA_TYPE_MAPPINGS property
  return parseAndValidateMappings(ServerProperties.MEDIA_TYPE_MAPPINGS, mappings, new TypeParser<MediaType>() {
    public MediaType valueOf(final String value) {
      return MediaType.valueOf(value);
    }
  });
}
origin: jersey/jersey

/**
 * Initializes this filter setting the sources of information the filter should look for.
 *
 * @param sources Sources of method override information. If empty, both
 *                {@link org.glassfish.jersey.server.filter.HttpMethodOverrideFilter.Source#HEADER} and
 *                {@link org.glassfish.jersey.server.filter.HttpMethodOverrideFilter.Source#QUERY} will
 *                be added to the config by default.
 */
public HttpMethodOverrideFilter(final Source... sources) {
  int c = 0;
  for (final Source cf : sources) {
    if (cf != null) {
      c |= cf.getFlag();
    }
  }
  if (c == 0) {
    c = 3;
  }
  this.config = c;
}
origin: jersey/jersey

/**
 * Returns parameter value in a normalized form (uppercase, trimmed and {@code null} if empty string)
 * considering the config flags.
 *
 * @param source    Config flag to look for (if set in the config, this method returns the param value,
 *                  if not set, this method returns {@code null}).
 * @param paramsMap Map to retrieve the parameter from.
 * @param paramName Name of the parameter to retrieve.
 * @return Normalized parameter value. Never returns an empty string - converts it to {@code null}.
 */
private String getParamValue(final Source source, final MultivaluedMap<String, String> paramsMap, final String paramName) {
  String value = source.isPresentIn(config) ? paramsMap.getFirst(paramName) : null;
  if (value == null) {
    return null;
  }
  value = value.trim();
  return value.length() == 0 ? null : value.toUpperCase();
}
origin: jersey/jersey

/**
 * Create a filter that reads the configuration (media type and language mappings)
 * from the provided {@link ResourceConfig} instance.
 * This constructor will be called by the Jersey runtime when the filter
 * class is returned from {@link javax.ws.rs.core.Application#getClasses()}.
 * The {@link ResourceConfig} instance will get auto-injected.
 *
 * @param rc ResourceConfig instance that holds the configuration for the filter.
 */
public UriConnegFilter(@Context final Configuration rc) {
  this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)),
      extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS)));
}
origin: jersey/jersey

private static <T> Map<String, T> parseAndValidateMappings(final String property,
                              final Object mappings,
                              final TypeParser<T> parser) {
  if (mappings == null) {
    return Collections.emptyMap();
  }
  if (mappings instanceof Map) {
    return (Map<String, T>) mappings;
  }
  final HashMap<String, T> mappingsMap = new HashMap<>();
  if (mappings instanceof String) {
    parseMappings(property, (String) mappings, mappingsMap, parser);
  } else if (mappings instanceof String[]) {
    final String[] mappingsArray = (String[]) mappings;
    for (final String aMappingsArray : mappingsArray) {
      parseMappings(property, aMappingsArray, mappingsMap, parser);
    }
  } else {
    throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_TYPE(property));
  }
  encodeKeys(mappingsMap);
  return mappingsMap;
}
origin: jersey/jersey

public static ContentEncoding fromString(String input) throws ParseException {
  HttpHeaderReader reader = HttpHeaderReader.newInstance(input);
  // Skip any white space
  reader.hasNext();
  return new ContentEncoding(reader.nextToken().toString(), HttpHeaderReader.readQualityFactorParameter(reader));
}
origin: jersey/jersey

/**
 * Create a filter that reads the configuration ({@link ServerProperties#HTTP_METHOD_OVERRIDE})
 * from the provided {@link org.glassfish.jersey.server.ResourceConfig} instance.
 * <p/>
 * This constructor will be called by the Jersey runtime when the filter class is returned from
 * {@link javax.ws.rs.core.Application#getClasses()}. The {@link org.glassfish.jersey.server.ResourceConfig}
 * instance will get auto-injected.
 *
 * @param rc ResourceConfig instance that holds the configuration for the filter.
 */
public HttpMethodOverrideFilter(@Context final Configuration rc) {
  this(parseConfig(rc.getProperty(ServerProperties.HTTP_METHOD_OVERRIDE)));
}
origin: jersey/jersey

@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
  if (!denyAll) {
    if (rolesAllowed.length > 0 && !isAuthenticated(requestContext)) {
      throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
    }
    for (final String role : rolesAllowed) {
      if (requestContext.getSecurityContext().isUserInRole(role)) {
        return;
      }
    }
  }
  throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
}
origin: jersey/jersey

private static <T> void parseMappings(final String property, final String mappings,
                   final Map<String, T> mappingsMap, final TypeParser<T> parser) {
  if (mappings == null) {
    return;
  }
  final String[] records = mappings.split(",");
  for (final String record : records) {
    final String[] mapping = record.split(":");
    if (mapping.length != 2) {
      throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_FORMAT(property, mappings));
    }
    final String trimmedSegment = mapping[0].trim();
    final String trimmedValue = mapping[1].trim();
    if (trimmedSegment.length() == 0) {
      throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_KEY_EMPTY(property, record));
    }
    if (trimmedValue.length() == 0) {
      throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_VALUE_EMPTY(property, record));
    }
    mappingsMap.put(trimmedSegment, parser.valueOf(trimmedValue));
  }
}
origin: Graylog2/graylog2-server

  @Override
  public void filter(ContainerRequestContext rc) throws IOException {
    try {
      // Backward compatibility for Sidecars < 0.1.7
      if (!rc.getHeaders().containsKey("X-Graylog-Collector-Version")) {
        super.filter(rc);
      }
    } catch (BadRequestException badRequestException) {
      throw new BadRequestException(
          "CSRF protection header is missing. Please add a \"" + HEADER_NAME + "\" header to your request.",
          badRequestException
      );
    }
  }
}
origin: jersey/jersey

/**
 * Create a filter that reads the configuration (media type and language mappings)
 * from the provided {@link ResourceConfig} instance.
 * This constructor will be called by the Jersey runtime when the filter
 * class is returned from {@link javax.ws.rs.core.Application#getClasses()}.
 * The {@link ResourceConfig} instance will get auto-injected.
 *
 * @param rc ResourceConfig instance that holds the configuration for the filter.
 */
public UriConnegFilter(@Context final Configuration rc) {
  this(extractMediaTypeMappings(rc.getProperty(ServerProperties.MEDIA_TYPE_MAPPINGS)),
      extractLanguageMappings(rc.getProperty(ServerProperties.LANGUAGE_MAPPINGS)));
}
origin: jersey/jersey

private static Map<String, String> extractLanguageMappings(final Object mappings) {
  // parse and validate languageMappings set through LANGUAGE_MAPPINGS property
  return parseAndValidateMappings(ServerProperties.LANGUAGE_MAPPINGS, mappings, new TypeParser<String>() {
    public String valueOf(final String value) {
      return LanguageTag.valueOf(value).toString();
    }
  });
}
origin: jersey/jersey

/**
 * Initializes this filter setting the sources of information the filter should look for.
 *
 * @param sources Sources of method override information. If empty, both
 *                {@link org.glassfish.jersey.server.filter.HttpMethodOverrideFilter.Source#HEADER} and
 *                {@link org.glassfish.jersey.server.filter.HttpMethodOverrideFilter.Source#QUERY} will
 *                be added to the config by default.
 */
public HttpMethodOverrideFilter(final Source... sources) {
  int c = 0;
  for (final Source cf : sources) {
    if (cf != null) {
      c |= cf.getFlag();
    }
  }
  if (c == 0) {
    c = 3;
  }
  this.config = c;
}
origin: jersey/jersey

public static ContentEncoding fromString(String input) throws ParseException {
  HttpHeaderReader reader = HttpHeaderReader.newInstance(input);
  // Skip any white space
  reader.hasNext();
  return new ContentEncoding(reader.nextToken().toString(), HttpHeaderReader.readQualityFactorParameter(reader));
}
origin: jersey/jersey

/**
 * Create a filter that reads the configuration ({@link ServerProperties#HTTP_METHOD_OVERRIDE})
 * from the provided {@link org.glassfish.jersey.server.ResourceConfig} instance.
 * <p/>
 * This constructor will be called by the Jersey runtime when the filter class is returned from
 * {@link javax.ws.rs.core.Application#getClasses()}. The {@link org.glassfish.jersey.server.ResourceConfig}
 * instance will get auto-injected.
 *
 * @param rc ResourceConfig instance that holds the configuration for the filter.
 */
public HttpMethodOverrideFilter(@Context final Configuration rc) {
  this(parseConfig(rc.getProperty(ServerProperties.HTTP_METHOD_OVERRIDE)));
}
origin: jersey/jersey

/**
 * Returns parameter value in a normalized form (uppercase, trimmed and {@code null} if empty string)
 * considering the config flags.
 *
 * @param source    Config flag to look for (if set in the config, this method returns the param value,
 *                  if not set, this method returns {@code null}).
 * @param paramsMap Map to retrieve the parameter from.
 * @param paramName Name of the parameter to retrieve.
 * @return Normalized parameter value. Never returns an empty string - converts it to {@code null}.
 */
private String getParamValue(final Source source, final MultivaluedMap<String, String> paramsMap, final String paramName) {
  String value = source.isPresentIn(config) ? paramsMap.getFirst(paramName) : null;
  if (value == null) {
    return null;
  }
  value = value.trim();
  return value.length() == 0 ? null : value.toUpperCase();
}
origin: jersey/jersey

@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
  if (!denyAll) {
    if (rolesAllowed.length > 0 && !isAuthenticated(requestContext)) {
      throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
    }
    for (final String role : rolesAllowed) {
      if (requestContext.getSecurityContext().isUserInRole(role)) {
        return;
      }
    }
  }
  throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
}
origin: jersey/jersey

private static <T> void parseMappings(final String property, final String mappings,
                   final Map<String, T> mappingsMap, final TypeParser<T> parser) {
  if (mappings == null) {
    return;
  }
  final String[] records = mappings.split(",");
  for (final String record : records) {
    final String[] mapping = record.split(":");
    if (mapping.length != 2) {
      throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_FORMAT(property, mappings));
    }
    final String trimmedSegment = mapping[0].trim();
    final String trimmedValue = mapping[1].trim();
    if (trimmedSegment.length() == 0) {
      throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_KEY_EMPTY(property, record));
    }
    if (trimmedValue.length() == 0) {
      throw new IllegalArgumentException(LocalizationMessages.INVALID_MAPPING_VALUE_EMPTY(property, record));
    }
    mappingsMap.put(trimmedSegment, parser.valueOf(trimmedValue));
  }
}
origin: jersey/jersey

private static Map<String, MediaType> extractMediaTypeMappings(final Object mappings) {
  // parse and validate mediaTypeMappings set through MEDIA_TYPE_MAPPINGS property
  return parseAndValidateMappings(ServerProperties.MEDIA_TYPE_MAPPINGS, mappings, new TypeParser<MediaType>() {
    public MediaType valueOf(final String value) {
      return MediaType.valueOf(value);
    }
  });
}
origin: jersey/jersey

private static Map<String, String> extractLanguageMappings(final Object mappings) {
  // parse and validate languageMappings set through LANGUAGE_MAPPINGS property
  return parseAndValidateMappings(ServerProperties.LANGUAGE_MAPPINGS, mappings, new TypeParser<String>() {
    public String valueOf(final String value) {
      return LanguageTag.valueOf(value).toString();
    }
  });
}
org.glassfish.jersey.server.filter

Most used classes

  • EncodingFilter
    Container filter that supports encoding-based content negotiation. The filter examines what content
  • UriConnegFilter
    A URI-based content negotiation filter mapping a dot-declared suffix in URI to media type that is th
  • EncodingFilter$ContentEncoding
  • HttpMethodOverrideFilter$Source
    Enumeration representing possible sources of information about the method overriding the filter shou
  • HttpMethodOverrideFilter
    A pre-matching filter to support HTTP method replacing of a POST request to a request utilizing anot
  • UriConnegFilter$TypeParser,
  • CsrfProtectionFilter
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now