Search in sources :

Example 71 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project spring-security-oauth by spring-projects.

the class AbstractRefreshTokenSupportTests method refreshAccessToken.

private OAuth2AccessToken refreshAccessToken(String refreshToken) {
    MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
    formData.add("grant_type", "refresh_token");
    formData.add("client_id", "my-trusted-client");
    formData.add("refresh_token", refreshToken);
    formData.add("scope", "read");
    HttpHeaders headers = getTokenHeaders("my-trusted-client");
    @SuppressWarnings("rawtypes") ResponseEntity<Map> response = http.postForMap(tokenPath(), headers, formData);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders().getFirst("Cache-Control").contains("no-store"));
    @SuppressWarnings("unchecked") OAuth2AccessToken newAccessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return newAccessToken;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 72 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project geode by apache.

the class ClientHttpRequest method getURL.

/**
   * Gets the URL for the client's HTTP request.
   * <p/>
   * 
   * @param uriVariables a Map of URI path variables to values in order to expand the URI template
   *        into a URI.
   * @return a URL as a URI referring to the location of the resource requested by the client via
   *         HTTP.
   * @see #getURI()
   * @see java.net.URI
   * @see org.springframework.web.util.UriComponents
   * @see org.springframework.web.util.UriComponentsBuilder
   */
public URI getURL(final Map<String, ?> uriVariables) {
    final UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(UriUtils.decode(getURI().toString()));
    if (isGet() || isDelete()) {
        final List<String> pathVariables = getPathVariables();
        // get query parameters to append to the URI/URL based on the request parameters that are not
        // path variables...
        final Map<String, List<Object>> queryParameters = CollectionUtils.removeKeys(new LinkedMultiValueMap<String, Object>(getParameters()), new Filter<Map.Entry<String, List<Object>>>() {

            @Override
            public boolean accept(final Map.Entry<String, List<Object>> entry) {
                // so that it won't interfere with the expand() call afterwards
                if (entry.getKey().contains(CLIMultiStepHelper.STEP_ARGS)) {
                    List<Object> stepArgsList = entry.getValue();
                    if (stepArgsList != null) {
                        String stepArgs = (String) stepArgsList.remove(0);
                        stepArgsList.add(UriUtils.encode(stepArgs));
                    }
                }
                return !pathVariables.contains(entry.getKey());
            }
        });
        for (final String queryParameterName : queryParameters.keySet()) {
            uriBuilder.queryParam(queryParameterName, getParameters().get(queryParameterName).toArray());
        }
    }
    return uriBuilder.build().expand(UriUtils.encode(new HashMap<String, Object>(uriVariables))).encode().toUri();
}
Also used : HashMap(java.util.HashMap) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) List(java.util.List) MultiValueMap(org.springframework.util.MultiValueMap) HashMap(java.util.HashMap) Map(java.util.Map) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 73 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project geode by apache.

the class ClientHttpRequestJUnitTest method testCreateRequestEntityForPost.

@Test
@SuppressWarnings("unchecked")
public void testCreateRequestEntityForPost() throws Exception {
    final Link expectedLink = new Link("post", toUri("http://host.domain.com:8080/app/libraries/{name}/books"), HttpMethod.POST);
    final ClientHttpRequest request = new ClientHttpRequest(expectedLink);
    assertEquals(expectedLink, request.getLink());
    final MultiValueMap<String, Object> expectedRequestParameters = new LinkedMultiValueMap<String, Object>(4);
    expectedRequestParameters.add("author", "Douglas Adams");
    expectedRequestParameters.add("title", "The Hitchhiker's Guide to the Galaxy");
    expectedRequestParameters.add("year", "1979");
    expectedRequestParameters.add("isbn", "0345453743");
    request.addHeaderValues(HttpHeader.CONTENT_TYPE.getName(), MediaType.APPLICATION_FORM_URLENCODED_VALUE);
    request.addParameterValues("author", expectedRequestParameters.getFirst("author"));
    request.addParameterValues("title", expectedRequestParameters.getFirst("title"));
    request.addParameterValues("year", expectedRequestParameters.getFirst("year"));
    request.addParameterValues("isbn", expectedRequestParameters.getFirst("isbn"));
    final HttpEntity<MultiValueMap<String, Object>> requestEntity = (HttpEntity<MultiValueMap<String, Object>>) request.createRequestEntity();
    assertNotNull(requestEntity);
    assertNotNull(requestEntity.getHeaders());
    assertEquals(MediaType.APPLICATION_FORM_URLENCODED, requestEntity.getHeaders().getContentType());
    assertEquals(expectedRequestParameters, requestEntity.getBody());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Link(org.apache.geode.management.internal.web.domain.Link) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 74 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.

the class GoogleAuthenticatorRestHttpRequestCredentialFactoryTests method verifyCredentials.

@Test
public void verifyCredentials() {
    final GoogleAuthenticatorRestHttpRequestCredentialFactory f = new GoogleAuthenticatorRestHttpRequestCredentialFactory();
    final LinkedMultiValueMap body = new LinkedMultiValueMap<>();
    body.add(GoogleAuthenticatorRestHttpRequestCredentialFactory.PARAMETER_NAME_GAUTH_OTP, "132456");
    final List<Credential> results = f.fromRequestBody(body);
    assertFalse(results.isEmpty());
    assertEquals("132456", results.get(0).getId());
}
Also used : Credential(org.apereo.cas.authentication.Credential) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 75 with LinkedMultiValueMap

use of org.springframework.util.LinkedMultiValueMap in project gocd by gocd.

the class AgentInstances method allElasticAgentsGroupedByPluginId.

public LinkedMultiValueMap<String, ElasticAgentMetadata> allElasticAgentsGroupedByPluginId() {
    LinkedMultiValueMap<String, ElasticAgentMetadata> map = new LinkedMultiValueMap<>();
    for (Map.Entry<String, AgentInstance> entry : agentInstances.entrySet()) {
        AgentInstance agentInstance = entry.getValue();
        if (agentInstance.isElastic()) {
            ElasticAgentMetadata metadata = agentInstance.elasticAgentMetadata();
            map.add(metadata.elasticPluginId(), metadata);
        }
    }
    return map;
}
Also used : AgentInstance(com.thoughtworks.go.domain.AgentInstance) NullAgentInstance(com.thoughtworks.go.domain.NullAgentInstance) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)76 Test (org.junit.Test)40 HttpHeaders (org.springframework.http.HttpHeaders)20 MultiValueMap (org.springframework.util.MultiValueMap)19 Map (java.util.Map)9 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)9 ClassPathResource (org.springframework.core.io.ClassPathResource)8 MediaType (org.springframework.http.MediaType)7 URI (java.net.URI)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Resource (org.springframework.core.io.Resource)5 HashMap (java.util.HashMap)4 FileItem (org.apache.commons.fileupload.FileItem)4 Credential (org.apereo.cas.authentication.Credential)4 IdmAuditDto (eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 X509CertificateCredential (org.apereo.cas.adaptors.x509.authentication.principal.X509CertificateCredential)3