/** Finishes the execution context */
  public static void finish() {
    Connection conn = JForumExecutionContext.getConnection(false);

    if (conn != null) {
      if (SystemGlobals.getBoolValue(ConfigKeys.DATABASE_USE_TRANSACTIONS)) {
        if (JForumExecutionContext.shouldRollback()) {
          try {
            conn.rollback();
          } catch (Exception e) {
            logger.error("Error while rolling back a transaction", e);
          }
        } else {
          try {
            conn.commit();
          } catch (Exception e) {
            logger.error("Error while commiting a transaction", e);
          }
        }
      }

      try {
        DBConnection.getImplementation().releaseConnection(conn);
      } catch (Exception e) {
        logger.error("Error while releasing the connection : " + e, e);
      }
    }

    userData.set(null);
  }
Ejemplo n.º 2
0
  private void removePosts(List posts) {
    PreparedStatement post = null;
    PreparedStatement text = null;

    try {
      post =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.deletePost"));

      text =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.deletePostText"));

      for (Iterator iter = posts.iterator(); iter.hasNext(); ) {
        Post p = (Post) iter.next();

        post.setInt(1, p.getId());
        text.setInt(1, p.getId());

        text.executeUpdate();
        post.executeUpdate();

        SearchFacade.delete(p);
      }
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(post);
      DbUtils.close(text);
    }
  }
Ejemplo n.º 3
0
  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
  }
Ejemplo n.º 4
0
  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;
  }
Ejemplo n.º 5
0
  /**
   * Setup optios and values for the user's session if authentication was ok.
   *
   * @param userSession The UserSession instance of the user
   * @param user The User instance of the authenticated user
   */
  protected void configureUserSession(UserSession userSession, User user) {

    LOG.trace("configureUserSession");
    userSession.dataToUser(user);

    // As an user may come back to the forum before its
    // last visit's session expires, we should check for
    // existent user information and then, if found, store
    // it to the database before getting his information back.
    String sessionId = SessionFacade.isUserInSession(user.getId());

    UserSession tmpUs;
    if (sessionId != null) {
      SessionFacade.storeSessionData(sessionId, JForumExecutionContext.getConnection());
      tmpUs = SessionFacade.getUserSession(sessionId);
      SessionFacade.remove(sessionId);
    } else {
      UserSessionDAO sm = DataAccessDriver.getInstance().newUserSessionDAO();
      tmpUs = sm.selectById(userSession, JForumExecutionContext.getConnection());
    }

    if (tmpUs == null) {
      userSession.setLastVisit(new Date(System.currentTimeMillis()));
    } else {
      // Update last visit and session start time
      userSession.setLastVisit(new Date(tmpUs.getStartTime().getTime() + tmpUs.getSessionTime()));
    }

    // If the execution point gets here, then the user
    // has chosen "autoLogin"
    userSession.setAutoLogin(true);
    SessionFacade.makeLogged();

    I18n.load(user.getLang());
  }
Ejemplo n.º 6
0
  /**
   * Gets the message text to send in the email.
   *
   * @param messageFile The optional message file to load the text.
   * @throws Exception
   */
  protected void createTemplate(final String messageFile) throws IOException {
    String templateEncoding = SystemGlobals.getValue(ConfigKeys.MAIL_TEMPLATE_ENCODING);

    if (StringUtils.isEmpty(templateEncoding)) {
      this.template = JForumExecutionContext.getTemplateConfig().getTemplate(messageFile);
    } else {
      this.template =
          JForumExecutionContext.getTemplateConfig().getTemplate(messageFile, templateEncoding);
    }
  }
Ejemplo n.º 7
0
  /** @see net.jforum.model.PostModel#countPreviousPosts(int) */
  public int countPreviousPosts(int postId) {
    int total = 0;

    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.countPreviousPosts"));
      p.setInt(1, postId);
      p.setInt(2, postId);

      rs = p.executeQuery();

      if (rs.next()) {
        total = rs.getInt(1);
      }

      return total;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
Ejemplo n.º 8
0
  public List selectHotForRSS(int limit) {
    List l = new ArrayList();

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.selectHotForRSS"));
      p.setInt(1, limit);

      rs = p.executeQuery();

      while (rs.next()) {
        Post post = this.buildPostForRSS(rs);
        l.add(post);
      }

    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }

    return l;
  }
