/* (non-Javadoc)
   * @see org.springframework.security.ui.rememberme.PersistentTokenRepository#getTokenForSeries(java.lang.String)
   */
  public PersistentRememberMeToken getTokenForSeries(String seriesId) {
    Cookie cookie = findById(seriesId);

    if (cookie == null) return null;

    PersistentRememberMeToken token =
        new PersistentRememberMeToken(
            cookie.getUserName(),
            cookie.getIdentifier(),
            cookie.getValue(),
            cookie.getLastUse().getTime());

    return token;
  }
  /* (non-Javadoc)
   * @see org.springframework.security.ui.rememberme.PersistentTokenRepository#createNewToken(org.springframework.security.ui.rememberme.PersistentRememberMeToken)
   */
  public void createNewToken(PersistentRememberMeToken token) {
    Cookie cookie = new Cookie();

    Calendar calendar = GregorianCalendar.getInstance();
    calendar.setTime(token.getDate());

    cookie.setLastUse(calendar);
    cookie.setIdentifier(token.getSeries());
    cookie.setUserName(token.getUsername());
    cookie.setValue(token.getTokenValue());

    try {
      create(cookie);
    } catch (BusinessException e) {
      e.printStackTrace();
    }
  }
  /* (non-Javadoc)
   * @see org.springframework.security.ui.rememberme.PersistentTokenRepository#updateToken(java.lang.String, java.lang.String, java.util.Date)
   */
  public void updateToken(String series, String tokenValue, Date lastUsed) {
    Cookie cookie = findById(series);

    if (cookie != null) {
      cookie.setValue(tokenValue);

      Calendar calendar = GregorianCalendar.getInstance();
      calendar.setTime(lastUsed);
      cookie.setLastUse(calendar);

      try {
        update(cookie);
      } catch (BusinessException e) {
        e.printStackTrace();
      }
    }
  }
 protected DetachedCriteria getNaturalKeyCriteria(Cookie entity) {
   DetachedCriteria det =
       DetachedCriteria.forClass(Cookie.class)
           .add(Restrictions.eq("identifier", entity.getIdentifier()));
   return det;
 }