List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap
public LinkedMultiValueMap()
From source file:org.cloudfoundry.identity.uaa.provider.saml.LoginSamlAuthenticationProvider.java
public MultiValueMap<String, String> retrieveUserAttributes(SamlIdentityProviderDefinition definition, SAMLCredential credential) {// ww w. j av a 2 s. c om logger.debug(String.format("Retrieving SAML user attributes [zone:%s, origin:%s]", definition.getZoneId(), definition.getIdpEntityAlias())); MultiValueMap<String, String> userAttributes = new LinkedMultiValueMap<>(); if (definition != null && definition.getAttributeMappings() != null) { for (Entry<String, Object> attributeMapping : definition.getAttributeMappings().entrySet()) { if (attributeMapping.getValue() instanceof String) { if (credential.getAttribute((String) attributeMapping.getValue()) != null) { String key = attributeMapping.getKey(); for (XMLObject xmlObject : credential.getAttribute((String) attributeMapping.getValue()) .getAttributeValues()) { String value = getStringValue(key, definition, xmlObject); if (value != null) { userAttributes.add(key, value); } } } } } } if (credential.getAuthenticationAssertion() != null && credential.getAuthenticationAssertion().getAuthnStatements() != null) { for (AuthnStatement statement : credential.getAuthenticationAssertion().getAuthnStatements()) { if (statement.getAuthnContext() != null && statement.getAuthnContext().getAuthnContextClassRef() != null) { userAttributes.add(AUTHENTICATION_CONTEXT_CLASS_REFERENCE, statement.getAuthnContext().getAuthnContextClassRef().getAuthnContextClassRef()); } } } return userAttributes; }
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 ww w .ja v a 2 s .c o 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 ww w . j a v a 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); }/*w w w . ja v a2 s . c om*/ }
From source file:org.encuestame.oauth1.support.OAuth1Support.java
/** * * @param tokenUrl/*from w w w . j ava2 s . co m*/ * @param tokenRequestParameters * @param additionalParameters * @param tokenSecret * @return * @throws EnMeOAuthSecurityException */ protected OAuth1Token getTokenFromProvider(String tokenUrl, Map<String, String> tokenRequestParameters, Map<String, String> additionalParameters, String tokenSecret) throws EnMeOAuthSecurityException { log.debug("getTokenFromProvider TOKEN " + tokenUrl); log.debug("getTokenFromProvider TOKEN " + tokenRequestParameters); log.debug("getTokenFromProvider TOKEN " + additionalParameters); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", getAuthorizationHeaderValue(tokenUrl, tokenRequestParameters, additionalParameters, tokenSecret)); MultiValueMap<String, String> bodyParameters = new LinkedMultiValueMap<String, String>(); bodyParameters.setAll(additionalParameters); HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>( bodyParameters, headers); Map<String, String> responseMap = null; /* * org.springframework.web.client.HttpServerErrorException: 503 Service Unavailable * Sometimes, api service are unavailable, like the famous twitter over capacity */ try { ResponseEntity<String> response = getRestTemplate().exchange(tokenUrl, HttpMethod.POST, request, String.class); responseMap = parseResponse(response.getBody()); } catch (HttpServerErrorException e) { e.printStackTrace(); throw new EnMeOAuthSecurityException(e); } catch (HttpClientErrorException e) { // normally if the social credentials are wrong e.printStackTrace(); throw new EnMeBadCredentialsException(e.getMessage()); } catch (Exception e) { // another kind of error, possible wrong configuration //TODO : only happends with twitter e.printStackTrace(); throw new EnMeBadCredentialsException(e.getMessage()); } return new OAuth1Token(responseMap.get("oauth_token"), responseMap.get("oauth_token_secret")); }
From source file:org.encuestame.oauth2.support.OAuth2Support.java
public AccessGrant exchangeForAccess(String authorizationCode, String redirectUri) { log.debug("exchangeForAccess:{" + authorizationCode); log.debug("exchangeForAccess redirectUri{: " + redirectUri); MultiValueMap<String, String> requestParameters = new LinkedMultiValueMap<String, String>(); requestParameters.set("client_id", clientId); requestParameters.set("client_secret", clientSecret); requestParameters.set("code", authorizationCode); requestParameters.set("redirect_uri", redirectUri); requestParameters.set("grant_type", "authorization_code"); log.debug("requestParameters " + requestParameters.toString()); Map result = getRestTemplate().postForObject(accessTokenUrl, requestParameters, Map.class); log.debug("Access Grant " + result.toString()); return new AccessGrant(valueOf(result.get("access_token")), valueOf(result.get("refresh_token"))); }
From source file:org.encuestame.oauth2.support.OAuth2Support.java
/** * * @param refreshToken//from w ww . ja va2 s .c om * @return */ public AccessGrant refreshToken(final String refreshToken) { log.debug("refreshToken" + refreshToken); MultiValueMap<String, String> requestParameters = new LinkedMultiValueMap<String, String>(); requestParameters.set("client_id", clientId); requestParameters.set("client_secret", clientSecret); requestParameters.set("refresh_token", refreshToken); requestParameters.set("grant_type", "refresh_token"); log.debug("requestParameters " + requestParameters.toString()); @SuppressWarnings("unchecked") Map<String, ?> result = getRestTemplate().postForObject(accessTokenUrl, requestParameters, Map.class); log.debug(result); return new AccessGrant(valueOf(result.get("access_token")), refreshToken); }
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 w w w . j ava 2 s . co 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.encuestame.social.api.templates.FacebookAPITemplate.java
public TweetPublishedMetadata updateStatus(final String message) { log.debug("facebook message to publish: " + message); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.set("message", message); return this.publish(CURRENT_USER_ID, FEED, map); }
From source file:org.encuestame.social.api.templates.FacebookAPITemplate.java
public void updateStatus(String message, FacebookLink link) { MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.set("link", link.getLink()); map.set("name", link.getName()); map.set("caption", link.getCaption()); map.set("description", link.getDescription()); map.set("message", message); this.publish(CURRENT_USER_ID, FEED, map); }