Ejemplo n.º 9
0
  public int countUserPosts(int userId) {
    int total = 0;

    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(
                  SystemGlobals.getSql("PostModel.countUserPosts")
                      .replaceAll(":fids:", ForumRepository.getListAllowedForums()));
      p.setInt(1, userId);

      rs = p.executeQuery();

      if (rs.next()) {
        total = rs.getInt(1);
      }

      return total;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
Ejemplo n.º 10
0
  /** @see net.jforum.dao.PostDAO#selectByUserByLimit(int, int, int) */
  public List selectByUserByLimit(int userId, int startFrom, int count) {
    String sql = SystemGlobals.getSql("PostModel.selectByUserByLimit");
    sql = sql.replaceAll(":fids:", ForumRepository.getListAllowedForums());

    PreparedStatement p = null;
    ResultSet rs = null;
    try {
      p = JForumExecutionContext.getConnection().prepareStatement(sql);

      p.setInt(1, userId);
      p.setInt(2, startFrom);
      p.setInt(3, count);

      rs = p.executeQuery();
      List l = new ArrayList();

      while (rs.next()) {
        l.add(this.makePost(rs));
      }

      return l;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
Ejemplo n.º 11
0
  /** @see net.jforum.dao.PostDAO#selectAllBytTopicByLimit(int, int, int) */
  public List selectAllByTopicByLimit(int topicId, int startFrom, int count) {
    List l = new ArrayList();

    String sql = SystemGlobals.getSql("PostModel.selectAllByTopicByLimit");

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p = JForumExecutionContext.getConnection().prepareStatement(sql);
      p.setInt(1, topicId);
      p.setInt(2, startFrom);
      p.setInt(3, count);

      rs = p.executeQuery();

      while (rs.next()) {
        l.add(this.makePost(rs));
      }

      return l;
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
Ejemplo n.º 12
0
  protected RoleCollection loadRoles(int[] groupIds) {
    String sql = SystemGlobals.getSql("PermissionControl.loadGroupRoles");
    String groupIdAsString = SecurityCommon.groupIdAsString(groupIds);

    if ("".equals(groupIdAsString)) {
      // We suppose there is no "negative" group ids
      sql = sql.replaceAll("#IN#", "-1");
    } else {
      sql = sql.replaceAll("#IN#", groupIdAsString);
    }

    RoleCollection roles = new RoleCollection();

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p = JForumExecutionContext.getConnection().prepareStatement(sql);
      rs = p.executeQuery();

      roles = SecurityCommon.loadRoles(rs);
    } catch (Exception e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }

    return roles;
  }
Ejemplo n.º 13
0
  public void deleteForumRoles(int forumId) {
    PreparedStatement p = null;

    List roleIds = this.selectForumRoles(forumId);

    try {
      StringBuffer ids = new StringBuffer();

      for (Iterator iterator = roleIds.iterator(); iterator.hasNext(); ) {
        Integer id = (Integer) iterator.next();
        ids.append(id).append(',');
      }

      ids.append("-1");

      // Role values
      String sql = SystemGlobals.getSql("PermissionControl.deleteRoleValues");
      sql = StringUtils.replace(sql, "#IDS#", ids.toString());

      p = JForumExecutionContext.getConnection().prepareStatement(sql);
      p.setString(1, String.valueOf(forumId));
      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
Ejemplo n.º 14
0
  private List selectForumRoles(int forumId) {
    List l = new ArrayList();

    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.selectForumRoles"));
      p.setString(1, String.valueOf(forumId));

      rs = p.executeQuery();

      while (rs.next()) {
        l.add(new Integer(rs.getInt("role_id")));
      }
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }

    return l;
  }
Ejemplo n.º 15
0
  protected void updatePostsTable(Post post) {
    PreparedStatement p = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.updatePost"));
      p.setInt(1, post.getTopicId());
      p.setInt(2, post.getForumId());
      p.setInt(3, post.isBbCodeEnabled() ? 1 : 0);
      p.setInt(4, post.isHtmlEnabled() ? 1 : 0);
      p.setInt(5, post.isSmiliesEnabled() ? 1 : 0);
      p.setInt(6, post.isSignatureEnabled() ? 1 : 0);
      p.setTimestamp(7, new Timestamp(System.currentTimeMillis()));
      p.setInt(8, post.getEditCount() + 1);
      p.setString(9, post.getUserIp());
      p.setInt(10, post.getId());

      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
Ejemplo n.º 16
0
  /** @see net.jforum.model.PostModel#deleteByTopic(int) */
  public void deleteByTopic(int topicId) {
    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.deleteByTopic"));
      p.setInt(1, topicId);
      rs = p.executeQuery();

      List posts = new ArrayList();

      while (rs.next()) {
        Post post = new Post();
        post.setId(rs.getInt("post_id"));
        post.setUserId(rs.getInt("user_id"));

        posts.add(post);
      }

      this.removePosts(posts);
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
Ejemplo n.º 17
0
  /**
   * Setup common variables used by almost all templates.
   *
   * @param context SimpleHash The context to use
   * @param jforumContext JForumContext
   */
  public void prepareTemplateContext(SimpleHash context, ForumContext jforumContext) {
    RequestContext request = JForumExecutionContext.getRequest();

    context.put("karmaEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_KARMA_ENABLED));
    context.put("dateTimeFormat", SystemGlobals.getValue(ConfigKeys.DATE_TIME_FORMAT));
    context.put("autoLoginEnabled", SystemGlobals.getBoolValue(ConfigKeys.AUTO_LOGIN_ENABLED));
    context.put(
        "sso", ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE)));
    context.put("contextPath", request.getContextPath());
    context.put("serverName", request.getServerName());
    context.put("templateName", SystemGlobals.getValue(ConfigKeys.TEMPLATE_DIR));
    context.put("extension", SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION));
    context.put("serverPort", Integer.toString(request.getServerPort()));
    context.put("I18n", I18n.getInstance());
    context.put("version", SystemGlobals.getValue(ConfigKeys.VERSION));
    context.put("forumTitle", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_TITLE));
    context.put("pageTitle", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_TITLE));
    context.put("metaKeywords", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_METATAG_KEYWORDS));
    context.put(
        "metaDescription", SystemGlobals.getValue(ConfigKeys.FORUM_PAGE_METATAG_DESCRIPTION));
    context.put("forumLink", SystemGlobals.getValue(ConfigKeys.FORUM_LINK));
    context.put("homepageLink", SystemGlobals.getValue(ConfigKeys.HOMEPAGE_LINK));
    context.put("encoding", SystemGlobals.getValue(ConfigKeys.ENCODING));
    context.put(
        "bookmarksEnabled", SecurityRepository.canAccess(SecurityConstants.PERM_BOOKMARKS_ENABLED));
    context.put(
        "canAccessModerationLog",
        SecurityRepository.canAccess(SecurityConstants.PERM_MODERATION_LOG));
    context.put("JForumContext", jforumContext);
    context.put("timestamp", new Long(System.currentTimeMillis()));
  }
Ejemplo n.º 18
0
  /**
   * Do a refresh in the user's session. This method will update the last visit time for the current
   * user, as well checking for authentication if the session is new or the SSO user has changed
   */
  public void refreshSession() {

    LOG.trace("refreshSession");
    UserSession userSession = SessionFacade.getUserSession();
    RequestContext request = JForumExecutionContext.getRequest();

    if (userSession == null) {
      userSession = new UserSession();
      userSession.registerBasicInfo();
      userSession.setSessionId(request.getSessionContext().getId());
      userSession.setIp(request.getRemoteAddr());
      SessionFacade.makeUnlogged();

      if (!JForumExecutionContext.getForumContext().isBot()) {
        // Non-SSO authentications can use auto login
        if (!ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
          if (SystemGlobals.getBoolValue(ConfigKeys.AUTO_LOGIN_ENABLED)) {
            this.checkAutoLogin(userSession);
          } else {
            userSession.makeAnonymous();
          }
        } else {
          this.checkSSO(userSession);
        }
      }

      SessionFacade.add(userSession);
    } else if (ConfigKeys.TYPE_SSO.equals(SystemGlobals.getValue(ConfigKeys.AUTHENTICATION_TYPE))) {
      SSO sso;

      try {
        sso =
            (SSO)
                Class.forName(SystemGlobals.getValue(ConfigKeys.SSO_IMPLEMENTATION)).newInstance();
      } catch (Exception e) {
        throw new ForumException(e);
      }

      // If SSO, then check if the session is valid
      if (!sso.isSessionValid(userSession, request)) {
        SessionFacade.remove(userSession.getSessionId());
        refreshSession();
      }
    } else {
      SessionFacade.getUserSession().updateSessionTime();
    }
  }
Ejemplo n.º 19
0
  /**
   * @see net.jforum.dao.GroupSecurityDAO#addRoleValue(int, net.jforum.security.Role,
   *     net.jforum.security.RoleValueCollection)
   */
  public void addRoleValue(int groupId, Role role, RoleValueCollection rvc) {
    PreparedStatement p = null;
    ResultSet rs = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.getRoleIdByName"));
      p.setString(1, role.getName());
      p.setInt(2, groupId);

      int roleId = -1;

      rs = p.executeQuery();
      if (rs.next()) {
        roleId = rs.getInt("role_id");
      }

      rs.close();
      rs = null;
      p.close();
      p = null;

      if (roleId == -1) {
        this.addRole(groupId, role, rvc);
      } else {
        p =
            JForumExecutionContext.getConnection()
                .prepareStatement(SystemGlobals.getSql("PermissionControl.addRoleValues"));
        p.setInt(1, roleId);

        for (Iterator iter = rvc.iterator(); iter.hasNext(); ) {
          RoleValue rv = (RoleValue) iter.next();
          p.setString(2, rv.getValue());
          p.executeUpdate();
        }
      }
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(rs, p);
    }
  }
  public static Connection getConnection(boolean validate) {
    JForumExecutionContext ex = get();
    Connection c = ex.conn;

    if (validate && c == null) {
      c = DBConnection.getImplementation().getConnection();

      try {
        c.setAutoCommit(!SystemGlobals.getBoolValue(ConfigKeys.DATABASE_USE_TRANSACTIONS));
      } catch (Exception e) {
        e.printStackTrace();
        // catch error autocommit
      }

      ex.setConnection(c);
      set(ex);
    }

    return c;
  }
