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

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

Introduction

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

Prototype

public CoreOAuthProviderSupport() 

Source Link

Usage

From source file:ltistarter.oauth.OAuth1LibraryTests.java

@Test
public void testParseParameters() throws Exception {
    CoreOAuthProviderSupport support = new CoreOAuthProviderSupport();
    when(request.getHeaders("Authorization"))
            .thenReturn(Collections.enumeration(Arrays.asList("OAuth realm=\"http://sp.example.com/\",\n"
                    + "                oauth_consumer_key=\"0685bd9184jfhq22\",\n"
                    + "                oauth_token=\"ad180jjd733klru7\",\n"
                    + "                oauth_signature_method=\"HMAC-SHA1\",\n"
                    + "                oauth_signature=\"wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D\",\n"
                    + "                oauth_timestamp=\"137131200\",\n"
                    + "                oauth_nonce=\"4572616e48616d6d65724c61686176\",\n"
                    + "                oauth_version=\"1.0\"")));

    Map<String, String> params = support.parseParameters(request);
    assertEquals("http://sp.example.com/", params.get("realm"));
    assertEquals("0685bd9184jfhq22", params.get(OAuthConsumerParameter.oauth_consumer_key.toString()));
    assertEquals("ad180jjd733klru7", params.get(OAuthConsumerParameter.oauth_token.toString()));
    assertEquals("HMAC-SHA1", params.get(OAuthConsumerParameter.oauth_signature_method.toString()));
    assertEquals("wOJIO9A2W5mFwDgiDvZbTSMK/PY=", params.get(OAuthConsumerParameter.oauth_signature.toString()));
    assertEquals("137131200", params.get(OAuthConsumerParameter.oauth_timestamp.toString()));
    assertEquals("4572616e48616d6d65724c61686176", params.get(OAuthConsumerParameter.oauth_nonce.toString()));
    assertEquals("1.0", params.get(OAuthConsumerParameter.oauth_version.toString()));
}

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

/**
 * tests compatibility of calculating the signature base string.
 */// w  w w. java  2s  . co 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);
}

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  w w w . ja va 2 s  . c  o  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);
}