/*
   * (non-Javadoc)
   *
   * @see
   * com.newtouch.lion.dsession.store.DistributedCookieStore#invalidate(com
   * .newtouch.lion.session.context.RequestContext)
   */
  @Override
  public void invalidate(DistributedSessionContext sessionContext) {
    Cookie[] cookies = sessionContext.getRequest().getCookies();
    // 判断是否为空
    if (cookies == null || cookies.length == 0) {
      return;
    }

    for (Cookie cookie : cookies) {
      String cookieName = cookie.getName();
      String decodeCookieName = cookieName;
      // 编码
      if (distributedCookieAttributeConfig.getEncoder() != null) {
        decodeCookieName =
            distributedCookieAttributeConfig.getEncoder().encodeName(decodeCookieName);
      }

      if (distributedCookieAttributeConfig.isMatch(decodeCookieName)) {
        cookie.setDomain(distributedCookieAttributeConfig.getDomain());
        cookie.setPath(distributedCookieAttributeConfig.getPath());
        cookie.setSecure(distributedCookieAttributeConfig.isSecure());
        cookie.setMaxAge(0);
        sessionContext.getResponse().addCookie(cookie);
      }
    }
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * com.newtouch.lion.dsession.store.DistributedCookieStore#removeAttribute
   * (com.newtouch.lion.session.context.SessionRequestContext,
   * java.lang.String)
   */
  @Override
  public void removeAttribute(DistributedSessionContext requestContext, String key) {
    if (key == null) {
      return;
    }

    String decodeCookieName = key;
    if (distributedCookieAttributeConfig.getEncoder() != null) {
      decodeCookieName = distributedCookieAttributeConfig.getEncoder().encodeName(decodeCookieName);
    }
    Cookie cookie = new Cookie(decodeCookieName, null);
    cookie.setDomain(distributedCookieAttributeConfig.getDomain());
    cookie.setPath(distributedCookieAttributeConfig.getPath());
    cookie.setSecure(distributedCookieAttributeConfig.isSecure());
    cookie.setMaxAge(0);
    logger.debug("Remove-cookie: {}", key);
    requestContext.getResponse().addCookie(cookie);
  }