Package org.apache.shindig.common.crypto

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


  private void loadContainers(ContainerConfig config, Collection<String> containers,
      Map<String, BlobCrypter> crypters, Map<String, String> domains) 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 {
      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

*/
public class OAuthFetcherConfigTest extends EasyMockTestCase {

  @Test
  public void testOAuthFetcherConfig() {
    BlobCrypter crypter = mock(BlobCrypter.class);
    HttpCache cache = mock(HttpCache.class);
    GadgetOAuthTokenStore tokenStore = mock(GadgetOAuthTokenStore.class);
    OAuthFetcherConfig config = new OAuthFetcherConfig(crypter, tokenStore, cache, new TimeSource());
    assertEquals(crypter, config.getStateCrypter());
    assertEquals(cache, config.getHttpCache());
View Full Code Here

          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

    Assert.assertNotSame("body is " + body, body.indexOf("window.close()"), -1);
  }

  @Test
  public void testServletWithCallback() throws Exception {
    BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes());
    OAuthCallbackState state = new OAuthCallbackState(crypter);
    OAuthCallbackServlet servlet = new OAuthCallbackServlet();
    servlet.setStateCrypter(crypter);
    state.setRealCallbackUrl("http://www.example.com/callback");
    expect(request.getParameter("cs")).andReturn(state.getEncryptedState());
View Full Code Here

    assertEquals("private,max-age=3600", cacheControl);
  }

  @Test
  public void testServletWithCallback_noQueryParams() throws Exception {
    BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes());
    OAuthCallbackState state = new OAuthCallbackState(crypter);
    OAuthCallbackServlet servlet = new OAuthCallbackServlet();
    servlet.setStateCrypter(crypter);
    state.setRealCallbackUrl("http://www.example.com/callback");
    expect(request.getParameter("cs")).andReturn(state.getEncryptedState());
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.