Package org.apache.shindig.social.opensocial.oauth

Examples of org.apache.shindig.social.opensocial.oauth.OAuthEntry


                oneOf(insertMapper).execute(with(any(PersistenceRequest.class)));
            }
        });

        OAuthEntry results = sut.execute(actionContext);
        assertNotNull(results);
        assertEquals(results.getCallbackUrl(), null);
        assertEquals(results.getConsumerKey(), TEST_CONSUMER_KEY);
        assertEquals(results.getOauthVersion(), TEST_OAUTH_VERSION);
        assertEquals(results.getType(), OAuthEntry.Type.REQUEST);
        assertNotNull(results.getToken());
        assertNotNull(results.getTokenSecret());
        assertEquals(results.getContainer(), TEST_OAUTH_CONTAINER);
        assertEquals(results.getDomain(), TEST_OAUTH_DOMAIN);
        assertEquals(results.getCallbackUrl(), null);
        assertEquals(results.isCallbackUrlSigned(), false);

        context.assertIsSatisfied();
    }
View Full Code Here


                oneOf(conversionStrat).convertToEntry(with(any(OAuthDomainEntry.class)));
            }
        });

        OAuthEntry results = (OAuthEntry) sut.execute(actionContext);

        assertNotNull(results);

        context.assertIsSatisfied();
    }
View Full Code Here

                oneOf(entryMapper).execute("token");
                will(returnValue(null));
            }
        });

        OAuthEntry results = (OAuthEntry) sut.execute(actionContext);

        Assert.assertNull(results);

        context.assertIsSatisfied();
    }
View Full Code Here

        dto.setToken("token");
        dto.setTokenSecret("tokensecret");
        dto.setType(Type.ACCESS.toString());
        dto.setUserId("userid");
               
        OAuthEntry entry = sut.convertToEntry(dto);
       
        assertEquals(entry.getAppId(), dto.getAppId());
        assertEquals(entry.isAuthorized(), dto.isAuthorized());
        assertEquals(entry.getCallbackToken(), dto.getCallbackToken());
        assertEquals(entry.getCallbackTokenAttempts(), dto.getCallbackTokenAttempts());
        assertEquals(entry.getCallbackUrl(), dto.getCallbackUrl());
        assertEquals(entry.isCallbackUrlSigned(), dto.isCallbackUrlSigned());
        assertEquals(entry.getConsumerKey(), dto.getConsumer().getConsumerKey());
        assertEquals(entry.getContainer(), dto.getContainer());
        assertEquals(entry.getDomain(), dto.getDomain());
        assertEquals(entry.getIssueTime(), dto.getIssueTime());
        assertEquals(entry.getOauthVersion(), dto.getOauthVersion());
        assertEquals(entry.getToken(), dto.getToken());
        assertEquals(entry.getTokenSecret(), dto.getTokenSecret());
        assertEquals(entry.getType(), Type.valueOf(dto.getType()));
        assertEquals(entry.getUserId(), dto.getUserId());

    }
View Full Code Here

     * Test successful conversion of an {@link OAuthEntry} to an {@link OAuthDomainEntry}.
     */
    @Test
    public void testSuccessfulEntryToDto()
    {
        OAuthEntry entry = new OAuthEntry();
        entry.setAppId("appid");
        entry.setAuthorized(true);
        entry.setCallbackToken("callbacktoken");
        entry.setCallbackTokenAttempts(0);
        entry.setCallbackUrl("callbackurl");
        entry.setCallbackUrlSigned(true);
        entry.setConsumerKey("testkey");
        entry.setContainer("container");
        entry.setDomain("domain");
        entry.setIssueTime(new Date());
        entry.setOauthVersion("1.0");
        entry.setToken("token");
        entry.setTokenSecret("secret");
        entry.setType(Type.ACCESS);
        entry.setUserId("userId");
       
        context.checking(new Expectations()
        {
            {
                oneOf(mapper).execute("testkey");
                will(returnValue(new OAuthConsumer(null, null, "testkey", null, null)));
            }
        });

        OAuthDomainEntry dto = sut.convertToEntryDTO(entry);
        assertEquals(entry.getAppId(), dto.getAppId());
        assertEquals(entry.isAuthorized(), dto.isAuthorized());
        assertEquals(entry.getCallbackToken(), dto.getCallbackToken());
        assertEquals(entry.getCallbackTokenAttempts(), dto.getCallbackTokenAttempts());
        assertEquals(entry.getCallbackUrl(), dto.getCallbackUrl());
        assertEquals(entry.isCallbackUrlSigned(), dto.isCallbackUrlSigned());
        assertEquals(entry.getConsumerKey(), dto.getConsumer().getConsumerKey());
        assertEquals(entry.getContainer(), dto.getContainer());
        assertEquals(entry.getDomain(), dto.getDomain());
        assertEquals(entry.getIssueTime(), dto.getIssueTime());
        assertEquals(entry.getOauthVersion(), dto.getOauthVersion());
        assertEquals(entry.getToken(), dto.getToken());
        assertEquals(entry.getTokenSecret(), dto.getTokenSecret());
        assertEquals(entry.getType(), Type.valueOf(dto.getType()));
        assertEquals(entry.getUserId(), dto.getUserId());
        context.assertIsSatisfied();
    }
