/** * 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; }
/** * @return an encrypted blob of state to store with the client. * @throws BlobCrypterException */ public String getEncryptedState() throws BlobCrypterException { return crypter.wrap(state); }
/** * 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; }
/** * @return an encrypted blob of state to store with the client. * @throws BlobCrypterException */ public String getEncryptedState() throws BlobCrypterException { return crypter.wrap(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; }
public String getEncryptedState() throws BlobCrypterException { return crypter.wrap(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; }
public String getEncryptedState() throws BlobCrypterException { return crypter.wrap(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; }
public String getEncryptedState() throws BlobCrypterException { String ret = null; if (this.crypter != null) { ret = this.crypter.wrap(this.state.toMap()); } return ret; }
/** * 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; }
/** * Encrypt and sign the token. The returned value is *not* web safe, it should be URL * encoded before being used as a form parameter. */ public String encrypt() throws BlobCrypterException { Map<String, String> values = buildValuesMap(); return container + ':' + crypter.wrap(values); }
@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; }
/** * Encrypt and sign the token. The returned value is *not* web safe, it should be URL * encoded before being used as a form parameter. */ public String encrypt() throws BlobCrypterException { Map<String, String> values = buildValuesMap(); return container + ':' + crypter.wrap(values); }
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(); } }
public String getEncryptedState() throws BlobCrypterException { return crypter.wrap(state.toMap()); }
/** * Decrypt and verify the provided security token. */ public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { String token = tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME); if (StringUtils.isBlank(token)) { // No token is present, assume anonymous access return new AnonymousSecurityToken(); } 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); } }
private String encryptSecurityToken(BlobCrypterSecurityToken securityToken) throws SecurityTokenException { String encryptedToken = null; try { encryptedToken = container + ":" + blobCrypter.wrap(securityToken.toMap()); if (logger.isTraceEnabled()) { logger.trace("Encrypted token created from security token: " + securityToken.toString() + " -- encrypted token is: " + encryptedToken); } } catch (Exception e) { throw new SecurityTokenException("Error creating security token from person gadget", e); } return encryptedToken; } }
/** * Decrypt and verify the provided security token. */ public SecurityToken createToken(Map<String, String> tokenParameters) throws SecurityTokenException { String token = tokenParameters.get(SecurityTokenCodec.SECURITY_TOKEN_NAME); if (StringUtils.isBlank(token)) { // No token is present, assume anonymous access return new AnonymousSecurityToken(); } 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); } }
/** * @return an encrypted blob of state to store with the client. * @throws BlobCrypterException */ public String getEncryptedState() throws BlobCrypterException { setExpires(); Map<String, String> map = this.toMap(); map.putAll(state); return crypter.wrap(map); }