Ejemplo n.º 21
0
  /**
   * Checks for user authentication using some SSO implementation
   *
   * @param userSession UserSession
   */
  protected void checkSSO(UserSession userSession) {

    LOG.trace("checkSSO");
    try {
      SSO sso =
          (SSO) Class.forName(SystemGlobals.getValue(ConfigKeys.SSO_IMPLEMENTATION)).newInstance();
      String username = sso.authenticateUser(JForumExecutionContext.getRequest());

      if (username == null || username.trim().equals("")) {
        userSession.makeAnonymous();
      } else {
        SSOUtils utils = new SSOUtils();

        if (!utils.userExists(username)) {
          SessionContext session = JForumExecutionContext.getRequest().getSessionContext();

          String email =
              (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_EMAIL_ATTRIBUTE));
          String password =
              (String)
                  session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_PASSWORD_ATTRIBUTE));

          if (email == null) {
            email = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_EMAIL);
          }

          if (password == null) {
            password = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_PASSWORD);
          }

          utils.register(password, email);
        }

        this.configureUserSession(userSession, utils.getUser());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw new ForumException("Error while executing SSO actions: " + e);
    }
  }
Ejemplo n.º 22
0
  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    try {
      String appPath = config.getServletContext().getRealPath("");
      // 是否为开发mode
      debug = "true".equals(config.getInitParameter("development"));
      // 读取log4j.xml配置文件
      DOMConfigurator.configure(appPath + "/WEB-INF/log4j.xml");

      logger.info("Starting JForum. Debug mode is " + debug);
      //
      ConfigLoader.startSystemglobals(appPath);
      // 启动缓存引擎
      ConfigLoader.startCacheEngine();

      // Configure the template engine
      Configuration templateCfg = new Configuration();
      templateCfg.setTemplateUpdateDelay(2);
      templateCfg.setSetting("number_format", "#");
      templateCfg.setSharedVariable("startupTime", new Long(new Date().getTime()));

      // Create the default template loader
      String defaultPath = SystemGlobals.getApplicationPath() + "/templates";
      FileTemplateLoader defaultLoader = new FileTemplateLoader(new File(defaultPath));

      String extraTemplatePath = SystemGlobals.getValue(ConfigKeys.FREEMARKER_EXTRA_TEMPLATE_PATH);

      if (StringUtils.isNotBlank(extraTemplatePath)) {
        // An extra template path is configured, we need a MultiTemplateLoader
        FileTemplateLoader extraLoader = new FileTemplateLoader(new File(extraTemplatePath));
        TemplateLoader[] loaders = new TemplateLoader[] {extraLoader, defaultLoader};
        MultiTemplateLoader multiLoader = new MultiTemplateLoader(loaders);
        templateCfg.setTemplateLoader(multiLoader);
      } else {
        // An extra template path is not configured, we only need the default loader
        templateCfg.setTemplateLoader(defaultLoader);
      }
      // 载入模块
      ModulesRepository.init(SystemGlobals.getValue(ConfigKeys.CONFIG_DIR));

      this.loadConfigStuff();

      if (!this.debug) {
        templateCfg.setTemplateUpdateDelay(3600);
      }

      JForumExecutionContext.setTemplateConfig(templateCfg);
    } catch (Exception e) {
      throw new ForumStartupException("Error while starting JForum", e);
    }
  }
