List of usage examples for org.springframework.util MultiValueMap putAll
void putAll(Map<? extends K, ? extends V> m);
From source file:com.zhm.config.MyAuthorizationCodeAccessTokenProvider.java
public String obtainAuthorizationCode(OAuth2ProtectedResourceDetails details, AccessTokenRequest request) throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException, OAuth2AccessDeniedException { AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) details; HttpHeaders headers = getHeadersForAuthorizationRequest(request); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); if (request.containsKey(OAuth2Utils.USER_OAUTH_APPROVAL)) { form.set(OAuth2Utils.USER_OAUTH_APPROVAL, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); for (String scope : details.getScope()) { form.set(scopePrefix + scope, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); }//ww w.jav a 2 s. c o m } else { form.putAll(getParametersForAuthorizeRequest(resource, request)); } authorizationRequestEnhancer.enhance(request, resource, form, headers); final AccessTokenRequest copy = request; final ResponseExtractor<ResponseEntity<Void>> delegate = getAuthorizationResponseExtractor(); ResponseExtractor<ResponseEntity<Void>> extractor = new ResponseExtractor<ResponseEntity<Void>>() { @Override public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException { if (response.getHeaders().containsKey("Set-Cookie")) { copy.setCookie(response.getHeaders().getFirst("Set-Cookie")); } return delegate.extractData(response); } }; // Instead of using restTemplate.exchange we use an explicit response extractor here so it can be overridden by // subclasses ResponseEntity<Void> response = getRestTemplate().execute(resource.getUserAuthorizationUri(), HttpMethod.POST, getRequestCallback(resource, form, headers), extractor, form.toSingleValueMap()); if (response.getStatusCode() == HttpStatus.OK) { // Need to re-submit with approval... throw getUserApprovalSignal(resource, request); } URI location = response.getHeaders().getLocation(); String query = location.getQuery(); Map<String, String> map = OAuth2Utils.extractMap(query); if (map.containsKey("state")) { request.setStateKey(map.get("state")); if (request.getPreservedState() == null) { String redirectUri = resource.getRedirectUri(request); if (redirectUri != null) { request.setPreservedState(redirectUri); } else { request.setPreservedState(new Object()); } } } String code = map.get("code"); if (code == null) { throw new UserRedirectRequiredException(location.toString(), form.toSingleValueMap()); } request.set("code", code); return code; }
From source file:com.emergya.spring.security.oauth.google.GoogleAuthorizationCodeAccessTokenProvider.java
/** * Obtains the authorization code from the access token request. * * @param details the authenticatoin details * @param request the access token request * @return the authorization code/*from www . j av a 2 s . c om*/ * @throws UserRedirectRequiredException when redirection is required * @throws UserApprovalRequiredException when the user requires approval * @throws AccessDeniedException when the user is denied access * @throws OAuth2AccessDeniedException when the user is denied access but we dont want the default Spring Security handling */ public final String obtainAuthorizationCode(final OAuth2ProtectedResourceDetails details, final AccessTokenRequest request) throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException, OAuth2AccessDeniedException { GoogleAuthCodeResourceDetails resource; try { resource = (GoogleAuthCodeResourceDetails) details; } catch (ClassCastException ex) { throw new IllegalArgumentException("details is not an instance of class GoogleAuthCodeResourceDetails"); } HttpHeaders headers = getHeadersForAuthorizationRequest(request); MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); if (request.containsKey(OAuth2Utils.USER_OAUTH_APPROVAL)) { form.set(OAuth2Utils.USER_OAUTH_APPROVAL, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); for (String scope : details.getScope()) { form.set(scopePrefix + scope, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); } } else { form.putAll(getParametersForAuthorizeRequest(resource, request)); } authorizationRequestEnhancer.enhance(request, resource, form, headers); final AccessTokenRequest copy = request; final ResponseExtractor<ResponseEntity<Void>> delegate = getAuthorizationResponseExtractor(); ResponseExtractor<ResponseEntity<Void>> extractor = new CookieResponseExtractor(copy, delegate); // Instead of using restTemplate.exchange we use an explicit response extractor here so it can be overridden by // subclasses ResponseEntity<Void> response = getRestTemplate().execute(resource.getUserAuthorizationUri(), HttpMethod.POST, getRequestCallback(resource, form, headers), extractor, form.toSingleValueMap()); if (response.getStatusCode() == HttpStatus.OK) { // Need to re-submit with approval... throw getUserApprovalSignal(resource, request); } URI location = response.getHeaders().getLocation(); String query = location.getQuery(); Map<String, String> map = OAuth2Utils.extractMap(query); if (map.containsKey("state")) { request.setStateKey(map.get("state")); if (request.getPreservedState() == null) { String redirectUri = resource.getRedirectUri(request); if (redirectUri != null) { request.setPreservedState(redirectUri); } else { request.setPreservedState(new Object()); } } } String code = map.get("code"); if (code == null) { throw new UserRedirectRequiredException(location.toString(), form.toSingleValueMap()); } request.set("code", code); return code; }
From source file:org.n52.io.request.IoParameters.java
public IoParameters extendWith(String key, String... values) { MultiValueMap<String, String> newValues = new LinkedMultiValueMap<>(); newValues.put(key.toLowerCase(), Arrays.asList(values)); MultiValueMap<String, JsonNode> mergedValues = new LinkedMultiValueMap<>(query); mergedValues.putAll(convertValuesToJsonNodes(newValues)); return new IoParameters(mergedValues); }
From source file:de.zib.vold.userInterface.RESTController.java
/** * Handles Put requests.//from w ww.j a v a2 s.c om * * This method is used by clients to submit new keys. * * @param clientIpAddress The ip of the sending client, it's extracted from the request itself. * @param args The URL arguments of the request. //* @param argsbody The PUT body arguments of the request. * @param request Request informations * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured. */ @RequestMapping(method = RequestMethod.PUT) public ResponseEntity<Map<String, String>> insert(@ModelAttribute("clientIpAddress") String clientIpAddress, @RequestParam MultiValueMap<String, String> args, //@RequestBody MultiValueMap< String, String > argsbody, @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader, HttpServletRequest request) throws IOException { MultiValueMap<String, String> argsbody = getBody(); final long timeStamp; if (timeStampHeader.equals("unset")) timeStamp = DateTime.now().getMillis(); else timeStamp = Long.parseLong(timeStampHeader); // guard { if (argsbody != null) logger.debug("PUT: " + args.toString() + " AND " + argsbody.toString()); else logger.debug("PUT: " + args.toString()); checkState(); } Map<String, String> invalidKeys = new HashMap<String, String>(); // get actual scope String scope; { scope = request.getRequestURI(); String removepath = removePrefix + request.getContextPath() + request.getServletPath(); scope = scope.substring(removepath.length(), scope.length()); } // merge args to argsbody { if (null == argsbody) { if (null == args) { logger.warn("Got a totally empty request from " + clientIpAddress + "."); return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); } argsbody = args; } else if (null != args) { argsbody.putAll(args); } } // process each key { for (Map.Entry<String, List<String>> entry : argsbody.entrySet()) { URIKey urikey; String source; Key k; // build key { urikey = URIKey.fromURIString(entry.getKey(), enc); File path_correction = new File(scope + "/" + urikey.getKey().get_scope()); k = new Key(path_correction.getPath(), urikey.getKey().get_type(), urikey.getKey().get_keyname()); if (null == urikey.getSource()) { source = clientIpAddress; } else { source = urikey.getSource(); } } // handle write request for that key { try { logger.debug( "Inserting " + entry.getValue().size() + " values for key " + urikey.toURIString()); frontend.insert(source, k, new HashSet<String>(entry.getValue()), timeStamp); } catch (VoldException e) { logger.error("Could not handle write request for key " + entry.getKey() + ". ", e); invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage()); } } } } return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK); }
From source file:org.springframework.messaging.simp.stomp.StompDecoder.java
/** * Decode a single STOMP frame from the given {@code buffer} into a {@link Message}. *///from w w w. j a v a2 s . com @Nullable private Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap<String, String> headers) { Message<byte[]> decodedMessage = null; skipLeadingEol(byteBuffer); // Explicit mark/reset access via Buffer base type for compatibility // with covariant return type on JDK 9's ByteBuffer... Buffer buffer = byteBuffer; buffer.mark(); String command = readCommand(byteBuffer); if (command.length() > 0) { StompHeaderAccessor headerAccessor = null; byte[] payload = null; if (byteBuffer.remaining() > 0) { StompCommand stompCommand = StompCommand.valueOf(command); headerAccessor = StompHeaderAccessor.create(stompCommand); initHeaders(headerAccessor); readHeaders(byteBuffer, headerAccessor); payload = readPayload(byteBuffer, headerAccessor); } if (payload != null) { if (payload.length > 0) { StompCommand stompCommand = headerAccessor.getCommand(); if (stompCommand != null && !stompCommand.isBodyAllowed()) { throw new StompConversionException(stompCommand + " shouldn't have a payload: length=" + payload.length + ", headers=" + headers); } } headerAccessor.updateSimpMessageHeadersFromStompHeaders(); headerAccessor.setLeaveMutable(true); decodedMessage = MessageBuilder.createMessage(payload, headerAccessor.getMessageHeaders()); if (logger.isTraceEnabled()) { logger.trace("Decoded " + headerAccessor.getDetailedLogMessage(payload)); } } else { logger.trace("Incomplete frame, resetting input buffer..."); if (headers != null && headerAccessor != null) { String name = NativeMessageHeaderAccessor.NATIVE_HEADERS; @SuppressWarnings("unchecked") MultiValueMap<String, String> map = (MultiValueMap<String, String>) headerAccessor .getHeader(name); if (map != null) { headers.putAll(map); } } buffer.reset(); } } else { StompHeaderAccessor headerAccessor = StompHeaderAccessor.createForHeartbeat(); initHeaders(headerAccessor); headerAccessor.setLeaveMutable(true); decodedMessage = MessageBuilder.createMessage(HEARTBEAT_PAYLOAD, headerAccessor.getMessageHeaders()); if (logger.isTraceEnabled()) { logger.trace("Decoded " + headerAccessor.getDetailedLogMessage(null)); } } return decodedMessage; }
From source file:org.springframework.social.oauth1.SigningSupport.java
/** * Builds the authorization header./*w w w . ja v a 2 s . c o m*/ * The elements in additionalParameters are expected to not be encoded. */ public String buildAuthorizationHeaderValue(HttpMethod method, URI targetUrl, Map<String, String> oauthParameters, MultiValueMap<String, String> additionalParameters, String consumerSecret, String tokenSecret) { StringBuilder header = new StringBuilder(); header.append("OAuth "); for (Entry<String, String> entry : oauthParameters.entrySet()) { header.append(oauthEncode(entry.getKey())).append("=\"").append(oauthEncode(entry.getValue())) .append("\", "); } MultiValueMap<String, String> collectedParameters = new LinkedMultiValueMap<String, String>( (int) ((oauthParameters.size() + additionalParameters.size()) / .75 + 1)); collectedParameters.setAll(oauthParameters); collectedParameters.putAll(additionalParameters); String baseString = buildBaseString(method, getBaseStringUri(targetUrl), collectedParameters); String signature = calculateSignature(baseString, consumerSecret, tokenSecret); header.append(oauthEncode("oauth_signature")).append("=\"").append(oauthEncode(signature)).append("\""); return header.toString(); }