Package org.apache.shindig.gadgets.oauth2.persistence

Examples of org.apache.shindig.gadgets.oauth2.persistence.OAuth2Client


   * @return The OAuth2Client matching the userId and serviceName.
   */
  public OAuth2Client getClient(final String userId, final String gadgetUri, final String serviceName)
          throws GadgetException {
    final boolean isLogging = OSEOAuth2Store.LOG.isLoggable();
    OAuth2Client client;
    if (isLogging) {
      OSEOAuth2Store.LOG.entering(OSEOAuth2Store.LOG_CLASS, "getClient", new Object[] {
              gadgetUri, serviceName });
    }
   
View Full Code Here


    state.setScope(scope);

    OAuth2Accessor ret = this.cache.getOAuth2Accessor(state);

    if (ret == null || !ret.isValid()) {
      final OAuth2Client client = this.getClient(user, gadgetUri, serviceName);

      if (client != null) {
        final OAuth2Token accessToken = this.getToken(gadgetUri, serviceName, user, scope,
            OAuth2Token.Type.ACCESS);
        final OAuth2Token refreshToken = this.getToken(gadgetUri, serviceName, user, scope,
            OAuth2Token.Type.REFRESH);

        final BasicOAuth2Accessor newAccessor = new BasicOAuth2Accessor(gadgetUri, serviceName,
            user, scope, client.isAllowModuleOverride(), this, this.globalRedirectUri,
            this.authority, this.contextRoot);
        newAccessor.setAccessToken(accessToken);
        newAccessor.setAuthorizationUrl(client.getAuthorizationUrl());
        newAccessor.setClientAuthenticationType(client.getClientAuthenticationType());
        newAccessor.setAuthorizationHeader(client.isAuthorizationHeader());
        newAccessor.setUrlParameter(client.isUrlParameter());
        newAccessor.setClientId(client.getClientId());
        newAccessor.setClientSecret(client.getClientSecret());
        newAccessor.setGrantType(client.getGrantType());
        newAccessor.setRedirectUri(client.getRedirectUri());
        newAccessor.setRefreshToken(refreshToken);
        newAccessor.setTokenUrl(client.getTokenUrl());
        newAccessor.setType(client.getType());
        newAccessor.setAllowedDomains(client.getAllowedDomains());
        ret = newAccessor;

        this.storeOAuth2Accessor(ret);
      }
    }
View Full Code Here

  }

  protected String getGadgetUri(final String userId, final String gadgetUri, final String serviceName)
          throws GadgetException {
    String ret = gadgetUri;
    final OAuth2Client client = this.getClient(ret, serviceName);
    if (client != null) {
      if (client.isSharedToken()) {
        ret = client.getClientId() + ':' + client.getServiceName();
      }
    }

    return ret;
  }
View Full Code Here

  public JSONArray getUserClients(String userId) throws JSONException, UnsupportedEncodingException {
    JSONArray array = new JSONArray();
    if(this.userClientStore.containsKey(userId)) {
      Map<String, OAuth2Client> userMap = this.userClientStore.get(userId);
      for (Entry<String, OAuth2Client> entry : userMap.entrySet()) {
        OAuth2Client client = entry.getValue();
        JSONObject service = new JSONObject();
        service.put("name", client.getServiceName());
        service.put("clientId", client.getClientId());
        service.put("clientSecret", new String(client.getClientSecret(), "UTF-8"));
        service.put("authUrl", client.getAuthorizationUrl());
        service.put("tokenUrl", client.getTokenUrl());
        service.put("type", client.getType().toString());
        service.put("grantType", client.getGrantType());
        service.put("authentication", client.getClientAuthenticationType());
        service.put("override", client.isAllowModuleOverride());
        service.put("authHeader", client.isAuthorizationHeader());
        service.put("urlParam", client.isUrlParameter());
        service.put("redirectUrl", client.getRedirectUri());
        array.add(service);
      }
    }
    return array;
  }
