/** * 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 encodeToken(SecurityToken token) throws SecurityTokenException { if (!token.getAuthenticationMode().equals( AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name())) { throw new SecurityTokenException("Can only encode BlobCrypterSecurityTokens"); } // 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); } }
/** * 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 encodeToken(SecurityToken token) throws SecurityTokenException { if (!token.getAuthenticationMode().equals( AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name())) { throw new SecurityTokenException("Can only encode BlobCrypterSecurityTokens"); } // 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); } }
/** * 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 encodeToken(SecurityToken token) throws SecurityTokenException { if (!token.getAuthenticationMode().equals( AuthenticationMode.SECURITY_TOKEN_URL_PARAMETER.name())) { throw new SecurityTokenException("Can only encode BlobCrypterSecurityTokens"); } // 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); } }