Package org.springframework.security.oauth.consumer

Examples of org.springframework.security.oauth.consumer.BaseProtectedResourceDetails


   * tests the filter.
   */
  @Test
  public void testDoFilter() throws Exception {
    final OAuthRememberMeServices rememberMeServices = new NoOpOAuthRememberMeServices();
    final BaseProtectedResourceDetails resource = new BaseProtectedResourceDetails();
    resource.setId("dep1");

    OAuthConsumerContextFilter filter = new OAuthConsumerContextFilter() {
      @Override
      protected String getCallbackURL(HttpServletRequest request) {
        return "urn:callback";
      }

      @Override
      protected String getUserAuthorizationRedirectURL(ProtectedResourceDetails details,
          OAuthConsumerToken requestToken, String callbackURL) {
        return callbackURL + "&" + requestToken.getResourceId();
      }
    };
    filter.setRedirectStrategy(new RedirectStrategy() {
      public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url)
          throws IOException {
        response.sendRedirect(url);
      }
    });

    filter.setTokenServices(tokenServices);
    filter.setConsumerSupport(support);
    filter.setRememberMeServices(rememberMeServices);

    doThrow(new AccessTokenRequiredException(resource)).when(filterChain).doFilter(request, response);
    when(tokenServices.getToken("dep1")).thenReturn(null);
    when(request.getParameter("oauth_verifier")).thenReturn(null);
    when(response.encodeRedirectURL("urn:callback")).thenReturn("urn:callback?query");

    OAuthConsumerToken token = new OAuthConsumerToken();
    token.setAccessToken(false);
    token.setResourceId(resource.getId());
    when(support.getUnauthorizedRequestToken("dep1", "urn:callback?query")).thenReturn(token);

    filter.doFilter(request, response, filterChain);

    verify(filterChain).doFilter(request, response);
View Full Code Here

TOP

Related Classes of org.springframework.security.oauth.consumer.BaseProtectedResourceDetails

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.