Java Code Examples for org.springframework.util.MultiValueMap#containsKey()

The following examples show how to use org.springframework.util.MultiValueMap#containsKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MyAuthorizationCodeAccessTokenProvider.java    From springboot-security-wechat with Apache License 2.0 6 votes vote down vote up
protected String getAccessTokenUri(OAuth2ProtectedResourceDetails resource, MultiValueMap<String, String> form) {
    String accessTokenUri = resource.getAccessTokenUri();
    if (form.containsKey("refresh_token"))
        accessTokenUri = "https://api.weixin.qq.com/sns/oauth2/refresh_token";
    if(this.logger.isDebugEnabled()) {
        this.logger.debug("Retrieving token from " + accessTokenUri);
    }

    StringBuilder builder = new StringBuilder(accessTokenUri);
    if(this.getHttpMethod() == HttpMethod.GET) {
        String separator = "?";
        if(accessTokenUri.contains("?")) {
            separator = "&";
        }

        for(Iterator var6 = form.keySet().iterator(); var6.hasNext(); separator = "&") {
            String key = (String)var6.next();
            builder.append(separator);
            builder.append(key + "={" + key + "}");
        }
    }

    if (form.containsKey("refresh_token"))
        return builder.toString();
    return builder.toString() + "#wechat_redirect";
}
 
Example 2
Source File: Util.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return an URL for the given HTTP request, with anonymized sensitive parameters.
 *
 * @param request An HTTP request instance
 * @return The associated anonymized URL
 */
public static String getAnonymizedURLForRequest(HttpServletRequest request) {

    String url = getURLForRequest(request);
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
    MultiValueMap<String, String> components = builder.build().getQueryParams();

    // Subsonic REST API authentication (see RESTRequestParameterProcessingFilter)
    if (components.containsKey("p")) builder.replaceQueryParam("p", URL_SENSITIVE_REPLACEMENT_STRING);  // Cleartext password
    if (components.containsKey("t")) builder.replaceQueryParam("t", URL_SENSITIVE_REPLACEMENT_STRING);  // Token
    if (components.containsKey("s")) builder.replaceQueryParam("s", URL_SENSITIVE_REPLACEMENT_STRING);  // Salt
    if (components.containsKey("u")) builder.replaceQueryParam("u", URL_SENSITIVE_REPLACEMENT_STRING);  // Username

    return builder.build().toUriString();
}
 
Example 3
Source File: AbstractNamedValueServiceParameterResolver.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@Override
public Object resolve(RestMethodMetadata restMethodMetadata,
		MethodParameterMetadata methodParameterMetadata, HttpServerRequest request) {

	Collection<String> names = getNames(restMethodMetadata, methodParameterMetadata);

	if (isEmpty(names)) { // index can't match
		return null;
	}

	MultiValueMap<String, String> nameAndValues = getNameAndValuesMap(request);

	String targetName = null;

	for (String name : names) {
		if (nameAndValues.containsKey(name)) {
			targetName = name;
			break;
		}
	}

	if (targetName == null) { // request parameter is abstract
		return null;
	}

	Class<?> parameterType = resolveClass(methodParameterMetadata.getType());

	Object paramValue = null;

	if (parameterType.isArray()) { // Array type
		paramValue = nameAndValues.get(targetName);
	}
	else {
		paramValue = nameAndValues.getFirst(targetName);
	}

	return resolveValue(paramValue, parameterType);
}
 
Example 4
Source File: Util.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return an URL for the given HTTP request, with anonymized sensitive parameters.
 *
 * @param request An HTTP request instance
 * @return The associated anonymized URL
 */
