/** * Generates a token from an input string * @param token String form of token * @param maxAge max age of the token (in seconds) * @throws BlobCrypterException never */ public BasicSecurityToken(String token, int maxAge, String activeUrl) throws BlobCrypterException { this.token = token; this.tokenData = crypter.unwrap(token, maxAge); this.activeUrl = activeUrl; }
/** * Generates a token from an input string * @param token String form of token * @param maxAge max age of the token (in seconds) * @throws BlobCrypterException never */ public BasicSecurityToken(String token, int maxAge, String activeUrl) throws BlobCrypterException { this.token = token; this.tokenData = crypter.unwrap(token, maxAge); this.activeUrl = activeUrl; }
public OAuthCallbackState(BlobCrypter crypter, String stateBlob) { this.crypter = crypter; Map<String, String> state = Maps.newHashMap(); if (stateBlob != null) { try { state = crypter.unwrap(stateBlob, CALLBACK_STATE_MAX_AGE_SECS); } catch (BlobCrypterException e) { // Too old, or corrupt. Ignore it. } } if (state == null) { state = Maps.newHashMap(); } this.state = state; }
public OAuthCallbackState(BlobCrypter crypter, String stateBlob) { this.crypter = crypter; Map<String, String> state = Maps.newHashMap(); if (stateBlob != null) { try { state = crypter.unwrap(stateBlob, CALLBACK_STATE_MAX_AGE_SECS); } catch (BlobCrypterException e) { // Too old, or corrupt. Ignore it. } } if (state == null) { state = Maps.newHashMap(); } this.state = state; }
/** * Initialize client state based on an encrypted blob passed by the * client. * * @param crypter * @param stateBlob */ public OAuthClientState(BlobCrypter crypter, String stateBlob) { this.crypter = crypter; Map<String, String> state = null; if (stateBlob != null) { try { state = crypter.unwrap(stateBlob, CLIENT_STATE_MAX_AGE_SECS); } catch (BlobCrypterException e) { // Probably too old, pretend we never saw it at all. } } if (state == null) { state = Maps.newHashMap(); } this.state = state; }
/** * Initialize client state based on an encrypted blob passed by the * client. * * @param crypter * @param stateBlob */ public OAuthClientState(BlobCrypter crypter, String stateBlob) { this.crypter = crypter; Map<String, String> state = null; if (stateBlob != null) { try { state = crypter.unwrap(stateBlob, CLIENT_STATE_MAX_AGE_SECS); } catch (BlobCrypterException e) { // Probably too old, pretend we never saw it at all. } } if (state == null) { state = Maps.newHashMap(); } this.state = state; }
@Override public SecurityToken decryptSecurityToken(String encryptedSecurityToken) throws SecurityTokenException { SecurityToken securityToken; try { if (logger.isTraceEnabled()) { logger.trace("Decrypting security token: " + encryptedSecurityToken); } //Remove the header container string and : encryptedSecurityToken = encryptedSecurityToken.substring((container + ":").length()); //Decrypt Map<String, String> values = blobCrypter.unwrap(encryptedSecurityToken); securityToken = new BlobCrypterSecurityToken(container, domain, null, values); } catch (Exception e) { throw new SecurityTokenException("Error creating security token from encrypted string: " + encryptedSecurityToken, e); } return securityToken; }
public OAuthCallbackState(BlobCrypter crypter, String stateBlob) { this.crypter = crypter; Map<String, String> state = null; if (stateBlob != null) { try { state = crypter.unwrap(stateBlob); if (state == null) { state = Maps.newHashMap(); } this.state = new OAuthCallbackStateToken(state); this.state.enforceNotExpired(); } catch (BlobCrypterException e) { // Too old, or corrupt. Ignore it. state = null; } } if (state == null) { this.state = new OAuthCallbackStateToken(); } }
/** * Decrypt and verify a token. Note this is not public, use BlobCrypterSecurityTokenCodec * instead. * * @param crypter crypter to use for decryption * @param container container that minted the token * @param domain oauth_consumer_key to use for signed fetch with default key * @param token the encrypted token (just the portion after the first ":") * @return the decrypted, verified token. * * @throws BlobCrypterException */ static BlobCrypterSecurityToken decrypt(BlobCrypter crypter, String container, String domain, String token, String activeUrl) throws BlobCrypterException { Map<String, String> values = crypter.unwrap(token, MAX_TOKEN_LIFETIME_SECS); BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(crypter, container, domain); setTokenValues(t, values); t.setActiveUrl(activeUrl); return t; }
/** * Decrypt and verify a token. Note this is not public, use BlobCrypterSecurityTokenCodec * instead. * * @param crypter crypter to use for decryption * @param container container that minted the token * @param domain oauth_consumer_key to use for signed fetch with default key * @param token the encrypted token (just the portion after the first ":") * @return the decrypted, verified token. * * @throws BlobCrypterException */ static BlobCrypterSecurityToken decrypt(BlobCrypter crypter, String container, String domain, String token, String activeUrl) throws BlobCrypterException { Map<String, String> values = crypter.unwrap(token, MAX_TOKEN_LIFETIME_SECS); BlobCrypterSecurityToken t = new BlobCrypterSecurityToken(crypter, container, domain); setTokenValues(t, values); t.setActiveUrl(activeUrl); return t; }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob); }
@Test public void testFixedKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("0123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); Map<String, String> out = alt.unwrap(blob); assertEquals("b", out.get("a")); }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes()); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob, 30); }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob); }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes()); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob, 30); }
@Test(expected=BlobCrypterException.class) public void testBadKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("1123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); alt.unwrap(blob); }
@Test public void testFixedKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("0123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); Map<String, String> out = alt.unwrap(blob); assertEquals("b", out.get("a")); }
@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")); }
@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")); }
@Test public void testFixedKey() throws Exception { BlobCrypter alt = new BasicBlobCrypter("0123456789abcdef".getBytes(),HMACType.HMACSHA1); Map<String, String> in = ImmutableMap.of("a","b"); String blob = crypter.wrap(in); Map<String, String> out = alt.unwrap(blob); assertEquals("b", out.get("a")); }