public boolean isSessionValid(UserSession userSession, RequestContext request) {
    String remoteUser = null;

    Cookie SSOCookie = ControllerUtils.getCookie("JforumSSO"); // my app login cookie
    logger.info("DEBUG - CustomSSO - isSessionValid - Getting JForumSSO Cookie!");

    if (SSOCookie != null) remoteUser = SSOCookie.getValue(); //  jforum username

    if (remoteUser == null) {
      logger.info("DEBUG - CustomSSO - isSessionValid - JForumSSO Cookie is NULL!");
      JForumExecutionContext.setRedirect(SystemGlobals.getValue(ConfigKeys.SSO_REDIRECT));
      return false;

    } else if (remoteUser.equals("")) {
      logger.info("DEBUG - CustomSSO - isSessionValid - JForumSSO Cookie is empty!");
      JForumExecutionContext.setRedirect(SystemGlobals.getValue(ConfigKeys.SSO_REDIRECT));
      return false;
      // user has since logged in
    } else if (remoteUser != null
        && userSession.getUserId() == SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
      logger.info("DEBUG - CustomSSO - isSessionValid - JForumSSO Cookie is Anonymous!");
      return false;
      // user has changed user
    } else if (remoteUser != null && !remoteUser.equals(userSession.getUsername())) {
      logger.info("DEBUG - CustomSSO - isSessionValid - JForumSSO Cookie User Mismatch");
      return false;
    }
    logger.info("DEBUG - CustomSSO - isSessionValid - Returning True");
    return true; // sso pool apps user and forum user the same
  }
  public String authenticateUser(RequestContext request) {
    Cookie cookie = ControllerUtils.getCookie("JForumSSO");
    logger.info("DEBUG - CustomSSO - authenticatUser - Getting JForumSSO Cookie!");

    String username = null;
    if (cookie == null) {
      logger.info("DEBUG - CustomSSO - authenticatUser - JForumSSO Cookie is NULL!");
      JForumExecutionContext.setRedirect(SystemGlobals.getValue(ConfigKeys.SSO_REDIRECT));

      return null;
    } else {
      username = (String) cookie.getValue();
      logger.info(
          "DEBUG - CustomSSO - authenticatUser - JForumSSO Cookie is contains username: "******"!");
      if (username.equals("")) {
        logger.info("DEBUG - CustomSSO - authenticatUser - JForumSSO Cookie is empty!");
        JForumExecutionContext.setRedirect(SystemGlobals.getValue(ConfigKeys.SSO_REDIRECT));
      }
    }
    logger.info(
        "DEBUG - CustomSSO - authenticatUser - JForumSSO is returning username: "******"!");
    return username;
  }
  /**
   * Template method to add a cookie. Useful to suatins when a subclass wants to add a cookie in a
   * fashion different than the normal behaviour
   *
   * @param name The cookie name
   * @param value The cookie value
   * @see #addCookie(String, String)
   */
  protected void addCookieTemplate(String name, String value) {

    LOG.trace("addCookieTemplate");
    ControllerUtils.addCookie(name, value);
  }
  /**
   * Template method to get a cookie. Useful to situations when a subclass wants to have a different
   * way to retrieve a cookie.
   *
   * @param name The cookie name to retrieve
   * @return The Cookie object if found, or null otherwise
   * @see #getCookie(String)
   */
  protected Cookie getCookieTemplate(String name) {

    LOG.trace("getCookieTemplate");
    return ControllerUtils.getCookie(name);
  }
 /**
  * Template method to add a cookie. Useful to suatins when a subclass wants to add a cookie in a
  * fashion different than the normal behaviour
  *
  * @param name The cookie name
  * @param value The cookie value
  * @see #addCookie(String, String)
  */
 protected void addCookieTemplate(String name, String value) {
   ControllerUtils.addCookie(name, value);
 }
 /**
  * Template method to get a cookie. Useful to situations when a subclass wants to have a different
  * way to retrieve a cookie.
  *
  * @param name The cookie name to retrieve
  * @return The Cookie object if found, or null otherwise
  * @see #getCookie(String)
  */
 protected Cookie getCookieTemplate(String name) {
   return ControllerUtils.getCookie(name);
 }