Examples of OAuth2Client


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

    client.setServiceName(MockUtils.SERVICE_NAME);
    client.setTokenUrl(MockUtils.TOKEN_URL);
  }

  protected static OAuth2Client getClient_Code_Confidential() throws Exception {
    final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter());
    MockUtils.setClientCommons(client);
    client.setClientAuthenticationType(OAuth2Message.BASIC_AUTH_TYPE);
    client.setClientId(MockUtils.CLIENT_ID1);
    client.setClientSecret(MockUtils.CLIENT_SECRET1.getBytes("UTF-8"));
    client.setGadgetUri(MockUtils.GADGET_URI1);
    client.setType(OAuth2Accessor.Type.CONFIDENTIAL);
    client.setAllowModuleOverride(true);
    client.setAuthorizationHeader(true);
    client.setUrlParameter(false);

    return client;
  }
View Full Code Here

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

    return client;
  }

  protected static OAuth2Client getClient_Code_Public() throws Exception {
    final OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter());
    MockUtils.setClientCommons(client);
    client.setClientAuthenticationType(OAuth2Message.STANDARD_AUTH_TYPE);
    client.setClientId(MockUtils.CLIENT_ID2);
    client.setClientSecret(MockUtils.CLIENT_SECRET2.getBytes("UTF-8"));
    client.setGadgetUri(MockUtils.GADGET_URI2);
    client.setType(OAuth2Accessor.Type.PUBLIC);
    client.setAllowModuleOverride(false);
    client.setAuthorizationHeader(false);
    client.setUrlParameter(true);

    return client;
  }
View Full Code Here

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

    final OAuth2Persister persister = MockUtils.getDummyPersister();
    final OAuth2Encrypter encrypter = MockUtils.getDummyEncrypter();
    final BlobCrypter stateCrypter = MockUtils.getDummyStateCrypter();

    OAuth2Token token = MockUtils.getAccessToken();
    OAuth2Client client = MockUtils.getClient_Code_Confidential();
    client.setSharedToken( true );

    BasicOAuth2Store mockStore = createMockBuilder( BasicOAuth2Store.class )
            .withConstructor( OAuth2Cache.class, OAuth2Persister.class, OAuth2Encrypter.class, String.class, Authority.class, String.class, BlobCrypter.class )
            .withArgs( cache, persister, encrypter, MockUtils.REDIRECT_URI, (Authority)null, (String)null, stateCrypter )
            .addMockedMethod( "getClient" )
View Full Code Here

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

            MockUtils.USER, MockUtils.SCOPE, Type.ACCESS));
  }

  @Test
  public void testGetClient_1() throws Exception {
    final OAuth2Client result = this.cache.getClient(MockUtils.GADGET_URI1, MockUtils.SERVICE_NAME);

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

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

  }

  @Test
  public void testRemoveClient_1() throws Exception {

    OAuth2Client result = this.cache.getClient(MockUtils.GADGET_URI1, MockUtils.SERVICE_NAME);

    Assert.assertNotNull(result);

    result = this.cache.removeClient(result);
View Full Code Here

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

  }

  @Test
  public void testStoreClient_1() throws Exception {

    OAuth2Client client = new OAuth2Client(MockUtils.getDummyEncrypter());
    client.setGadgetUri("xxx");
    client.setServiceName("yyy");

    this.cache.storeClient(client);

    client = this.cache.getClient(client.getGadgetUri(), client.getServiceName());

    Assert.assertNotNull(client);
    Assert.assertEquals("xxx", client.getGadgetUri());
    Assert.assertEquals("yyy", client.getServiceName());
  }
