Search in sources :

Example 6 with MultiValueMap

use of org.springframework.util.MultiValueMap in project spring-framework by spring-projects.

the class WebMvcStompWebSocketEndpointRegistrationTests method handshakeHandlerAndInterceptorWithAllowedOrigins.

@Test
public void handshakeHandlerAndInterceptorWithAllowedOrigins() {
    WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] { "/foo" }, this.handler, this.scheduler);
    DefaultHandshakeHandler handshakeHandler = new DefaultHandshakeHandler();
    HttpSessionHandshakeInterceptor interceptor = new HttpSessionHandshakeInterceptor();
    String origin = "http://mydomain.com";
    registration.setHandshakeHandler(handshakeHandler).addInterceptors(interceptor).setAllowedOrigins(origin);
    MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
    assertEquals(1, mappings.size());
    Map.Entry<HttpRequestHandler, List<String>> entry = mappings.entrySet().iterator().next();
    assertEquals(Arrays.asList("/foo"), entry.getValue());
    WebSocketHttpRequestHandler requestHandler = (WebSocketHttpRequestHandler) entry.getKey();
    assertNotNull(requestHandler.getWebSocketHandler());
    assertSame(handshakeHandler, requestHandler.getHandshakeHandler());
    assertEquals(2, requestHandler.getHandshakeInterceptors().size());
    assertEquals(interceptor, requestHandler.getHandshakeInterceptors().get(0));
    assertEquals(OriginHandshakeInterceptor.class, requestHandler.getHandshakeInterceptors().get(1).getClass());
}
Also used : HttpSessionHandshakeInterceptor(org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) SockJsHttpRequestHandler(org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler) HttpRequestHandler(org.springframework.web.HttpRequestHandler) List(java.util.List) DefaultHandshakeHandler(org.springframework.web.socket.server.support.DefaultHandshakeHandler) MultiValueMap(org.springframework.util.MultiValueMap) Map(java.util.Map) WebSocketHttpRequestHandler(org.springframework.web.socket.server.support.WebSocketHttpRequestHandler) Test(org.junit.Test)

Example 7 with MultiValueMap

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

the class ServerRunning method postForString.

public ResponseEntity<String> postForString(String path, HttpHeaders headers, MultiValueMap<String, String> formData) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED));
    return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 8 with MultiValueMap

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

the class ServerRunning method postForString.

public ResponseEntity<String> postForString(String path, MultiValueMap<String, String> formData) {
    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_FORM_URLENCODED));
    return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, headers), String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 9 with MultiValueMap

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

the class RefreshTokenSupportTests method getAccessToken.

private OAuth2AccessToken getAccessToken(String scope, String clientId) throws Exception {
    MultiValueMap<String, String> formData = getTokenFormData(scope, clientId);
    HttpHeaders headers = getTokenHeaders(clientId);
    @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.postForMap("/sparklr2/oauth/token", 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 accessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
    return accessToken;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) 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 10 with MultiValueMap

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

the class ServerRunning method postForString.

public ResponseEntity<String> postForString(String path, HttpHeaders headers, MultiValueMap<String, String> formData) {
    HttpHeaders actualHeaders = new HttpHeaders();
    actualHeaders.putAll(headers);
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    return client.exchange(getUrl(path), HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(formData, actualHeaders), String.class);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Aggregations

MultiValueMap (org.springframework.util.MultiValueMap)46 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)33 Test (org.junit.Test)18 Map (java.util.Map)17 HttpHeaders (org.springframework.http.HttpHeaders)17 List (java.util.List)9 HttpEntity (org.springframework.http.HttpEntity)9 RestTemplate (org.springframework.web.client.RestTemplate)6 URI (java.net.URI)4 LinkedHashMap (java.util.LinkedHashMap)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)4 HttpRequestHandler (org.springframework.web.HttpRequestHandler)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Link (org.apache.geode.management.internal.web.domain.Link)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 MethodParameter (org.springframework.core.MethodParameter)3 DefaultHandshakeHandler (org.springframework.web.socket.server.support.DefaultHandshakeHandler)3 HttpSessionHandshakeInterceptor (org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor)3