Package org.apache.shindig.gadgets.oauth2

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


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

  @Test
  public void testGetOAuth2Accessor_1() throws Exception {
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();

    final OAuth2CallbackState state = new OAuth2CallbackState(MockUtils.getDummyStateCrypter());
    state.setGadgetUri(accessor.getGadgetUri());
    state.setServiceName(accessor.getServiceName());
    state.setUser(accessor.getUser());
    state.setScope(accessor.getScope());

    final OAuth2Accessor result = this.cache.getOAuth2Accessor(state);

    Assert.assertNotNull(result);
    Assert.assertEquals(MockUtils.CLIENT_ID1, result.getClientId());
  }
View Full Code Here


    final OAuth2CallbackState state = new OAuth2CallbackState(MockUtils.getDummyStateCrypter());
    state.setGadgetUri("BAD");
    state.setServiceName("BAD");
    state.setUser("BAD");
    state.setScope("BAD");
    final OAuth2Accessor result = this.cache.getOAuth2Accessor(state);

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

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

    this.cache.storeOAuth2Accessor(accessor);

    final OAuth2CallbackState state = new OAuth2CallbackState(MockUtils.getDummyStateCrypter());
    state.setGadgetUri(accessor.getGadgetUri());
    state.setServiceName(accessor.getServiceName());
    state.setUser(accessor.getUser());
    state.setScope(accessor.getScope());
    accessor = this.cache.getOAuth2Accessor(state);

    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());
  }
View Full Code Here

  @Override
  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 encRequestStateKey = msg.getState();
      if (encRequestStateKey == null) {
        if (error != null) {
          OAuth2CallbackServlet.sendError(error, "encRequestStateKey is null", msg.getErrorUri(),
                  msg.getErrorDescription(), null, resp, null, this.sendTraceToClient);
        } else {
          OAuth2CallbackServlet.sendError(OAuth2Error.CALLBACK_PROBLEM,
                  "OAuth2CallbackServlet requestStateKey is null.", "", "", null, resp, null,
                  this.sendTraceToClient);
        }
        return;
      }

      final OAuth2CallbackState state = new OAuth2CallbackState(this.stateCrypter,
              encRequestStateKey);

      accessor = this.store.getOAuth2Accessor(state);

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

      if (accessor == null || !accessor.isValid() || accessor.isErrorResponse()) {
        String message;
        if (accessor != null) {
          message = accessor.isValid() ? "OAuth2CallbackServlet accessor isErrorResponse "
                  : "OAuth2CallbackServlet accessor is invalid ";
          message = message + accessor;
        } else {
          message = "OAuth2CallbackServlet accessor is null";
        }

        OAuth2CallbackServlet.sendError(OAuth2Error.CALLBACK_PROBLEM, message,
                accessor.getErrorContextMessage(), accessor.getErrorUri(), accessor, resp,
                accessor.getErrorException(), this.sendTraceToClient);

        return;
      }

      if (!accessor.isRedirecting()) {
        // Somehow our accessor got lost. We should not proceed.
        OAuth2CallbackServlet.sendError(OAuth2Error.CALLBACK_PROBLEM,
                "OAuth2CallbackServlet accessor is not valid, isn't redirecting.", "", "",
                accessor, resp, null, this.sendTraceToClient);
        return;
      }

      boolean foundHandler = false;
      for (final AuthorizationEndpointResponseHandler authorizationEndpointResponseHandler : this.authorizationEndpointResponseHandlers) {
        if (authorizationEndpointResponseHandler.handlesRequest(accessor, request)) {
          final OAuth2HandlerError handlerError = authorizationEndpointResponseHandler
                  .handleRequest(accessor, request);
          if (handlerError != null) {
            OAuth2CallbackServlet.sendError(handlerError.getError(),
                    handlerError.getContextMessage(), handlerError.getDescription(),
                    handlerError.getUri(), accessor, resp, handlerError.getCause(),
                    this.sendTraceToClient);
            return;
          }
          foundHandler = true;
          break;
        }
      }

      if (!foundHandler) {
        OAuth2CallbackServlet.sendError(OAuth2Error.NO_RESPONSE_HANDLER,
                "OAuth2Callback servlet couldn't find a AuthorizationEndpointResponseHandler", "",
                "", accessor, resp, null, this.sendTraceToClient);
        return;
      }

      HttpUtil.setNoCache(resp);
      resp.setContentType("text/html; charset=UTF-8");
      resp.getWriter().write(OAuth2CallbackServlet.RESP_BODY);
    } catch (final Exception e) {
      OAuth2CallbackServlet.sendError(OAuth2Error.CALLBACK_PROBLEM,
              "Exception occurred processing redirect.", "", "", accessor, resp, e,
              this.sendTraceToClient);
      if (IOException.class.isInstance(e)) {
        throw (IOException) e;
      }
    } finally {
      if (accessor != null) {
        if (!accessor.isErrorResponse()) {
          accessor.invalidate();
          this.store.removeOAuth2Accessor(accessor);
        } else {
          this.store.storeOAuth2Accessor(accessor);
        }
      }
View Full Code Here

  @Test
  public void testAddOAuth2Authentication1() throws Exception {
    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
    final HttpRequest request = null;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();

    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);

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

  @Test
  public void testAddOAuth2Authentication2() throws Exception {
    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
    final OAuth2Accessor accessor = null;

    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);

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

  @Test
  public void testAddOAuth2Authentication3() throws Exception {
    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error();

    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);

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

  @Test
  public void testAddOAuth2Authentication4() throws Exception {
    final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler();
    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code();

    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);

    Assert.assertNull(result);
View Full Code Here

  @Test
  public void testAddOAuth2Authentication_1() throws Exception {
    final StandardAuthenticationHandler fixture = new StandardAuthenticationHandler();
    final HttpRequest request = null;
    final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_StandardAuth();

    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);

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

  @Test
  public void testAddOAuth2Authentication_2() throws Exception {
    final StandardAuthenticationHandler fixture = new StandardAuthenticationHandler();
    final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI("")));
    final OAuth2Accessor accessor = null;

    final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor);

    Assert.assertNotNull(result);
    Assert.assertEquals(OAuth2Error.AUTHENTICATION_PROBLEM, result.getError());
View Full Code Here

TOP

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

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.