Example usage for org.springframework.util MultiValueMap remove

List of usage examples for org.springframework.util MultiValueMap remove

Introduction

In this page you can find the example usage for org.springframework.util MultiValueMap remove.

Prototype

V remove(Object key);

Source Link

Document

Removes the mapping for a key from this map if it is present (optional operation).

Usage

From source file:org.cleverbus.admin.web.log.LogController.java

@RequestMapping("/")
public String getLogSearch(@RequestParam(value = "fromDate", required = false) DateTime fromDate,
        @RequestParam MultiValueMap<String, String> params, Model model) throws UnsupportedEncodingException {
    if (fromDate != null) {
        params.remove("fromDate");
        // remove empty values:
        for (List<String> valueList : params.values()) {
            ListIterator<String> values = valueList.listIterator();
            while (values.hasNext()) {
                if (!StringUtils.hasText(values.next())) {
                    values.remove();//w ww.  j  a  v a  2  s  .c o m
                }
            }
        }
        model.mergeAttributes(params);
        return "redirect:"
                + UriUtils.encodePath(LogParserConstants.LOGBACK_ISO8601_FORMAT.print(fromDate), "UTF-8");
    }

    model.addAttribute("fromDate", LogParserConstants.LOGBACK_ISO8601_FORMAT.print(
            DateTime.now().minusHours(2).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)));

    LogParserConfig logParserConfig = new LogParserConfig();
    logParserConfig.setGroupBy(LogParserConstants.DEFAULT_GROUP_BY_PROPERTY);
    logParserConfig.setGroupLimit(LogParserConstants.DEFAULT_GROUP_SIZE);
    model.addAttribute("config", logParserConfig);

    return "logSearch";
}

From source file:org.cloudfoundry.identity.uaa.login.SamlRemoteUaaController.java

@RequestMapping(value = "/oauth/token", method = RequestMethod.POST, params = "grant_type=password")
@ResponseBody//  w  ww. j a  v a 2 s  . c  o  m
public ResponseEntity<byte[]> tokenEndpoint(HttpServletRequest request, HttpEntity<byte[]> entity,
        @RequestParam Map<String, String> parameters, Map<String, Object> model, Principal principal)
        throws Exception {

    // Request has a password. Owner password grant with a UAA password
    if (null != request.getParameter("password")) {
        return passthru(request, entity, model);
    } else {
        //
        MultiValueMap<String, String> requestHeadersForClientInfo = new LinkedMultiValueMap<String, String>();
        requestHeadersForClientInfo.add(AUTHORIZATION, request.getHeader(AUTHORIZATION));

        ResponseEntity<byte[]> clientInfoResponse = getDefaultTemplate().exchange(
                getUaaBaseUrl() + "/clientinfo", HttpMethod.POST,
                new HttpEntity<MultiValueMap<String, String>>(null, requestHeadersForClientInfo), byte[].class);

        if (clientInfoResponse.getStatusCode() == HttpStatus.OK) {
            String path = extractPath(request);

            MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
            map.setAll(parameters);
            if (principal != null) {
                map.set("source", "login");
                map.set("client_id", getClientId(clientInfoResponse.getBody()));
                map.setAll(getLoginCredentials(principal));
                map.remove("credentials"); // legacy vmc might break otherwise
            } else {
                throw new BadCredentialsException("No principal found in authorize endpoint");
            }

            HttpHeaders requestHeaders = new HttpHeaders();
            requestHeaders.putAll(getRequestHeaders(requestHeaders));
            requestHeaders.remove(AUTHORIZATION.toLowerCase());
            requestHeaders.remove(ACCEPT.toLowerCase());
            requestHeaders.remove(CONTENT_TYPE.toLowerCase());
            requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
            requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
            requestHeaders.remove(COOKIE);
            requestHeaders.remove(COOKIE.toLowerCase());

            ResponseEntity<byte[]> response = getAuthorizationTemplate().exchange(getUaaBaseUrl() + "/" + path,
                    HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders),
                    byte[].class);

            saveCookie(response.getHeaders(), model);

            byte[] body = response.getBody();
            if (body != null) {
                HttpHeaders outgoingHeaders = getResponseHeaders(response.getHeaders());
                return new ResponseEntity<byte[]>(response.getBody(), outgoingHeaders,
                        response.getStatusCode());
            }

            throw new IllegalStateException("Neither a redirect nor a user approval");
        } else {
            throw new BadCredentialsException(new String(clientInfoResponse.getBody()));
        }
    }
}

From source file:org.n52.io.request.IoParameters.java

public IoParameters removeAllOf(String key) {
    MultiValueMap<String, JsonNode> newValues = new LinkedMultiValueMap<>(query);
    newValues.remove(key.toLowerCase());
    return new IoParameters(newValues);
}

From source file:puma.application.evaluation.AdvancedDocumentController.java

