List of usage examples for org.springframework.util LinkedMultiValueMap LinkedMultiValueMap
public LinkedMultiValueMap()
From source file:com.miserablemind.api.consumer.tradeking.api.impl.WatchlistTemplate.java
@Override public String[] addSymbolsToList(String watchlistName, String[] tickers) { URI url = this.buildUri(String.format(URL_WATCHLIST_LIST_EDIT, watchlistName)); MultiValueMap<String, Object> requestObject = new LinkedMultiValueMap<>(); requestObject.add("symbols", this.buildCommaSeparatedParameterValue(tickers)); ResponseEntity<TKAllWatchListsResponse> response = this.getRestTemplate().postForEntity(url, requestObject, TKAllWatchListsResponse.class); if (response.getBody().getError() != null) throw new ApiException(TradeKingServiceProvider.PROVIDER_ID, response.getBody().getError()); return response.getBody().getWatchLists(); }
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 ww . j av a2s . c om*/ 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:com.ginema.ApplicationTests.java
@Test public void loginSucceeds() { ResponseEntity<String> response = template.getForEntity("http://localhost:" + port + "/ginema-server/login", String.class); String csrf = getCsrf(response.getBody()); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); form.set("username", "user"); form.set("password", "password"); form.set("_csrf", csrf); HttpHeaders headers = new HttpHeaders(); headers.put("COOKIE", response.getHeaders().get("Set-Cookie")); RequestEntity<MultiValueMap<String, String>> request = new RequestEntity<MultiValueMap<String, String>>( form, headers, HttpMethod.POST, URI.create("http://localhost:" + port + "/ginema-server/login")); ResponseEntity<Void> location = template.exchange(request, Void.class); assertEquals("http://localhost:" + port + "/ginema-server/", location.getHeaders().getFirst("Location")); }
From source file:org.cloudfoundry.identity.app.integration.AuthenticationIntegrationTests.java
@Test public void formLoginSucceeds() throws Exception { ResponseEntity<Void> result; String location;// ww w. j a v a 2 s . co m String cookie; HttpHeaders uaaHeaders = new HttpHeaders(); HttpHeaders appHeaders = new HttpHeaders(); uaaHeaders.setAccept(Arrays.asList(MediaType.TEXT_HTML)); appHeaders.setAccept(Arrays.asList(MediaType.TEXT_HTML)); // *** GET /app/id result = serverRunning.getForResponse("/id", appHeaders); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); cookie = result.getHeaders().getFirst("Set-Cookie"); assertNotNull("Expected cookie in " + result.getHeaders(), cookie); appHeaders.set("Cookie", cookie); assertTrue("Wrong location: " + location, location.contains("/oauth/authorize")); // *** GET /uaa/oauth/authorize result = serverRunning.getForResponse(location, uaaHeaders); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); cookie = result.getHeaders().getFirst("Set-Cookie"); assertNotNull("Expected cookie in " + result.getHeaders(), cookie); uaaHeaders.set("Cookie", cookie); assertTrue("Wrong location: " + location, location.contains("/login")); location = serverRunning.getAuthServerUrl("/login.do"); MultiValueMap<String, String> formData; formData = new LinkedMultiValueMap<String, String>(); formData.add("username", testAccounts.getUserName()); formData.add("password", testAccounts.getPassword()); // *** POST /uaa/login.do result = serverRunning.postForResponse(location, uaaHeaders, formData); cookie = result.getHeaders().getFirst("Set-Cookie"); assertNotNull("Expected cookie in " + result.getHeaders(), cookie); uaaHeaders.set("Cookie", cookie); assertEquals(HttpStatus.FOUND, result.getStatusCode()); location = result.getHeaders().getLocation().toString(); assertTrue("Wrong location: " + location, location.contains("/oauth/authorize")); // *** GET /uaa/oauth/authorize result = serverRunning.getForResponse(location, uaaHeaders); // If there is no token in place already for this client we get the approval page. // TODO: revoke the token so we always get the approval page if (result.getStatusCode() == HttpStatus.OK) { location = serverRunning.getAuthServerUrl("/oauth/authorize"); formData = new LinkedMultiValueMap<String, String>(); formData.add("user_oauth_approval", "true"); // *** POST /uaa/oauth/authorize result = serverRunning.postForResponse(location, uaaHeaders, formData); } location = result.getHeaders().getLocation().toString(); // SUCCESS assertTrue("Wrong location: " + location, location.contains("/id")); // *** GET /app/id result = serverRunning.getForResponse(location, appHeaders); // System.err.println(result.getHeaders()); assertEquals(HttpStatus.OK, result.getStatusCode()); }
From source file:org.ihtsdo.otf.refset.security.RefsetIdentityService.java
protected UserDetails authenticate(String userName, String token) { LOGGER.debug("Authenticating user {} ", userName); User user = getGuestUser();//from w w w.j a v a 2s. c o m MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("username", userName); params.add("password", token); params.add("queryName", "getUserByNameAuth"); try { if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(token)) { throw new AccessDeniedException("User is unauthorized. Please check user name and password"); } Assert.notNull(rt, "Rest template can not be empty"); LOGGER.debug("Calling authentication service with URL {}, User {} and Parameters {} ", otfServiceUrl, userName); JsonNode obj = rt.postForObject(otfServiceUrl, params, JsonNode.class); LOGGER.debug("authentication service call successfully returned with {} ", obj); //populate user with other user details populateUser(user, obj); //now check if user has access to Refset app. params = new LinkedMultiValueMap<String, String>(); params.add("username", userName); params.add("queryName", "getUserApps"); LOGGER.debug("Calling autorization service with URL {}, User {} and Parameters {} ", otfServiceUrl, userName); JsonNode appJson = rt.postForObject(otfServiceUrl, params, JsonNode.class); LOGGER.debug("autorization service call successfully returned with {} ", appJson); JsonNode apps = appJson.get("apps"); Collection<RefsetRole> roles = new ArrayList<RefsetRole>(); for (JsonNode object : apps) { if (object != null && object.asText().equals(APP_NAME)) { RefsetRole role = new RefsetRole(); role.setAuthority(ROLE_USER); roles.add(role); break; } } user.setAuthorities(roles); if (isUserHasRole(user)) { String info = userName + ":" + token; Token key = service.allocateToken(info); user.setToken(key.getKey()); } } catch (Exception e) { LOGGER.error("Error during authentication for user:password - {} ", userName + ":" + token, e); throw new AccessDeniedException("User is unauthorized. Please check user name and password"); } return user; }
From source file:com.jiwhiz.domain.account.impl.ConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findAllConnections() { List<UserSocialConnection> userSocialConnectionList = userSocialConnectionRepository.findByUserId(userId); MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<String, Connection<?>>(); Set<String> registeredProviderIds = socialAuthenticationServiceLocator.registeredProviderIds(); for (String registeredProviderId : registeredProviderIds) { connections.put(registeredProviderId, Collections.<Connection<?>>emptyList()); }/*from ww w.j a va 2 s . c om*/ for (UserSocialConnection userSocialConnection : userSocialConnectionList) { String providerId = userSocialConnection.getProviderId(); if (connections.get(providerId).size() == 0) { connections.put(providerId, new LinkedList<Connection<?>>()); } connections.add(providerId, buildConnection(userSocialConnection)); } return connections; }
From source file:com.jiwhiz.domain.account.impl.MongoConnectionRepositoryImpl.java
public MultiValueMap<String, Connection<?>> findAllConnections() { List<UserSocialConnection> userSocialConnectionList = this.userSocialConnectionRepository .findByUserId(userId);/*from w ww . j a v a 2 s . c o m*/ MultiValueMap<String, Connection<?>> connections = new LinkedMultiValueMap<String, Connection<?>>(); Set<String> registeredProviderIds = socialAuthenticationServiceLocator.registeredProviderIds(); for (String registeredProviderId : registeredProviderIds) { connections.put(registeredProviderId, Collections.<Connection<?>>emptyList()); } for (UserSocialConnection userSocialConnection : userSocialConnectionList) { String providerId = userSocialConnection.getProviderId(); if (connections.get(providerId).size() == 0) { connections.put(providerId, new LinkedList<Connection<?>>()); } connections.add(providerId, buildConnection(userSocialConnection)); } return connections; }
From source file:org.kurento.repository.test.util.HttpRepositoryTest.java
protected void uploadFileWithMultiparts(String uploadURL, File fileToUpload) { RestTemplate template = getRestTemplate(); MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>(); parts.add("file", new FileSystemResource(fileToUpload)); ResponseEntity<String> entity = postWithRetries(uploadURL, template, parts); assertEquals("Returned response: " + entity.getBody(), HttpStatus.OK, entity.getStatusCode()); }
From source file:org.cloudfoundry.identity.uaa.integration.NativeApplicationIntegrationTests.java
/** * tests that an error occurs if you attempt to use bad client credentials. *//*from ww w . ja v a 2s .c o m*/ @Test // Need a custom auth entry point to get the correct JSON response here. public void testInvalidClient() throws Exception { MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>(); formData.add("grant_type", "password"); formData.add("username", resource.getUsername()); formData.add("password", resource.getPassword()); formData.add("scope", "cloud_controller.read"); HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", "Basic " + new String(Base64.encode("no-such-client:".getBytes("UTF-8")))); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/oauth/token", formData, headers); assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); List<String> newCookies = response.getHeaders().get("Set-Cookie"); if (newCookies != null && !newCookies.isEmpty()) { fail("No cookies should be set. Found: " + newCookies.get(0) + "."); } assertEquals("no-store", response.getHeaders().getFirst("Cache-Control")); @SuppressWarnings("unchecked") OAuth2Exception error = OAuth2Exception.valueOf(response.getBody()); assertEquals("invalid_client", error.getOAuth2ErrorCode()); }