List of usage examples for org.springframework.util MultiValueMap add
void add(K key, @Nullable V value);
From source file:org.cloudfoundry.identity.uaa.provider.saml.LoginSamlAuthenticationProvider.java
protected UaaUser createIfMissing(UaaPrincipal samlPrincipal, boolean addNew, Collection<? extends GrantedAuthority> authorities, MultiValueMap<String, String> userAttributes) { UaaUser user = null;//from w w w .jav a 2 s .c o m String invitedUserId = null; boolean is_invitation_acceptance = isAcceptedInvitationAuthentication(); if (is_invitation_acceptance) { invitedUserId = (String) RequestContextHolder.currentRequestAttributes().getAttribute("user_id", RequestAttributes.SCOPE_SESSION); user = userDatabase.retrieveUserById(invitedUserId); if (userAttributes.getFirst(EMAIL_ATTRIBUTE_NAME) != null) { if (!userAttributes.getFirst(EMAIL_ATTRIBUTE_NAME).equalsIgnoreCase(user.getEmail())) { throw new BadCredentialsException( "SAML User email mismatch. Authenticated email doesn't match invited email."); } } else { userAttributes = new LinkedMultiValueMap<>(userAttributes); userAttributes.add(EMAIL_ATTRIBUTE_NAME, user.getEmail()); } addNew = false; if (user.getUsername().equals(user.getEmail()) && !user.getUsername().equals(samlPrincipal.getName())) { user.setVerified(true); user = user.modifyUsername(samlPrincipal.getName()); } publish(new InvitedUserAuthenticatedEvent(user)); user = userDatabase.retrieveUserById(invitedUserId); } boolean userModified = false; UaaUser userWithSamlAttributes = getUser(samlPrincipal, userAttributes); try { if (user == null) { user = userDatabase.retrieveUserByName(samlPrincipal.getName(), samlPrincipal.getOrigin()); } } catch (UsernameNotFoundException e) { UaaUser uaaUser = userDatabase.retrieveUserByEmail(userWithSamlAttributes.getEmail(), samlPrincipal.getOrigin()); if (uaaUser != null) { user = uaaUser.modifyUsername(samlPrincipal.getName()); } else { if (!addNew) { throw new LoginSAMLException("SAML user does not exist. " + "You can correct this by creating a shadow user for the SAML user.", e); } // Register new users automatically publish(new NewUserAuthenticatedEvent(userWithSamlAttributes)); try { user = userDatabase.retrieveUserByName(samlPrincipal.getName(), samlPrincipal.getOrigin()); } catch (UsernameNotFoundException ex) { throw new BadCredentialsException( "Unable to establish shadow user for SAML user:" + samlPrincipal.getName()); } } } if (haveUserAttributesChanged(user, userWithSamlAttributes)) { userModified = true; user = user.modifyAttributes(userWithSamlAttributes.getEmail(), userWithSamlAttributes.getGivenName(), userWithSamlAttributes.getFamilyName(), userWithSamlAttributes.getPhoneNumber()); } publish(new ExternalGroupAuthorizationEvent(user, userModified, authorities, true)); user = userDatabase.retrieveUserById(user.getId()); UaaPrincipal result = new UaaPrincipal(user); Authentication success = new UaaAuthentication(result, user.getAuthorities(), null); publish(new UserAuthenticationSuccessEvent(user, success)); return user; }
From source file:org.craftercms.commons.http.HttpUtils.java
/** * Returns a map with the extracted parameters from the specified query string. A multi value map is used * since there can be several values for the same param. * * @param queryString the query string to extract the params from * @return the param map/*from w w w.j a va 2 s .co m*/ */ @SuppressWarnings("unchecked") public static MultiValueMap<String, String> getParamsFromQueryString(String queryString) { MultiValueMap queryParams = new LinkedMultiValueMap<>(); if (StringUtils.isNotEmpty(queryString)) { String[] params = queryString.split("&"); for (String param : params) { String[] splitParam = param.split("="); String paramName = splitParam[0]; String paramValue = splitParam[1]; queryParams.add(paramName, paramValue); } } return queryParams; }
From source file:org.craftercms.profile.services.impl.ProfileServiceRestClient.java
@Override public ProfileAttachment addProfileAttachment(String profileId, String attachmentName, InputStream file) throws ProfileException { MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); params.add(PARAM_ACCESS_TOKEN_ID, accessTokenIdResolver.getAccessTokenId()); params.add(PARAM_FILENAME, attachmentName); String url = getAbsoluteUrl(BASE_URL_PROFILE + URL_PROFILE_UPLOAD_ATTACHMENT); File tmpFile = null;//from www . j a va 2s .c o m try { tmpFile = File.createTempFile(profileId + "-" + attachmentName, "attachment"); FileUtils.copyInputStreamToFile(file, tmpFile); params.add("attachment", new FileSystemResource(tmpFile)); return doPostForUpload(url, params, ProfileAttachment.class, profileId); } catch (IOException e) { throw new I10nProfileException(ERROR_KEY_TMP_COPY_FAILED, e, attachmentName, profileId); } finally { try { file.close(); FileUtils.forceDelete(tmpFile); } catch (Throwable e) { } } }
From source file:org.egov.mrs.domain.service.MarriageRegistrationService.java
private void sendMarriageCertificate(final MarriageRegistration marriageRegistration) { MarriageCertificate marriageCertificate = marriageCertificateService .getGeneratedCertificate(marriageRegistration); if (marriageCertificate != null) { final RestTemplate restTemplate = new RestTemplate(); MultiValueMap<String, Object> requestObjectMap = new LinkedMultiValueMap<>(); HttpHeaders headers = new HttpHeaders(); File file = fileStoreService.fetch(marriageCertificate.getFileStore().getFileStoreId(), MarriageConstants.FILESTORE_MODULECODE); requestObjectMap.add("certificate", new FileSystemResource(file)); requestObjectMap.add("ApplicationKey", marriageMessageSource.getMessage("mrs.cpk.apikey", null, null)); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, Object>> requestObj = new HttpEntity<>(requestObjectMap, headers); restTemplate.postForObject(CPK_END_POINT_URL + marriageRegistration.getApplicationNo(), requestObj, String.class); }//from w w w.j a v a2 s . c o m }
From source file:org.encuestame.social.api.IdenticaAPITemplate.java
public TweetPublishedMetadata updateStatus(final String message, final IdenticaStatusDetails details) { log.debug("Identica updateStatus 1 " + message); log.debug("Identica updateStatus 1 " + details); final MultiValueMap<String, Object> tweetParams = new LinkedMultiValueMap<String, Object>(); tweetParams.add("status", message); tweetParams.setAll(details.toParameterMap()); final ResponseEntity<Map> response = getRestTemplate().postForEntity(TWEET_URL, tweetParams, Map.class); /**//from www . jav a 2 s. c o m * {text=fdfasfasfadfa fas fa fda sfda dsadsads http://tinyurl.com/3p3fs2a dasdsadsa http://tinyurl.com/4xnfgws #dasdsaas, * truncated=false, created_at=Sun May 22 23:30:03 +0000 2011, in_reply_to_status_id=null, * source=<a href="http://www.encuestame.org" rel="nofollow">encuestame</a>, * ---ID STATUS----> id=74199692, * in_reply_to_user_id=null, in_reply_to_screen_name=null, geo=null, * favorited=false, attachments=[], user={id=423318, name=jpicado, screen_name=jpicado, * location=null, description=null, profile_image_url=http://theme.identi.ca/0.9.7/identica/default-avatar-stream.png, * url=null, protected=false, followers_count=0, profile_background_color=, * profile_text_color=, profile_link_color=, profile_sidebar_fill_color=, * profile_sidebar_border_color=, friends_count=2, created_at=Thu Apr 21 23:15:53 +0000 2011, * favourites_count=0, utc_offset=0, time_zone=UTC, profile_background_image_url=, * profile_background_tile=false, statuses_count=40, following=true, statusnet:blocking=false, * notifications=true, statusnet_profile_url=http://identi.ca/jpicado}, * statusnet_html=fdfasfasfadfa fas fa fda sfda dsadsads <a href="http://tinyurl.com/3p3fs2a" * title="http://tinyurl.com/3p3fs2a" rel="nofollow external">http://tinyurl.com/3p3fs2a</a> dasdsadsa * <a href="http://tinyurl.com/4xnfgws" title="http://tinyurl.com/4xnfgws" * rel="nofollow external">http://tinyurl.com/4xnfgws</a> #<span class="tag"> * <a href="http://identi.ca/tag/dasdsaas" rel="tag">dasdsaas</a></span>} */ log.debug("Identica updateStatus " + response.getBody()); log.debug("Identica updateStatus " + response.getHeaders()); log.debug("Identica updateStatus " + response.getStatusCode()); final Map body = response.getBody(); //this.handleIdentiCaResponseErrors(response); final TweetPublishedMetadata status = createStatus(message); status.setTweetId(body.get("id").toString()); return status; }
From source file:org.fao.geonet.services.resources.handlers.DefaultResourceDownloadHandler.java
public HttpEntity<byte[]> onDownload(ServiceContext context, NativeWebRequest request, int metadataId, String fileName, Path file) throws ResourceHandlerException { try {/*from w ww. j av a 2s. c om*/ String requesterName = getParam(request, "name", ""); String requesterMail = getParam(request, "email", ""); String requesterOrg = getParam(request, "org", ""); String requesterComments = getParam(request, "comments", ""); // Store download request for statistics String downloadDate = new ISODate().toString(); storeFileDownloadRequest(context, metadataId, fileName, requesterName, requesterMail, requesterOrg, requesterComments, downloadDate); if (Files.exists(file) && request.checkNotModified(Files.getLastModifiedTime(file).toMillis())) { return null; } MultiValueMap<String, String> headers = new HttpHeaders(); headers.add("Content-Disposition", "inline; filename=\"" + fileName + "\""); headers.add("Cache-Control", "no-cache"); headers.add("Content-Type", getFileContentType(file)); return new HttpEntity<>(Files.readAllBytes(file), headers); } catch (Exception ex) { Log.error(Geonet.RESOURCES, "DefaultResourceDownloadHandler (onDownload): " + ex.getMessage(), ex); throw new ResourceHandlerException(ex); } }
From source file:org.fenixedu.bennu.social.domain.api.BitbucketAPI.java
public HttpEntity<MultiValueMap<String, String>> getAccessTokenRequest(String code) { MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("grant_type", "authorization_code"); map.add("code", code); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); String plainCreds = getClientId() + ":" + getClientSecret(); byte[] plainCredsBytes = plainCreds.getBytes(); byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); String base64Creds = new String(base64CredsBytes); headers.add("Authorization", "Basic " + base64Creds); return new HttpEntity<MultiValueMap<String, String>>(map, headers); }
From source file:org.geoserver.importer.rest.ImportTaskControllerTest.java
private Integer putZipAsURL(String zip) throws Exception { MockHttpServletResponse resp = postAsServletResponse(RestBaseController.ROOT_PATH + "/imports", ""); assertEquals(201, resp.getStatus()); assertNotNull(resp.getHeader("Location")); String[] split = resp.getHeader("Location").split("/"); Integer id = Integer.parseInt(split[split.length - 1]); ImportContext context = importer.getContext(id); MockHttpServletRequest req = createRequest(RestBaseController.ROOT_PATH + "/imports/" + id + "/tasks/"); MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>(1); form.add("url", new File(zip).getAbsoluteFile().toURI().toString()); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final HttpHeaders headers = new HttpHeaders(); new FormHttpMessageConverter().write(form, MediaType.APPLICATION_FORM_URLENCODED, new HttpOutputMessage() { @Override// ww w. jav a2 s . c o m public OutputStream getBody() throws IOException { return stream; } @Override public HttpHeaders getHeaders() { return headers; } }); req.setContent(stream.toByteArray()); req.setMethod("POST"); req.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE); req.addHeader("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); resp = dispatch(req); assertEquals(201, resp.getStatus()); context = importer.getContext(context.getId()); assertNull(context.getData()); assertEquals(1, context.getTasks().size()); ImportTask task = context.getTasks().get(0); assertTrue(task.getData() instanceof SpatialFile); return id; }
From source file:org.jahia.services.render.webflow.MultipartResolver.java
@Override protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException { FileUpload fileUpload = (FileUpload) request.getAttribute(FileUpload.FILEUPLOAD_ATTRIBUTE); List<FileItem> fileItems = new ArrayList<FileItem>(fileUpload.getFileItems().values()); MultiValueMap<String, MultipartFile> multipartFiles = new LinkedMultiValueMap<String, MultipartFile>(); Map<String, String> multipartParameterContentTypes = new HashMap<String, String>(); for (FileItem fileItem : fileItems) { CommonsMultipartFile file = new CommonsMultipartFile(fileItem); multipartFiles.add(fileItem.getFieldName(), file); }/*from w w w .j av a 2s .com*/ Map<String, String[]> multipartParameters = new HashMap<String, String[]>(); for (String param : fileUpload.getParameterNames()) { if (!request.getQueryString().contains("&" + param + "=") && !request.getQueryString().startsWith(param + "=")) { multipartParameters.put(param, fileUpload.getParameterValues(param)); multipartParameterContentTypes.put(param, fileUpload.getParameterContentType(param)); } } return new MultipartParsingResult(multipartFiles, multipartParameters, multipartParameterContentTypes); }
From source file:org.kaaproject.kaa.sandbox.rest.SandboxClient.java
public String buildProjectBinary(String projectId) { MultiValueMap<String, String> request = new LinkedMultiValueMap<>(); request.add("projectId", projectId); request.add("dataType", "BINARY"); byte[] result = restTemplate.postForObject(url + "buildProjectData", request, byte[].class); return new String(result); }