List of usage examples for org.springframework.util MultiValueMap add
void add(K key, @Nullable V value);
From source file:org.apigw.util.OAuthTestHelper.java
public String getAuthorizationCode(String clientId, String redirectUri, String scope) { String cookie = loginAndGetConfirmationPage(clientId, redirectUri, scope); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); headers.set("Cookie", cookie); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("user_oauth_approval", "true"); ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/oauth/authorize", headers, formData);// ww w . j a va 2s. c o m assertEquals(HttpStatus.FOUND, result.getStatusCode()); // Get the authorization code using the same session return getAuthorizationCode(result); }
From source file:org.apigw.util.OAuthTestHelper.java
private MultiValueMap<String, String> getTokenFormData(String clientId, String redirectUri, String code, String scope) {// ww w.jav a 2 s . c om MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("grant_type", "authorization_code"); formData.add("client_id", clientId); formData.add("scope", scope); formData.add("redirect_uri", redirectUri); formData.add("state", "gzzFqB!!!"); if (code != null) { formData.add("code", code); } return formData; }
From source file:com.netflix.genie.web.security.oauth2.pingfederate.PingFederateRemoteTokenServices.java
/** * {@inheritDoc}// w w w .j ava 2s . co m */ @Override public OAuth2Authentication loadAuthentication(final String accessToken) throws AuthenticationException, InvalidTokenException { final long start = System.nanoTime(); try { final MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add(TOKEN_NAME_KEY, accessToken); formData.add(CLIENT_ID_KEY, this.clientId); formData.add(CLIENT_SECRET_KEY, this.clientSecret); formData.add(GRANT_TYPE_KEY, GRANT_TYPE); final Map<String, Object> map = this.postForMap(this.checkTokenEndpointUrl, formData); if (map.containsKey(ERROR_KEY)) { final String error = map.get(ERROR_KEY).toString(); log.debug("Validating the token produced an error: {}", error); throw new InvalidTokenException(error); } Assert.state(map.containsKey(CLIENT_ID_KEY), "Client id must be present in response from auth server"); Assert.state(map.containsKey(SCOPE_KEY), "No scopes included in response from authentication server"); this.convertScopes(map); final OAuth2Authentication authentication = this.converter.extractAuthentication(map); log.info("User {} authenticated with authorities {}", authentication.getPrincipal(), authentication.getAuthorities()); return authentication; } finally { final long finished = System.nanoTime(); this.authenticationTimer.record(finished - start, TimeUnit.NANOSECONDS); } }
From source file:com.seajas.search.codex.service.social.SocialFacade.java
@Override @Cacheable("facebookPageSearchCache") public List<Reference> searchFacebookPages(final String person) { MultiValueMap<String, String> queryMap = new LinkedMultiValueMap<String, String>(); queryMap.add("q", person); queryMap.add("type", "page"); return getFacebookTemplate().fetchConnections("search", null, Reference.class, queryMap); }
From source file:com.github.wnameless.spring.bulkapi.DefaultBulkApiService.java
private RequestEntity<MultiValueMap<String, Object>> requestEntity(BodyBuilder bodyBuilder, BulkOperation op) { for (Entry<String, String> header : op.getHeaders().entrySet()) { bodyBuilder.header(header.getKey(), header.getValue()); }//from w w w . j a v a 2 s. c o m MultiValueMap<String, Object> params = new LinkedMultiValueMap<String, Object>(); for (Entry<String, ?> param : op.getParams().entrySet()) { params.add(param.getKey(), param.getValue()); } return bodyBuilder.body(params); }
From source file:fr.itldev.koya.services.impl.AlfrescoRestService.java
@Override public AlfrescoUploadReturn uploadToXpathNode(User user, Resource resource, String parentXPath) throws AlfrescoServiceException { MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>(); parts.add("filedata", resource); parts.add("destination", xPathToNodeRef(user, parentXPath)); parts.add("overwrite", "true"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers); return fromJSON(new TypeReference<AlfrescoUploadReturn>() { }, user.getRestTemplate().postForObject(getAlfrescoServerUrl() + REST_POST_UPLOAD, request, String.class)); }
From source file:org.apigw.util.OAuthTestHelper.java
private String loginAndGrabCookie() { HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.TEXT_HTML)); MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("j_username", username); formData.add("j_password", password); // Should be redirected to the original URL, but now authenticated ResponseEntity<Void> result = serverRunning.postForStatus("/apigw-auth-server-web/login.do", headers, formData);// w ww . j a v a2 s . c o m assertEquals(HttpStatus.FOUND, result.getStatusCode()); assertTrue(result.getHeaders().containsKey("Set-Cookie")); return result.getHeaders().getFirst("Set-Cookie"); }
From source file:com.marklogic.mgmt.admin.AdminManager.java
/** * Set whether SSL FIPS is enabled on the cluster or not by running against /v1/eval on the given appServicesPort. *//*from w w w . j a va 2s .c o m*/ public void setSslFipsEnabled(final boolean enabled, final int appServicesPort) { final String xquery = "import module namespace admin = 'http://marklogic.com/xdmp/admin' at '/MarkLogic/admin.xqy'; " + "admin:save-configuration(admin:cluster-set-ssl-fips-enabled(admin:get-configuration(), " + enabled + "()))"; invokeActionRequiringRestart(new ActionRequiringRestart() { @Override public boolean execute() { RestTemplate rt = RestTemplateUtil.newRestTemplate(adminConfig.getHost(), appServicesPort, adminConfig.getUsername(), adminConfig.getPassword()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); map.add("xquery", xquery); HttpEntity<MultiValueMap<String, String>> entity = new HttpEntity<MultiValueMap<String, String>>( map, headers); String url = format("http://%s:%d/v1/eval", adminConfig.getHost(), appServicesPort); if (logger.isInfoEnabled()) { logger.info("Setting SSL FIPS enabled: " + enabled); } rt.exchange(url, HttpMethod.POST, entity, String.class); if (logger.isInfoEnabled()) { logger.info("Finished setting SSL FIPS enabled: " + enabled); } return true; } }); }
From source file:org.cloudfoundry.identity.uaa.login.feature.AutologinIT.java
@Test public void testFormEncodedAutologinRequest() throws Exception { HttpHeaders headers = getAppBasicAuthHttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>(); requestBody.add("username", testAccounts.getUserName()); requestBody.add("password", testAccounts.getPassword()); ResponseEntity<Map> autologinResponseEntity = restOperations.exchange(baseUrl + "/autologin", HttpMethod.POST, new HttpEntity<>(requestBody, headers), Map.class); String autologinCode = (String) autologinResponseEntity.getBody().get("code"); assertEquals(6, autologinCode.length()); }