public static String getAnonymizedURLForRequest(HttpServletRequest request) {

    String url = getURLForRequest(request);
    UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(url);
    MultiValueMap<String, String> components = builder.build().getQueryParams();

    // Subsonic REST API authentication (see RESTRequestParameterProcessingFilter)
    if (components.containsKey("p")) builder.replaceQueryParam("p", URL_SENSITIVE_REPLACEMENT_STRING);  // Cleartext password
    if (components.containsKey("t")) builder.replaceQueryParam("t", URL_SENSITIVE_REPLACEMENT_STRING);  // Token
    if (components.containsKey("s")) builder.replaceQueryParam("s", URL_SENSITIVE_REPLACEMENT_STRING);  // Salt
    if (components.containsKey("u")) builder.replaceQueryParam("u", URL_SENSITIVE_REPLACEMENT_STRING);  // Username

    return builder.build().toUriString();
}
 
Example 5
Source File: WorkbasketAccessItemController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private void getAccessIds(WorkbasketAccessItemQuery query, MultiValueMap<String, String> params) {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to getAccessIds(query= {}, params= {})", query, params);
  }

  if (params.containsKey(ACCESS_IDS)) {
    String[] accessIds = extractVerticalBarSeparatedFields(params.get(ACCESS_IDS));
    query.accessIdIn(accessIds);
    params.remove(ACCESS_IDS);
  }

  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from getAccessIds(), returning {}", query);
  }
}
 
Example 6
Source File: WorkbasketAccessItemController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private void applyFilterParams(
    WorkbasketAccessItemQuery query, MultiValueMap<String, String> params) {
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Entry to applyFilterParams(query= {}, params= {})", query, params);
  }

  if (params.containsKey(WORKBASKET_KEY)) {
    String[] keys = extractCommaSeparatedFields(params.get(WORKBASKET_KEY));
    query.workbasketKeyIn(keys);
    params.remove(WORKBASKET_KEY);
  }
  if (params.containsKey(WORKBASKET_KEY_LIKE)) {
    query.workbasketKeyLike(LIKE + params.get(WORKBASKET_KEY_LIKE).get(0) + LIKE);
    params.remove(WORKBASKET_KEY_LIKE);
  }
  if (params.containsKey(ACCESS_ID)) {
    String[] accessId = extractCommaSeparatedFields(params.get(ACCESS_ID));
    query.accessIdIn(accessId);
    params.remove(ACCESS_ID);
  }
  if (params.containsKey(ACCESS_ID_LIKE)) {
    query.accessIdLike(LIKE + params.get(ACCESS_ID_LIKE).get(0) + LIKE);
    params.remove(ACCESS_ID_LIKE);
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug("Exit from applyFilterParams(), returning {}", query);
  }
}
 
Example 7
Source File: TaskController.java    From taskana with Apache License 2.0 5 votes vote down vote up
private void checkForIllegalParamCombinations(MultiValueMap<String, String> params) {

    if (params.containsKey(PLANNED)
        && (params.containsKey(PLANNED_FROM) || params.containsKey(PLANNED_UNTIL))) {

      throw new IllegalArgumentException(
          "It is prohibited to use the param \""
              + PLANNED
              + "\" in combination with the params \""
              + PLANNED_FROM
              + "\" and / or \""
              + PLANNED_UNTIL
              + "\"");
    }

    if (params.containsKey(DUE) && (params.containsKey(DUE_FROM) || params.containsKey(DUE_TO))) {

      throw new IllegalArgumentException(
          "It is prohibited to use the param \""
              + DUE
              + "\" in combination with the params \""
              + PLANNED_FROM
              + "\" and / or \""
              + PLANNED_UNTIL
              + "\"");
    }

    if (params.containsKey(WILDCARD_SEARCH_FIELDS) && !params.containsKey(WILDCARD_SEARCH_VALUE)
        || !params.containsKey(WILDCARD_SEARCH_FIELDS)
            && params.containsKey(WILDCARD_SEARCH_VALUE)) {

      throw new IllegalArgumentException(
          "The params "
              + WILDCARD_SEARCH_FIELDS
              + " and "
              + WILDCARD_SEARCH_VALUE
              + " must be used together!");
    }
  }
 
