Package org.apache.shindig.gadgets.oauth2

Examples of org.apache.shindig.gadgets.oauth2.OAuth2Message


    Assert.assertEquals(MockUtils.CLIENT_ID1, result.getClientId());
  }

  @Test
  public void testGetOAuth2Accessor_2() throws Exception {
    final OAuth2Accessor result = this.cache.getOAuth2Accessor(null);

    Assert.assertNull(result);
  }
View Full Code Here


    Assert.assertNull(result);
  }

  @Test
  public void testGetOAuth2Accessor_3() throws Exception {
    final OAuth2Accessor result = this.cache.getOAuth2Accessor(MockUtils.BAD_INDEX);

    Assert.assertNull(result);
  }
View Full Code Here

  }

  @Test
  public void testRemoveOAuth2Accessor_1() throws Exception {

    final OAuth2Accessor result = this.cache.removeOAuth2Accessor(MockUtils.BAD_INDEX);

    Assert.assertNull(result);
  }
View Full Code Here

  }

  @Test
  public void testStoreOAuth2Accessor_1() throws Exception {
    final OAuth2Store store = MockUtils.getDummyStore(this.cache, null, null);
    OAuth2Accessor accessor = new BasicOAuth2Accessor("XXX", "YYY", "ZZZ", "", false, store, "AAA");

    final Integer result = this.cache.storeOAuth2Accessor(accessor);

    Assert.assertEquals(-1664180105, result.intValue());

    accessor = this.cache.getOAuth2Accessor(result);

    Assert.assertNotNull(accessor);
    Assert.assertEquals("XXX", accessor.getGadgetUri());
    Assert.assertEquals("YYY", accessor.getServiceName());
    Assert.assertEquals("ZZZ", accessor.getUser());
    Assert.assertEquals("", accessor.getScope());
    Assert.assertEquals(false, accessor.isAllowModuleOverrides());
    Assert.assertEquals("AAA", accessor.getRedirectUri());
    Assert.assertEquals("-1664180105", accessor.getState());
  }
View Full Code Here

  }

  @Test
  public void testStoreOAuth2Accessor_2() throws Exception {

    final OAuth2Accessor accessor = null;

    final Integer result = this.cache.storeOAuth2Accessor(accessor);

    Assert.assertEquals(null, result);
  }
View Full Code Here

  protected void doGet(final HttpServletRequest request, final HttpServletResponse resp)
      throws IOException {

    OAuth2Accessor accessor = null;
    try {
      final OAuth2Message msg = this.oauth2MessageProvider.get();
      msg.parseRequest(request);
      final OAuth2Error error = msg.getError();
      final String requestStateKey = msg.getState();
      if (requestStateKey == null) {
        if (error != null) {
          OAuth2CallbackServlet.sendError(error, msg.getErrorDescription(), msg.getErrorUri(),
              null, resp, null);
        } else {
          OAuth2CallbackServlet.sendError(OAuth2Error.CALLBACK_PROBLEM,
              "OAuth2CallbackServlet requestStateKey is null.", "", null, resp, null);
        }
        return;
      }

      final Integer index = Integer.decode(requestStateKey);
      accessor = this.store.getOAuth2Accessor(index);

      if (error != null) {
        OAuth2CallbackServlet.sendError(error, msg.getErrorDescription(), msg.getErrorUri(),
            accessor, resp, null);
        return;
      }

      if ((accessor == null) || (!accessor.isValid()) || (accessor.isErrorResponse())) {
View Full Code Here

          "grant_type is not code", null);
    }

    if (ret == null) {
      try {
        final OAuth2Message msg = this.oauth2MessageProvider.get();
        msg.parseRequest(request);

        ret = this.setAuthorizationCode(msg.getAuthorization(), accessor);
      } catch (final Exception e) {
        if (CodeAuthorizationResponseHandler.LOG.isLoggable()) {
          CodeAuthorizationResponseHandler.LOG.log(
              "Exception exchanging authorization code for access_token", e);
        }
View Full Code Here

            "error exchanging code for access_token", e);
      }

      if ((ret == null) && (response != null)) {
        if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
          final OAuth2Message msg = this.oauth2MessageProvider.get();
          msg.parseJSON(response.getResponseAsString());
          if (msg.getError() != null) {
            ret = new OAuth2HandlerError(msg.getError(), "error exchanging code for access_token",
                null);
          }
        }

        if (ret == null) {
View Full Code Here

        if (ret == null) {
          final long issuedAt = System.currentTimeMillis() / 1000;

          final String contentType = response.getHeader("Content-Type");
          final String responseString = response.getResponseAsString();
          final OAuth2Message msg = this.oauth2MessageProvider.get();

          if (contentType.startsWith("text/plain")) {
            // Facebook does this
            msg.parseQuery('?' + responseString);
          } else if (contentType.startsWith("application/json")) {
            // Google does this
            final JSONObject responseJson = new JSONObject(responseString);
            msg.parseJSON(responseJson.toString());
          } else {
            if (isLogging) {
              TokenAuthorizationResponseHandler.LOG.log("Unhandled Content-Type {0}", contentType);
              TokenAuthorizationResponseHandler.LOG.exiting(
                  TokenAuthorizationResponseHandler.LOG_CLASS, "handleResponse", null);
            }
            ret = TokenAuthorizationResponseHandler.getError("Unhandled Content-Type "
                + contentType);
          }

          final OAuth2Error error = msg.getError();
          if ((error == null) && (accessor != null)) {
            final String accessToken = msg.getAccessToken();
            final String refreshToken = msg.getRefreshToken();
            final String expiresIn = msg.getExpiresIn();
            final String tokenType = msg.getTokenType();
            final String providerName = accessor.getServiceName();
            final String gadgetUri = accessor.getGadgetUri();
            final String scope = accessor.getScope();
            final String user = accessor.getUser();
            final String macAlgorithm = msg.getMacAlgorithm();
            final String macSecret = msg.getMacSecret();
            final Map<String, String> unparsedProperties = msg.getUnparsedProperties();

            if (accessToken != null) {
              final OAuth2Token storedAccessToken = this.store.createToken();
              storedAccessToken.setIssuedAt(issuedAt);
              if (expiresIn != null) {
View Full Code Here

  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse resp)
      throws IOException {
    final String method = "doGet";
    DominoOAuth2Accessor accessor = null;
    final OAuth2Message msg = this.oauth2MessageProvider.get();
    msg.parseRequest(request);
    if(!isOAuthMsgValid(msg, resp)) {
      return;
    }
    final DominoOAuth2CallbackState state = new DominoOAuth2CallbackState(this.stateCrypter,
        msg.getState());

    try {
      accessor = this.store.getOAuth2Accessor(state);
    } catch (GadgetException e1) {
      log.logp(Level.WARNING, CLASS, method, "Error getting accessor from store.", e1);
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.oauth2.OAuth2Message

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.