View Full Code Here

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

  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

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

      final JSONObject clients = this.configFile.getJSONObject(CLIENTS);
      for (final Iterator<?> j = clients.keys(); j.hasNext();) {
        final String clientName = (String) j.next();
        final JSONObject settings = clients.getJSONObject(clientName);

        final OAuth2Client client = new OAuth2Client(this.encrypter);

        final String providerName = settings.getString(PROVIDER_NAME);
        final OAuth2Provider provider = providers.get(providerName);
        client.setAuthorizationUrl(provider.getAuthorizationUrl());
        client.setClientAuthenticationType(provider.getClientAuthenticationType());
        client.setAuthorizationHeader(provider.isAuthorizationHeader());
        client.setUrlParameter(provider.isUrlParameter());
        client.setTokenUrl(provider.getTokenUrl());

        String redirectUri = settings.optString(OAuth2Message.REDIRECT_URI, null);
        if (redirectUri == null) {
          redirectUri = this.globalRedirectUri;
        }
        final String secret = settings.optString(OAuth2Message.CLIENT_SECRET);
        final String clientId = settings.getString(OAuth2Message.CLIENT_ID);
        final String typeS = settings.optString(TYPE, null);
        String grantType = settings.optString(OAuth2Message.GRANT_TYPE, null);
        final String sharedToken = settings.optString(OAuth2Message.SHARED_TOKEN, "false");
        if ("true".equalsIgnoreCase(sharedToken)) {
          client.setSharedToken(true);
        }

        try {
          client.setEncryptedSecret(secret.getBytes("UTF-8"));
        } catch (final OAuth2EncryptionException e) {
          throw new OAuth2PersistenceException(e);
        }

        client.setClientId(clientId);

        if (this.authority != null) {
          redirectUri = redirectUri.replace("%authority%", this.authority.getAuthority());
          redirectUri = redirectUri.replace("%contextRoot%", this.contextRoot);
          redirectUri = redirectUri.replace("%origin%", this.authority.getOrigin());
          redirectUri = redirectUri.replace("%scheme", this.authority.getScheme());
        }
        client.setRedirectUri(redirectUri);

        if (grantType == null || grantType.length() == 0) {
          grantType = OAuth2Message.AUTHORIZATION;
        }

        client.setGrantType(grantType);

        OAuth2Accessor.Type type = OAuth2Accessor.Type.UNKNOWN;
        if (OAuth2Message.CONFIDENTIAL_CLIENT_TYPE.equals(typeS)) {
          type = OAuth2Accessor.Type.CONFIDENTIAL;
        } else if (OAuth2Message.PUBLIC_CLIENT_TYPE.equals(typeS)) {
          type = OAuth2Accessor.Type.PUBLIC;
        }
        client.setType(type);

        final JSONArray dArray = settings.optJSONArray(ALLOWED_DOMAINS);
        if (dArray != null) {
          final ArrayList<String> domains = new ArrayList<String>();
          for (int i = 0; i < dArray.length(); i++) {
            domains.add(dArray.optString(i));
          }
          client.setAllowedDomains(domains.toArray(new String[domains.size()]));
        }

        internalMap.put(clientName, client);
      }
    } catch (RuntimeException e) {
      throw e; 
    } catch (final Exception e) {
      LOG.logp(Level.WARNING, CLAZZ, method, "Exception loading clients.", e);
      throw new OAuth2PersistenceException(e);
    }
   
    final Set<OAuth2Client> ret = new HashSet<OAuth2Client>(gadgetBindings.size());
    for (final OAuth2GadgetBinding binding : gadgetBindings.values()) {
      final String clientName = binding.getClientName();
      final OAuth2Client cachedClient = internalMap.get(clientName);
      final OAuth2Client client = cachedClient.clone();
      client.setGadgetUri(binding.getGadgetUri());
      client.setServiceName(binding.getGadgetServiceName());
      client.setAllowModuleOverride(binding.isAllowOverride());
      ret.add(client);
    }

    return ret;
  }
View Full Code Here

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

      type = Type.UNKNOWN;
    } else {
      type = Type.CONFIDENTIAL;
    }
   
    OAuth2Client client = new OAuth2Client();
    client.setServiceName(serviceName);
    client.setClientId(clientId);
    client.setClientSecret(clientSecret.getBytes("UTF-8"));
    client.setAuthorizationUrl(authUrl);
    client.setTokenUrl(tokenUrl);
    client.setType(type);
    client.setGrantType(grantType);
    client.setClientAuthenticationType(authentication);
    client.setAllowModuleOverride(Boolean.parseBoolean(override));
    client.setAuthorizationHeader(Boolean.parseBoolean(authHeader));
    client.setUrlParameter(Boolean.parseBoolean(urlParam));
    client.setRedirectUri(redirectUrl);
   
    this.oAuth2ServiceStore.addUserClient(userId, serviceName, client);
  }
View Full Code Here

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
TOP
Copyright © 2018 www.massapi.com. 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.