Ejemplo n.º 23
0
  /**
   * Check if the logged user has access to the role. This method gets user's id from its session.
   *
   * @param roleName The role name to verify
   * @param value The value relacted to the role to verify for access
   * @return <code>true</code> if the user has access to the role, <code>false</code> if access is
   *     denied
   */
  public static boolean canAccess(String roleName, String value) {
    UserSession us = SessionFacade.getUserSession();

    if (us == null) {
      logger.warn(
          "Found null userSession. Going anonymous. Session id #"
              + JForumExecutionContext.getRequest().getSessionContext().getId());
      us = new UserSession();
      us.makeAnonymous();
    }

    return canAccess(us.getUserId(), roleName, value);
  }
Ejemplo n.º 24
0
  /** @see net.jforum.dao.security.SecurityDAO#deleteAllRoles(int) */
  public void deleteAllRoles(int groupId) {
    PreparedStatement p = null;

    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.deleteAllRoleValues"));
      p.setInt(1, groupId);
      p.executeUpdate();
      p.close();

      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PermissionControl.deleteAllGroupRoles"));
      p.setInt(1, groupId);
      p.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(p);
    }
  }
Ejemplo n.º 25
0
 /** @see net.jforum.dao.SmilieDAO#delete(int) */
 public void delete(int id) {
   PreparedStatement pstmt = null;
   try {
     pstmt =
         JForumExecutionContext.getConnection()
             .prepareStatement(SystemGlobals.getSql("SmiliesModel.delete"));
     pstmt.setInt(1, id);
     pstmt.executeUpdate();
   } catch (SQLException e) {
     throw new DatabaseException(e);
   } finally {
     DbUtils.close(pstmt);
   }
 }