View Full Code Here

  }
 
  @Test
  public void testDoGetExistingOAuth2() throws Exception {
    setUpBasic();
    OAuth2Client client = new OAuth2Client();
      client.setServiceName("testName");
      client.setClientId("testClientId");
      client.setClientSecret("testClientSecret".getBytes());
      client.setAuthorizationUrl("testAuthUrl");
      client.setTokenUrl("testTokenUrl");
      client.setType(Type.CONFIDENTIAL);
      client.setGrantType("testGrantType");
      client.setClientAuthenticationType("testAuthentication");
      client.setAllowModuleOverride(true);
      client.setAuthorizationHeader(false);
      client.setUrlParameter(true);
      client.setRedirectUri("testRedirectUrl");
    this.oAuth2Store.addUserClient("testID", "testName", client);

    expect(oAuthProvider.get()).andReturn(oAuthStore);
    expect(oAuth2Provider.get()).andReturn(oAuth2Store);
    expect(resp.getWriter()).andReturn(writer);
View Full Code Here

  @Test
  public void testDoGetExistingBoth() throws Exception {
    setUpBasic();
    BasicOAuthStoreConsumerKeyAndSecret kas = new BasicOAuthStoreConsumerKeyAndSecret("testKey", "testSecret", KeyType.HMAC_SYMMETRIC, "testName", "testCallbackUrl");
    this.oAuthStore.addUserService("testID", "testName", kas);
    OAuth2Client client = new OAuth2Client();
      client.setServiceName("testName");
      client.setClientId("testClientId");
      client.setClientSecret("testClientSecret".getBytes());
      client.setAuthorizationUrl("testAuthUrl");
      client.setTokenUrl("testTokenUrl");
      client.setType(Type.CONFIDENTIAL);
      client.setGrantType("testGrantType");
      client.setClientAuthenticationType("testAuthentication");
      client.setAllowModuleOverride(true);
      client.setAuthorizationHeader(false);
      client.setUrlParameter(true);
      client.setRedirectUri("testRedirectUrl");
    this.oAuth2Store.addUserClient("testID", "testName", client);

    expect(oAuthProvider.get()).andReturn(oAuthStore);
    expect(oAuth2Provider.get()).andReturn(oAuth2Store);
    expect(resp.getWriter()).andReturn(writer);
View Full Code Here

  }
 
  @Test
  public void testDoPostOverwriteOAuth2() throws Exception {
    setUpBasic();
    OAuth2Client client = new OAuth2Client();
      client.setServiceName("testName123");
      client.setClientId("testClientId123");
      client.setClientSecret("testClientSecret123".getBytes());
      client.setAuthorizationUrl("testAuthUrl123");
      client.setTokenUrl("testTokenUrl123");
      client.setType(Type.UNKNOWN);
      client.setGrantType("testGrantType123");
      client.setClientAuthenticationType("testAuthentication123");
      client.setAllowModuleOverride(false);
      client.setAuthorizationHeader(true);
      client.setUrlParameter(false);
      client.setRedirectUri("testRedirectUrl123");
    this.oAuth2Store.addUserClient("testID", "testName", client);

    expect(authority.getOrigin()).andReturn("testOrigin/");
    expect(req.getPathInfo()).andReturn("/oauth2");
    expect(req.getParameter("name")).andReturn("testName");
View Full Code Here

  }
 
  @Test
  public void testDoPostAddOAuth2() throws Exception {
    setUpBasic();
    OAuth2Client client = new OAuth2Client();
      client.setServiceName("testName123");
      client.setClientId("testClientId123");
      client.setClientSecret("testClientSecret123".getBytes());
      client.setAuthorizationUrl("testAuthUrl123");
      client.setTokenUrl("testTokenUrl123");
      client.setType(Type.UNKNOWN);
      client.setGrantType("testGrantType123");
      client.setClientAuthenticationType("testAuthentication123");
      client.setAllowModuleOverride(false);
      client.setAuthorizationHeader(true);
      client.setUrlParameter(false);
      client.setRedirectUri("testRedirectUrl123");
    this.oAuth2Store.addUserClient("testID", "testName123", client);

    expect(authority.getOrigin()).andReturn("testOrigin/");
    expect(req.getPathInfo()).andReturn("/oauth2");
    expect(req.getParameter("name")).andReturn("testName");
View Full Code Here

  }
 
  @Test
  public void testDoDeleteOAuth2() throws Exception {
    setUpBasic();
    OAuth2Client client = new OAuth2Client();
      client.setServiceName("testName123");
      client.setClientId("testClientId123");
      client.setClientSecret("testClientSecret123".getBytes());
      client.setAuthorizationUrl("testAuthUrl123");
      client.setTokenUrl("testTokenUrl123");
      client.setType(Type.UNKNOWN);
      client.setGrantType("testGrantType123");
      client.setClientAuthenticationType("testAuthentication123");
      client.setAllowModuleOverride(false);
      client.setAuthorizationHeader(true);
      client.setUrlParameter(false);
      client.setRedirectUri("testRedirectUrl123");
    this.oAuth2Store.addUserClient("testID", "testName123", client);

    expect(req.getPathInfo()).andReturn("/oauth2");
    expect(req.getParameter("name")).andReturn("testName123");
    expect(oAuthProvider.get()).andReturn(oAuthStore);
View Full Code Here

  }

  protected static OAuth2Store getDummyStore() throws Exception {
    if (MockUtils.dummyStore == null) {
      final OAuth2Cache cache = new InMemoryCache();
      final OAuth2Persister persister = MockUtils.getDummyPersister();
      MockUtils.dummyStore = MockUtils.getDummyStore(cache, persister, MockUtils.REDIRECT_URI);
    }

    MockUtils.dummyStore.clearCache();
    MockUtils.dummyStore.init();
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.oauth2.persistence.OAuth2Client

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.