View Full Code Here

     *             on error.
     */
    @Test
    public void testGenerateRequestToken() throws Exception
    {
        final OAuthEntry entry = new OAuthEntry();
        mockery.checking(new Expectations()
        {
            {
                oneOf(serviceActionControllerMock).execute(with(any(ServiceActionContext.class)),
                        with(any(ServiceAction.class)));
View Full Code Here

     *             on error.
     */
    @Test
    public void testConvertToAccessToken() throws Exception
    {
        final OAuthEntry entry = new OAuthEntry();
        mockery.checking(new Expectations()
        {
            {
                oneOf(principalDao).execute(with(any(String.class)));
                will(returnValue(principal));
View Full Code Here

     *             on error.
     */
    @Test
    public void testGetEntry() throws Exception
    {
        final OAuthEntry entry = new OAuthEntry();
        mockery.checking(new Expectations()
        {
            {
                oneOf(serviceActionControllerMock).execute(with(any(ServiceActionContext.class)),
                        with(any(ServiceAction.class)));
View Full Code Here

    if (callback == null) {
      callback = "oob";
    }

    // generate request_token and secret
    OAuthEntry entry = dataStore.generateRequestToken(consumerKey,
                                                      requestMessage.getParameter(OAuth.OAUTH_VERSION), callback);

    List<Parameter> responseParams = OAuth.newList(OAuth.OAUTH_TOKEN, entry.getToken(),
                                                   OAuth.OAUTH_TOKEN_SECRET, entry.getTokenSecret());
    if (callback != null) {
      responseParams.add(new Parameter(OAuth.OAUTH_CALLBACK_CONFIRMED, "true"));
    }
    sendResponse(servletResponse, responseParams);
  }
View Full Code Here

    if (requestMessage.getToken() == null) {
      // MALFORMED REQUEST
      servletResponse.sendError(HttpServletResponse.SC_BAD_REQUEST, "Authentication token not found");
      return;
    }
    OAuthEntry entry = dataStore.getEntry(requestMessage.getToken());

    if (entry == null) {
      servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "OAuth Entry not found");
      return;
    }

    OAuthConsumer consumer = dataStore.getConsumer(entry.getConsumerKey());

    // Extremely rare case where consumer dissappears
    if (consumer == null) {
      servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, "consumer for entry not found");
      return;
    }

    // The token is disabled if you try to convert to an access token prior to authorization
    if (entry.getType() == OAuthEntry.Type.DISABLED) {
      servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "This token is disabled, please reinitate login");
      return;
    }

    String callback = entry.getCallbackUrl();

    // Redirect to a UI flow if the token is not authorized
    if (!entry.isAuthorized()) {
      // TBD -- need to decode encrypted payload somehow..
      if (this.oauthAuthorizeAction.startsWith("http")) {
        // Redirect to authorization page with params
        // Supply standard set of params
        // TBD
      } else {
        // Use internal forward to a jsp page
        servletRequest.setAttribute("OAUTH_DATASTORE",  dataStore);
       
        servletRequest.setAttribute("OAUTH_ENTRY",  entry);
        servletRequest.setAttribute("CALLBACK", callback);

        servletRequest.setAttribute("TOKEN", entry.getToken());
        servletRequest.setAttribute("CONSUMER", consumer);

        servletRequest.getRequestDispatcher(oauthAuthorizeAction).forward(servletRequest,servletResponse);
      }
      return;
    }

    // If we're here then the entry has been authorized

    // redirect to callback
    if (callback == null || "oob".equals(callback)) {
      // consumer did not specify a callback
      servletResponse.setContentType("text/plain");
      PrintWriter out = servletResponse.getWriter();
      out.write("Token successfully authorized.\n");     
      if (entry.getCallbackToken() != null) {
        // Usability fail.
        out.write("Please enter code " + entry.getCallbackToken() + " at the consumer.");
      }
    } else {
      callback = OAuth.addParameters(callback, OAuth.OAUTH_TOKEN, entry.getToken());
      // Add user_id to the callback
      callback = OAuth.addParameters(callback, "user_id", entry.getUserId());
      if (entry.getCallbackToken() != null) {
        callback = OAuth.addParameters(callback, OAuth.OAUTH_VERIFIER,
                                       entry.getCallbackToken());
      }

      servletResponse.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
      servletResponse.setHeader("Location", callback);
    }
View Full Code Here

TOP

Related Classes of org.apache.shindig.social.opensocial.oauth.OAuthEntry

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.