Ejemplo n.º 26
0
  /**
   * Add or update a cookie. This method adds a cookie, serializing its value using XML.
   *
   * @param name The cookie name.
   * @param value The cookie value
   */
  public static void addCookie(String name, String value) {
    int maxAge = 3600 * 24 * 365;

    if (value == null) {
      maxAge = 0;
      value = "";
    }

    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);
    cookie.setPath("/");
    // TODO cookie.setDomain(SystemGlobals.getValue(ConfigKeys.));

    JForumExecutionContext.getResponse().addCookie(cookie);
  }
Ejemplo n.º 27
0
  /**
   * Gets a cookie by its name.
   *
   * @param name The cookie name to retrieve
   * @return The <code>Cookie</code> object if found, or <code>null</code> oterwhise
   */
  public static Cookie getCookie(String name) {
    Cookie[] cookies = JForumExecutionContext.getRequest().getCookies();

    if (cookies != null) {
      for (int i = 0; i < cookies.length; i++) {
        Cookie c = cookies[i];

        if (c.getName().equals(name)) {
          return c;
        }
      }
    }

    return null;
  }
Ejemplo n.º 28
0
  /**
   * Add or update a cookie. This method adds a cookie, serializing its value using XML.
   *
   * @param name The cookie name.
   * @param value The cookie value
   */
  public static void addCookie(String name, String value) {

    LOG.trace("addCookie");
    int maxAge = 3600 * 24 * 365;

    if (value == null) {
      maxAge = 0;
      value = "";
    }

    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);
    cookie.setPath("/");

    JForumExecutionContext.getResponse().addCookie(cookie);
  }
Ejemplo n.º 29
0
  protected void addNewPostText(Post post) throws Exception {
    PreparedStatement p = null;
    try {
      p =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("PostModel.addNewPostText"));
      int cIndex = 1;
      p.setInt(cIndex++, post.getId());
      p.setString(cIndex++, post.getText());
      p.setString(cIndex++, post.getSubject());

      p.executeUpdate();
    } finally {
      DbUtils.close(p);
    }
  }
Ejemplo n.º 30
0
  /** @see net.jforum.dao.SmilieDAO#update(net.jforum.entities.Smilie) */
  public void update(Smilie smilie) {
    PreparedStatement pstmt = null;
    try {
      pstmt =
          JForumExecutionContext.getConnection()
              .prepareStatement(SystemGlobals.getSql("SmiliesModel.update"));
      pstmt.setString(1, smilie.getCode());
      pstmt.setString(2, smilie.getUrl());
      pstmt.setString(3, smilie.getDiskName());
      pstmt.setInt(4, smilie.getId());

      pstmt.executeUpdate();
    } catch (SQLException e) {
      throw new DatabaseException(e);
    } finally {
      DbUtils.close(pstmt);
    }
  }