/**
   * Encode the user ID in a secure cookie.
   *
   * @param userId
   * @return
   */
  String encodeCookie(String userId, String tokenType) {
    if (userId == null) {
      return null;
    }
    if (clusterCookieServer != null) {
      return clusterCookieServer.encodeCookie(userId);
    } else {
      long expires = System.currentTimeMillis() + ttl;
      SecureCookie secretKeyHolder = tokenStore.getActiveToken();

      try {
        return secretKeyHolder.encode(expires, userId, tokenType);
      } catch (NoSuchAlgorithmException e) {
        LOG.error(e.getMessage(), e);
      } catch (InvalidKeyException e) {
        LOG.error(e.getMessage(), e);
      } catch (IllegalStateException e) {
        LOG.error(e.getMessage(), e);
      } catch (UnsupportedEncodingException e) {
        LOG.error(e.getMessage(), e);
      } catch (SecureCookieException e) {
        if (e.isError()) {
          LOG.error(e.getMessage(), e);
        } else {
          LOG.info(e.getMessage(), e);
        }
      }
      return null;
    }
  }
 /**
  * Decode the user ID.
  *
  * @param value
  * @return
  */
 String[] decodeCookie(String value) {
   if (value == null) {
     return null;
   }
   if (clusterCookieServer != null) {
     return clusterCookieServer.decodeCookie(value);
   } else {
     try {
       SecureCookie secureCookie = tokenStore.getSecureCookie();
       return secureCookie.decode(value);
     } catch (SecureCookieException e) {
       if (e.isError()) {
         LOG.error(e.getMessage());
       } else {
         LOG.info(e.getMessage());
       }
     }
   }
   return null;
 }