Package org.apache.shindig.common.crypto

Examples of org.apache.shindig.common.crypto.BlobCrypter


          Map<String, BlobCrypter> crypters, Map<String, String> domains,
          Map<String, Integer> tokenTTLs) throws IOException {
    for (String container : containers) {
      String key = config.getString(container, SECURITY_TOKEN_KEY);
      if (key != null) {
        BlobCrypter crypter = loadCrypter(key);
        crypters.put(container, crypter);
      }
      String domain = config.getString(container, SIGNED_FETCH_DOMAIN);
      domains.put(container, domain);
View Full Code Here


    String[] fields = StringUtils.split(token, ':');
    if (fields.length != 2) {
      throw new SecurityTokenException("Invalid security token " + token);
    }
    String container = fields[0];
    BlobCrypter crypter = crypters.get(container);
    if (crypter == null) {
      throw new SecurityTokenException("Unknown container " + token);
    }
    String domain = domains.get(container);
    String activeUrl = tokenParameters.get(SecurityTokenCodec.ACTIVE_URL_NAME);
    String crypted = fields[1];
    try {
      BlobCrypterSecurityToken st = new BlobCrypterSecurityToken(container, domain, activeUrl,
          crypter.unwrap(crypted));
      return st.enforceNotExpired();
    } catch (BlobCrypterException e) {
      throw new SecurityTokenException(e);
    }
  }
View Full Code Here

    // Test code sends in real AbstractTokens, they have modified time sources in them so
    // that we can test token expiration, production tokens are proxied via the SecurityToken interface.
    AbstractSecurityToken aToken = token instanceof AbstractSecurityToken ?
        (AbstractSecurityToken)token : BlobCrypterSecurityToken.fromToken(token);

    BlobCrypter crypter = crypters.get(aToken.getContainer());
    if (crypter == null) {
      throw new SecurityTokenException("Unknown container " + aToken.getContainer());
    }

    try {
      Integer tokenTTL = this.tokenTTLs.get(aToken.getContainer());
      if (tokenTTL != null) {
        aToken.setExpires(tokenTTL);
      } else {
        aToken.setExpires();
      }
      return aToken.getContainer() + ':' + crypter.wrap(aToken.toMap());
    } catch (BlobCrypterException e) {
      throw new SecurityTokenException(e);
    }
  }
View Full Code Here

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

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

  @Test
  public void testSetTokenForSharedClient() throws Exception {
    final OAuth2Cache cache = new InMemoryCache();
    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 );
View Full Code Here

*/
public class OAuthFetcherConfigTest extends EasyMockTestCase {

  @Test
  public void testOAuthFetcherConfig() {
    BlobCrypter crypter = mock(BlobCrypter.class);
    mock(HttpCache.class);
    GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class);
    OAuthCallbackGenerator callbackGenerator = mock(OAuthCallbackGenerator.class);
    OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, new TimeSource(),
        callbackGenerator, false);
View Full Code Here

  public BlobCrypterSecurityTokenDecoder(ContainerConfig config) {
    try {
      for (String container : config.getContainers()) {
        String keyFile = config.get(container, SECURITY_TOKEN_KEY_FILE);
        if (keyFile != null) {
          BlobCrypter crypter = loadCrypterFromFile(new File(keyFile));
          crypters.put(container, crypter);
        }
        String domain = config.get(container, SIGNED_FETCH_DOMAIN);
        domains.put(container, domain);
      }
View Full Code Here

    String[] fields = token.split(":");
    if (fields.length != 2) {
      throw new SecurityTokenException("Invalid security token " + token);
    }
    String container = fields[0];
    BlobCrypter crypter = crypters.get(container);
    if (crypter == null) {
      throw new SecurityTokenException("Unknown container " + token);
    }
    String domain = domains.get(container);
    String crypted = fields[1];
View Full Code Here

    }
  }

  @Test
  public void testFixedKey() throws Exception {
    BlobCrypter alt = new BasicBlobCrypter("0123456789abcdef".getBytes());
    Map<String, String> in = ImmutableMap.of("a","b");

    String blob = crypter.wrap(in);
    Map<String, String> out = alt.unwrap(blob, 30);
    assertEquals("b", out.get("a"));
  }
View Full Code Here

    assertEquals("b", out.get("a"));
  }

  @Test
  public void testBadKey() throws Exception {
    BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes());
    Map<String, String> in = ImmutableMap.of("a","b");

    String blob = crypter.wrap(in);
    try {
      alt.unwrap(blob, 30);
      fail("Decryption should have failed");
    } catch (BlobCrypterException e) {
      // Good.
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.shindig.common.crypto.BlobCrypter

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.