Example usage for org.springframework.security.oauth.provider.filter CoreOAuthProviderSupport getSignatureBaseString

List of usage examples for org.springframework.security.oauth.provider.filter CoreOAuthProviderSupport getSignatureBaseString

Introduction

In this page you can find the example usage for org.springframework.security.oauth.provider.filter CoreOAuthProviderSupport getSignatureBaseString.

Prototype

public String getSignatureBaseString(HttpServletRequest request) 

Source Link

Usage

From source file:ltistarter.oauth.OAuth1LibraryTests.java

@Test
public void testGetSignatureBaseString() throws Exception {
    Map<String, String[]> requestParameters = new HashMap<>();
    requestParameters.put("file", new String[] { "vacation.jpg" });
    requestParameters.put("size", new String[] { "original" });

    when(request.getParameterNames()).thenReturn(Collections.enumeration(requestParameters.keySet()));
    for (String key : requestParameters.keySet()) {
        when(request.getParameterValues(key)).thenReturn(requestParameters.get(key));
    }/*from  ww  w.j  av  a  2  s  .co m*/

    when(request.getHeaders("Authorization"))
            .thenReturn(Collections.enumeration(Arrays.asList("OAuth realm=\"http://sp.example.com/\",\n"
                    + "                oauth_consumer_key=\"dpf43f3p2l4k3l03\",\n"
                    + "                oauth_token=\"nnch734d00sl2jdk\",\n"
                    + "                oauth_signature_method=\"HMAC-SHA1\",\n"
                    + "                oauth_signature=\"unimportantforthistest\",\n"
                    + "                oauth_timestamp=\"1191242096\",\n"
                    + "                oauth_nonce=\"kllo9940pd9333jh\",\n"
                    + "                oauth_version=\"1.0\"")));

    when(request.getMethod()).thenReturn("gEt");

    CoreOAuthProviderSupport support = new CoreOAuthProviderSupport();
    support.setBaseUrl("http://photos.example.net");
    when(request.getRequestURI()).thenReturn("photos");

    String baseString = support.getSignatureBaseString(request);
    assertEquals(
            "GET&http%3A%2F%2Fphotos.example.net%2Fphotos&file%3Dvacation.jpg%26oauth_consumer_key%3Ddpf43f3p2l4k3l03%26oauth_nonce%3Dkllo9940pd9333jh%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1191242096%26oauth_token%3Dnnch734d00sl2jdk%26oauth_version%3D1.0%26size%3Doriginal",
            baseString);
}

From source file:net.oauth.signature.GoogleCodeCompatibilityTests.java

/**
 * tests compatibility of calculating the signature base string.
 *///ww  w. ja v a 2 s  . c  o m
@Test
public void testCalculateSignatureBaseString() throws Exception {
    final String baseUrl = "http://www.springframework.org/schema/security/";
    CoreOAuthProviderSupport support = new CoreOAuthProviderSupport() {
        @Override
        protected String getBaseUrl(HttpServletRequest request) {
            return baseUrl;
        }
    };

    Map<String, String[]> parameterMap = new HashMap<String, String[]>();
    parameterMap.put("a", new String[] { "value-a" });
    parameterMap.put("b", new String[] { "value-b" });
    parameterMap.put("c", new String[] { "value-c" });
    parameterMap.put("param[1]", new String[] { "aaa", "bbb" });

    when(request.getParameterNames()).thenReturn(Collections.enumeration(parameterMap.keySet()));
    for (Map.Entry<String, String[]> param : parameterMap.entrySet()) {
        when(request.getParameterValues(param.getKey())).thenReturn(param.getValue());
    }

    String header = "OAuth realm=\"http://sp.example.com/\","
            + "                oauth_consumer_key=\"0685bd9184jfhq22\","
            + "                oauth_token=\"ad180jjd733klru7\","
            + "                oauth_signature_method=\"HMAC-SHA1\","
            + "                oauth_signature=\"wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D\","
            + "                oauth_timestamp=\"137131200\"," + "                oauth_callback=\""
            + OAuthCodec.oauthEncode("http://myhost.com/callback") + "\","
            + "                oauth_nonce=\"4572616e48616d6d65724c61686176\","
            + "                oauth_version=\"1.0\"";
    when(request.getHeaders("Authorization")).thenReturn(Collections.enumeration(Arrays.asList(header)));
    when(request.getMethod()).thenReturn("GET");
    String ours = support.getSignatureBaseString(request);

    when(request.getHeaders("Authorization")).thenReturn(Collections.enumeration(Arrays.asList(header)));
    when(request.getParameterMap()).thenReturn(parameterMap);
    when(request.getHeaderNames()).thenReturn(null);
    OAuthMessage message = OAuthServlet.getMessage(request, baseUrl);

    String theirs = OAuthSignatureMethod.getBaseString(message);
    assertEquals(theirs, ours);
}