private String access(Action action, MultiValueMap<String, String> params, Environment environment) {
    if (!params.containsKey("user") || !params.containsKey("document")) {
        throw new IllegalArgumentException("Provide at least user and document ids");
    }/*  ww  w .  ja v a2s  . c  o  m*/
    User u = this.userService.byId(Long.parseLong(params.getFirst("user")));
    if (u == null)
        throw new IllegalArgumentException("Could not find user with specified id~!");
    Subject subject = new Subject(u.getId().toString());
    for (Attribute next : u.getAttributes())
        if (next.getFamily().getRetrievalStrategy().equals(RetrievalStrategy.PUSH))
            addAttribute(subject, next.getFamily().getXacmlIdentifier(), next.getValue());
    Document doc = this.docService.getDocumentById(Long.parseLong(params.getFirst("document")));
    if (doc == null)
        throw new IllegalArgumentException("Could not find document with specified id~!");
    params.remove("document");
    params.remove("user");
    puma.peputils.Object object = constructAuthzObject(doc, params);
    Boolean decision = ApplicationPEP.getInstance().isAuthorized(subject, object, action, environment);
    return decision.toString();
}

From source file:org.ambraproject.wombat.controller.SearchController.java

/**
 * Performs an advanced search and serves the result as XML to be read by an RSS reader
 *
 * @param request HttpServletRequest//  w  w w  .  j  a va2s .c om
 * @param model   model that will be passed to the template
 * @param site    site the request originates from
 * @param params  search parameters identical to the {@code search} method
 * @return RSS view of articles returned by the search
 * @throws IOException
 */
@RequestMapping(name = "advancedSearchFeed", value = "/search/feed/{feedType:atom|rss}", params = {
        "unformattedQuery" }, method = RequestMethod.GET)
public ModelAndView getAdvancedSearchRssFeedView(HttpServletRequest request, Model model, @SiteParam Site site,
        @PathVariable String feedType, @RequestParam MultiValueMap<String, String> params) throws IOException {
    String queryString = params.getFirst("unformattedQuery");
    params.remove("unformattedQuery");
    params.add("q", queryString);
    return getSearchRssFeedView(request, model, site, feedType, params);
}

From source file:org.ambraproject.wombat.controller.SearchController.java

/**
 * This is a catch for advanced searches originating from Old Ambra. It transforms the
 * "unformattedQuery" param into "q" which is used by Wombat's new search.
 * todo: remove this method and direct all advancedSearch requests to the simple search method
 *//*from w w w. j av a2s.  c  o  m*/
@RequestMapping(name = "advancedSearch", value = "/search", params = { "unformattedQuery", "!q" })
public String advancedSearch(HttpServletRequest request, Model model, @SiteParam Site site,
        @RequestParam MultiValueMap<String, String> params) throws IOException {
    String queryString = params.getFirst("unformattedQuery");
    params.remove("unformattedQuery");
    params.add("q", queryString);
    return search(request, model, site, params);
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

@RequestMapping(value = "/oauth/authorize", params = "response_type")
public ModelAndView startAuthorization(HttpServletRequest request, @RequestParam Map<String, String> parameters,
        Map<String, Object> model, @RequestHeader HttpHeaders headers, Principal principal) throws Exception {

    String path = extractPath(request);

    MultiValueMap<String, String> map = new LinkedMaskingMultiValueMap<String, String>();
    map.setAll(parameters);//from w w w  .  j  a  v a 2s. c o m

    String redirectUri = parameters.get("redirect-uri");
    if (redirectUri != null && !redirectUri.matches("(http:|https:)?//.*")) {
        redirectUri = "http://" + redirectUri;
        map.set("redirect-uri", redirectUri);
    }

    if (principal != null) {
        map.set("source", "login");
        map.setAll(getLoginCredentials(principal));
        map.remove("credentials"); // legacy cf might break otherwise
        map.remove("password"); // request for token will not use password
    } else {
        throw new BadCredentialsException("No principal found in authorize endpoint");
    }

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.putAll(getRequestHeaders(headers));
    requestHeaders.remove(AUTHORIZATION.toLowerCase());
    requestHeaders.remove(USER_AGENT);
    requestHeaders.remove(ACCEPT.toLowerCase());
    requestHeaders.remove(CONTENT_TYPE.toLowerCase());
    requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    requestHeaders.remove(COOKIE);
    requestHeaders.remove(COOKIE.toLowerCase());

    @SuppressWarnings("rawtypes")
    ResponseEntity<Map> response;

    response = authorizationTemplate.exchange(getUaaBaseUrl() + "/" + path, HttpMethod.POST,
            new HttpEntity<MultiValueMap<String, String>>(map, requestHeaders), Map.class);

    saveCookie(response.getHeaders(), model);

    @SuppressWarnings("unchecked")
    Map<String, Object> body = response.getBody();
    if (body != null) {
        // User approval is required
        logger.debug("Response: " + body);
        model.putAll(body);
        model.put("links", getLinksInfo());
        if (!body.containsKey("options")) {
            String errorMsg = "No options returned from UAA for user approval";
            if (body.containsKey("error")) {
                throw OAuth2Exception.create((String) body.get("error"),
                        (String) (body.containsKey("error_description") ? body.get("error_description")
                                : errorMsg));
            } else {
                throw new OAuth2Exception(errorMsg);
            }
        }
        logger.info("Approval required in /oauth/authorize for: " + principal.getName());
        return new ModelAndView("access_confirmation", model);
    }

    String location = response.getHeaders().getFirst("Location");
    if (location != null) {
        logger.info("Redirect in /oauth/authorize for: " + principal.getName());
        // Don't expose model attributes (cookie) in redirect
        return new ModelAndView(new RedirectView(location, false, true, false));
    }

    throw new IllegalStateException("Neither a redirect nor a user approval");

}