Example 8
Source File: MatrixVariableMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Nullable
@Override
protected Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) {
	Map<String, MultiValueMap<String, String>> pathParameters =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	MatrixVariable ann = param.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVar = ann.pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = param.getNestedParameterType().getName();
					throw new ServerErrorException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.",
							param, null);
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 9
Source File: MatrixVariableMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
@Nullable
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
	Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>)
			request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	MatrixVariable ann = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVar = ann.pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = parameter.getNestedParameterType().getName();
					throw new ServletRequestBindingException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.");
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 10
Source File: MatrixVariableMethodArgumentResolver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Nullable
@Override
protected Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) {
	Map<String, MultiValueMap<String, String>> pathParameters =
			exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	MatrixVariable ann = param.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVar = ann.pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = param.getNestedParameterType().getName();
					throw new ServerErrorException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.",
							param, null);
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 11
Source File: MatrixVariableMethodArgumentResolver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
@Nullable
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
	Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>)
			request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	MatrixVariable ann = parameter.getParameterAnnotation(MatrixVariable.class);
	Assert.state(ann != null, "No MatrixVariable annotation");
	String pathVar = ann.pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = parameter.getNestedParameterType().getName();
					throw new ServletRequestBindingException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.");
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 12
Source File: ParamExpression.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchName(HttpRequest request) {
	MultiValueMap<String, String> parametersMap = getParameters(request);
	return parametersMap.containsKey(this.name);
}
 
Example 13
Source File: MatrixVariableMethodArgumentResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {
	Map<String, MultiValueMap<String, String>> pathParameters = (Map<String, MultiValueMap<String, String>>)
			request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	String pathVar = parameter.getParameterAnnotation(MatrixVariable.class).pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<String>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = parameter.getNestedParameterType().getName();
					throw new ServletRequestBindingException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use 'pathVar' attribute to disambiguate.");
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 14
Source File: MatrixVariableMethodArgumentResolver.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {

	@SuppressWarnings("unchecked")
	Map<String, MultiValueMap<String, String>> pathParameters =
		(Map<String, MultiValueMap<String, String>>) request.getAttribute(
				HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

	if (CollectionUtils.isEmpty(pathParameters)) {
		return null;
	}

	String pathVar = parameter.getParameterAnnotation(MatrixVariable.class).pathVar();
	List<String> paramValues = null;

	if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
		if (pathParameters.containsKey(pathVar)) {
			paramValues = pathParameters.get(pathVar).get(name);
		}
	}
	else {
		boolean found = false;
		paramValues = new ArrayList<String>();
		for (MultiValueMap<String, String> params : pathParameters.values()) {
			if (params.containsKey(name)) {
				if (found) {
					String paramType = parameter.getParameterType().getName();
					throw new ServletRequestBindingException(
							"Found more than one match for URI path parameter '" + name +
							"' for parameter type [" + paramType + "]. Use pathVar attribute to disambiguate.");
				}
				paramValues.addAll(params.get(name));
				found = true;
			}
		}
	}

	if (CollectionUtils.isEmpty(paramValues)) {
		return null;
	}
	else if (paramValues.size() == 1) {
		return paramValues.get(0);
	}
	else {
		return paramValues;
	}
}
 
Example 15
Source File: SpecialRoutesFilter.java    From spring-microservices-in-action with Apache License 2.0 3 votes vote down vote up
/**
 * Convert an array of the {@code Header} objects to 
 * a {@code MultiValueMap} object for the HTTP header.
 * 
 * <p>This is a opposite operation for 
 * the {@link #convertHeaders(headers)} method.
 * 
 * @param  headers
 *         The array of the {@code Header} objects.
 * 
 * @return  The {@code MultiValueMap} object representing the headers.
 */
private MultiValueMap<String, String> revertHeaders(Header[] headers) {
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    for (Header header : headers) {
        String name = header.getName();
        if (!map.containsKey(name)) {
            map.put(name, new ArrayList<String>());
        }
        map.get(name).add(header.getValue());
    }
    return map;
}