Search in sources :

Example 11 with HttpMethod

use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.

the class ResourceHttpRequestHandlerTests method invalidPath.

@Test
public void invalidPath() throws Exception {
    for (HttpMethod method : HttpMethod.values()) {
        this.request = new MockHttpServletRequest("GET", "");
        this.response = new MockHttpServletResponse();
        testInvalidPath(method);
    }
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) HttpMethod(org.springframework.http.HttpMethod) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 12 with HttpMethod

use of org.springframework.http.HttpMethod in project spring-framework by spring-projects.

the class ResourceHttpRequestHandlerTests method resourceNotFound.

@Test
public void resourceNotFound() throws Exception {
    for (HttpMethod method : HttpMethod.values()) {
        this.request = new MockHttpServletRequest("GET", "");
        this.response = new MockHttpServletResponse();
        resourceNotFound(method);
    }
}
Also used : MockHttpServletRequest(org.springframework.mock.web.test.MockHttpServletRequest) HttpMethod(org.springframework.http.HttpMethod) MockHttpServletResponse(org.springframework.mock.web.test.MockHttpServletResponse) Test(org.junit.Test)

Example 13 with HttpMethod

use of org.springframework.http.HttpMethod in project spring-security-oauth by spring-projects.

the class AuthorizationCodeAccessTokenProviderWithConversionTests method testGetAccessTokenFromJson.

@Test
public void testGetAccessTokenFromJson() throws Exception {
    final OAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
    requestFactory = new ClientHttpRequestFactory() {

        public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException {
            return new StubClientHttpRequest(new ObjectMapper().writeValueAsString(token));
        }
    };
    AccessTokenRequest request = new DefaultAccessTokenRequest();
    request.setAuthorizationCode("foo");
    resource.setAccessTokenUri("http://localhost/oauth/token");
    request.setPreservedState(new Object());
    setUpRestTemplate();
    assertEquals(token, provider.obtainAccessToken(resource, request));
}
Also used : ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) IOException(java.io.IOException) DefaultAccessTokenRequest(org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest) AccessTokenRequest(org.springframework.security.oauth2.client.token.AccessTokenRequest) ClientHttpRequest(org.springframework.http.client.ClientHttpRequest) URI(java.net.URI) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) HttpMethod(org.springframework.http.HttpMethod) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) DefaultAccessTokenRequest(org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest) Test(org.junit.Test)

Example 14 with HttpMethod

use of org.springframework.http.HttpMethod in project spring-security-oauth by spring-projects.

the class TokenEndpointTests method testGetAccessTokenWithSupportedRequestParametersNotPost.

@Test
public void testGetAccessTokenWithSupportedRequestParametersNotPost() throws HttpRequestMethodNotSupportedException {
    endpoint.setAllowedRequestMethods(new HashSet<HttpMethod>(Arrays.asList(HttpMethod.GET)));
    HashMap<String, String> parameters = new HashMap<String, String>();
    parameters.put("client_id", clientId);
    parameters.put("scope", "read");
    parameters.put("grant_type", "authorization_code");
    parameters.put("code", "kJAHDFG");
    OAuth2AccessToken expectedToken = new DefaultOAuth2AccessToken("FOO");
    when(tokenGranter.grant(Mockito.eq("authorization_code"), Mockito.any(TokenRequest.class))).thenReturn(expectedToken);
    @SuppressWarnings("unchecked") Map<String, String> anyMap = Mockito.any(Map.class);
    when(authorizationRequestFactory.createTokenRequest(anyMap, Mockito.any(ClientDetails.class))).thenReturn(createFromParameters(parameters));
    ResponseEntity<OAuth2AccessToken> response = endpoint.getAccessToken(clientAuthentication, parameters);
    assertNotNull(response);
    assertEquals(HttpStatus.OK, response.getStatusCode());
    OAuth2AccessToken body = response.getBody();
    assertEquals(body, expectedToken);
    assertTrue("Wrong body: " + body, body.getTokenType() != null);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) HashMap(java.util.HashMap) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) HttpMethod(org.springframework.http.HttpMethod) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) Test(org.junit.Test)

Example 15 with HttpMethod

use of org.springframework.http.HttpMethod in project grails-core by grails.

the class DefaultUrlMappingsHolder method allowedMethods.

@Override
public Set<HttpMethod> allowedMethods(String uri) {
    UrlMappingInfo[] urlMappingInfos = matchAll(uri, UrlMapping.ANY_HTTP_METHOD);
    Set<HttpMethod> methods = new HashSet<HttpMethod>();
    for (UrlMappingInfo urlMappingInfo : urlMappingInfos) {
        if (urlMappingInfo.getHttpMethod() == null || urlMappingInfo.getHttpMethod().equals(UrlMapping.ANY_HTTP_METHOD)) {
            methods.addAll(Arrays.asList(HttpMethod.values()));
            break;
        } else {
            HttpMethod method = HttpMethod.valueOf(urlMappingInfo.getHttpMethod().toUpperCase());
            methods.add(method);
        }
    }
    return Collections.unmodifiableSet(methods);
}
Also used : HttpMethod(org.springframework.http.HttpMethod) UrlMappingInfo(grails.web.mapping.UrlMappingInfo) HashSet(java.util.HashSet)

Aggregations

HttpMethod (org.springframework.http.HttpMethod)35 Test (org.junit.Test)19 URI (java.net.URI)16 IOException (java.io.IOException)11 HttpHeaders (org.springframework.http.HttpHeaders)8 ClientHttpRequest (org.springframework.http.client.ClientHttpRequest)7 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)7 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)4 AccessTokenRequest (org.springframework.security.oauth2.client.token.AccessTokenRequest)4 DefaultAccessTokenRequest (org.springframework.security.oauth2.client.token.DefaultAccessTokenRequest)4 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)4 HttpRequest (org.springframework.http.HttpRequest)3 EnumSet (java.util.EnumSet)2 HashMap (java.util.HashMap)2 Set (java.util.Set)2 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)2 ResolvableType (org.springframework.core.ResolvableType)2 InvalidMediaTypeException (org.springframework.http.InvalidMediaTypeException)2 MediaType (org.springframework.http.MediaType)2 HttpRequestWrapper (org.springframework.http.client.support.HttpRequestWrapper)2