List of usage examples for org.springframework.util LinkedMultiValueMap add
@Override public void add(K key, @Nullable V value)
From source file:org.cloudfoundry.identity.uaa.integration.RefreshTokenSupportIntegrationTests.java
@Test public void testRefreshTokenWithNonExistingZone() { LinkedMultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("grant_type", "refresh_token"); formData.add("refresh_token", "dummyrefreshtoken-r"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap( serverRunning.getAccessTokenUri().replace("localhost", "testzonedoesnotexist.localhost"), formData, new HttpHeaders()); assertEquals(HttpStatus.NOT_FOUND, tokenResponse.getStatusCode()); }
From source file:org.cloudfoundry.identity.uaa.integration.RefreshTokenSupportIntegrationTests.java
@Test public void testRefreshTokenWithInactiveZone() { RestTemplate identityClient = IntegrationTestUtils.getClientCredentialsTemplate( IntegrationTestUtils.getClientCredentialsResource(serverRunning.getBaseUrl(), new String[] { "zones.write", "zones.read", "scim.zones" }, "identity", "identitysecret")); IntegrationTestUtils.createInactiveIdentityZone(identityClient, "http://localhost:8080/uaa"); LinkedMultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("grant_type", "refresh_token"); formData.add("refresh_token", "dummyrefreshtoken-r"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap( serverRunning.getAccessTokenUri().replace("localhost", "testzoneinactive.localhost"), formData, new HttpHeaders()); assertEquals(HttpStatus.NOT_FOUND, tokenResponse.getStatusCode()); }
From source file:org.cloudfoundry.identity.uaa.integration.RemoteAuthenticationEndpointTests.java
private String getScimReadBearerToken() { HttpHeaders accessTokenHeaders = new HttpHeaders(); String basicDigestHeaderValue = "Basic " + new String(Base64.encodeBase64( (testAccounts.getAdminClientId() + ":" + testAccounts.getAdminClientSecret()).getBytes())); accessTokenHeaders.add("Authorization", basicDigestHeaderValue); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("grant_type", "client_credentials"); params.add("client_id", testAccounts.getAdminClientId()); params.add("scope", "scim.read"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, accessTokenHeaders);// w ww . j a v a 2 s . c o m return (String) tokenResponse.getBody().get("access_token"); }
From source file:org.cloudfoundry.identity.uaa.integration.RemoteAuthenticationEndpointTests.java
private String getLoginReadBearerToken() { HttpHeaders accessTokenHeaders = new HttpHeaders(); String basicDigestHeaderValue = "Basic " + new String(Base64.encodeBase64(("login:loginsecret").getBytes())); accessTokenHeaders.add("Authorization", basicDigestHeaderValue); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("grant_type", "client_credentials"); params.add("client_id", "login"); params.add("scope", "oauth.login"); ResponseEntity<Map> tokenResponse = serverRunning.postForMap(serverRunning.getAccessTokenUri(), params, accessTokenHeaders);// www . j a va2 s .co m return (String) tokenResponse.getBody().get("access_token"); }
From source file:org.jgrades.rest.client.lic.LicenceManagerServiceClient.java
@Override public Licence uploadAndInstall(MultipartFile licence, MultipartFile signature) throws IOException { Resource licenceResource = getResource(licence); Resource signatureResource = getResource(signature); try {/*w w w.j a va 2 s . com*/ String serviceUrl = backendBaseUrl + "/licence"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); LinkedMultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); params.add("licence", licenceResource); params.add("signature", signatureResource); HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); ResponseEntity<Licence> response = restTemplate.exchange(serviceUrl, HttpMethod.POST, requestEntity, Licence.class); return response.getBody(); } finally { FileUtils.deleteQuietly(licenceResource.getFile()); FileUtils.deleteQuietly(signatureResource.getFile()); } }
From source file:org.pesc.cds.web.TranscriptRequestController.java
private void sendDocument(File outboxFile, String endpointURI, Transaction tx, String fileFormat, String documentType, String department) throws IOException { byte[] fileSignature = pkiService.createDigitalSignature(new FileInputStream(outboxFile), pkiService.getSigningKeys().getPrivate()); try {/*from ww w . ja v a 2s . c om*/ LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); map.add("recipient_id", tx.getRecipientId()); map.add("sender_id", tx.getSenderId()); map.add("signer_id", localServerId); map.add("file_format", fileFormat); map.add("document_type", documentType); map.add("department", department); map.add("transaction_id", tx.getId()); map.add("ack_url", localServerWebServiceURL); map.add("file", new FileSystemResource(outboxFile)); map.add("signature", new ByteArrayResource(fileSignature) { @Override public String getFilename() { return "signature.dat"; } }); org.springframework.http.HttpHeaders headers = new org.springframework.http.HttpHeaders(); headers.setContentType(org.springframework.http.MediaType.MULTIPART_FORM_DATA); ResponseEntity<String> response = restTemplate.exchange(endpointURI, HttpMethod.POST, new org.springframework.http.HttpEntity<Object>(map, headers), String.class); if (response.getStatusCode() != HttpStatus.OK) { throw new IllegalArgumentException( "Failed to send document. Reason: " + response.getStatusCode().getReasonPhrase()); } log.info(response.getStatusCode().getReasonPhrase()); } catch (ResourceAccessException e) { //Force the OAuth client to retrieve the token again whenever it is used again. restTemplate.getOAuth2ClientContext().setAccessToken(null); tx.setError(e.getMessage()); transactionService.update(tx); log.error(e); throw new IllegalArgumentException(e); } catch (Exception e) { tx.setError(e.getMessage()); transactionService.update(tx); log.error(e); throw new IllegalArgumentException(e); } }
From source file:org.slc.sli.api.security.saml.SamlHelper.java
/** * * @param samlAssertion/*from w ww . j a v a2 s. c o m*/ * @return */ public LinkedMultiValueMap<String, String> extractAttributesFromResponse(Assertion samlAssertion) { LinkedMultiValueMap<String, String> attributes = new LinkedMultiValueMap<String, String>(); AttributeStatement attributeStatement = samlAssertion.getAttributeStatements().get(0); for (org.opensaml.saml2.core.Attribute attribute : attributeStatement.getAttributes()) { String samlAttributeName = attribute.getName(); List<XMLObject> valueObjects = attribute.getAttributeValues(); for (XMLObject valueXmlObject : valueObjects) { attributes.add(samlAttributeName, valueXmlObject.getDOM().getTextContent()); } } return attributes; }
From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequestTests.java
@Test public void testNullEntity() throws Exception { String uri = "http://example.com"; LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); headers.add("my-header", "my-value"); headers.add(HttpEncoding.CONTENT_LENGTH, "5192"); LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>(); params.add("myparam", "myparamval"); RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(new RibbonCommandContext("example", "GET", uri, false, headers, params, null, new ArrayList<RibbonRequestCustomizer>())); HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build()); assertThat("request is wrong type", request, is(not(instanceOf(HttpEntityEnclosingRequest.class)))); assertThat("uri is wrong", request.getURI().toString(), startsWith(uri)); assertThat("my-header is missing", request.getFirstHeader("my-header"), is(notNullValue())); assertThat("my-header is wrong", request.getFirstHeader("my-header").getValue(), is(equalTo("my-value"))); assertThat("Content-Length is wrong", request.getFirstHeader(HttpEncoding.CONTENT_LENGTH).getValue(), is(equalTo("5192"))); assertThat("myparam is missing", request.getURI().getQuery(), is(equalTo("myparam=myparamval"))); }
From source file:org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequestTests.java
void testEntity(String entityValue, ByteArrayInputStream requestEntity, boolean addContentLengthHeader, String method) throws IOException { String lengthString = String.valueOf(entityValue.length()); Long length = null;//from w w w .j a v a 2s .c o m URI uri = URI.create("http://example.com"); LinkedMultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); if (addContentLengthHeader) { headers.add("Content-Length", lengthString); length = (long) entityValue.length(); } RibbonRequestCustomizer requestCustomizer = new RibbonRequestCustomizer<RequestBuilder>() { @Override public boolean accepts(Class builderClass) { return builderClass == RequestBuilder.class; } @Override public void customize(RequestBuilder builder) { builder.addHeader("from-customizer", "foo"); } }; RibbonCommandContext context = new RibbonCommandContext("example", method, uri.toString(), false, headers, new LinkedMultiValueMap<String, String>(), requestEntity, Collections.singletonList(requestCustomizer)); context.setContentLength(length); RibbonApacheHttpRequest httpRequest = new RibbonApacheHttpRequest(context); HttpUriRequest request = httpRequest.toRequest(RequestConfig.custom().build()); assertThat("request is wrong type", request, is(instanceOf(HttpEntityEnclosingRequest.class))); assertThat("uri is wrong", request.getURI().toString(), startsWith(uri.toString())); if (addContentLengthHeader) { assertThat("Content-Length is missing", request.getFirstHeader("Content-Length"), is(notNullValue())); assertThat("Content-Length is wrong", request.getFirstHeader("Content-Length").getValue(), is(equalTo(lengthString))); } assertThat("from-customizer is missing", request.getFirstHeader("from-customizer"), is(notNullValue())); assertThat("from-customizer is wrong", request.getFirstHeader("from-customizer").getValue(), is(equalTo("foo"))); HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) request; assertThat("entity is missing", entityRequest.getEntity(), is(notNullValue())); HttpEntity entity = entityRequest.getEntity(); assertThat("contentLength is wrong", entity.getContentLength(), is(equalTo((long) entityValue.length()))); assertThat("content is missing", entity.getContent(), is(notNullValue())); String string = StreamUtils.copyToString(entity.getContent(), Charset.forName("UTF-8")); assertThat("content is wrong", string, is(equalTo(entityValue))); }