예제 #1
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
  }
예제 #2
0
  /**
   * @see #getAllCategoriesAndForums(boolean)
   * @return List
   */
  public static List getAllCategoriesAndForums() {

    LOG.trace("getAllCategoriesAndForums");
    UserSession us = SessionFacade.getUserSession();
    boolean checkUnread =
        (us != null && us.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID));
    return getAllCategoriesAndForums(checkUnread);
  }
예제 #3
0
  /**
   * @see #getAllCategoriesAndForums(UserSession, int, Map, boolean)
   * @return List
   * @param checkUnreadPosts boolean
   */
  public static List getAllCategoriesAndForums(boolean checkUnreadPosts) {

    LOG.trace("getAllCategoriesAndForums");
    return getAllCategoriesAndForums(
        SessionFacade.getUserSession(),
        SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID),
        SessionFacade.getTopicsReadTime(),
        checkUnreadPosts);
  }
예제 #4
0
  /** @param u User */
  private static void handleAvatar(User u) {

    LOG.trace("handleAvatar");
    String fileName = MD5.crypt(Integer.toString(u.getId()));
    FileItem item = (FileItem) JForumExecutionContext.getRequest().getObjectParameter("avatar");
    UploadUtils uploadUtils = new UploadUtils(item);

    // Gets file extension
    String extension = uploadUtils.getExtension().toLowerCase();
    int type = ImageUtils.IMAGE_UNKNOWN;

    if (extension.equals("jpg") || extension.equals("jpeg")) {
      type = ImageUtils.IMAGE_JPEG;
    } else if (extension.equals("gif") || extension.equals("png")) {
      type = ImageUtils.IMAGE_PNG;
    }

    if (type != ImageUtils.IMAGE_UNKNOWN) {
      String avatarTmpFileName =
          SystemGlobals.getApplicationPath() + "/images/avatar/" + fileName + "_tmp." + extension;

      // We cannot handle gifs
      if (extension.toLowerCase().equals("gif")) {
        extension = "png";
      }

      String avatarFinalFileName =
          SystemGlobals.getApplicationPath() + "/images/avatar/" + fileName + "." + extension;

      uploadUtils.saveUploadedFile(avatarTmpFileName);

      // OK, time to check and process the avatar size
      int maxWidth = SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_WIDTH);
      int maxHeight = SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_HEIGHT);

      BufferedImage image = ImageUtils.resizeImage(avatarTmpFileName, type, maxWidth, maxHeight);
      ImageUtils.saveImage(image, avatarFinalFileName, type);

      u.setAvatar(fileName + "." + extension);

      // Delete the temporary file
      new File(avatarTmpFileName).delete();
    }
  }
예제 #5
0
파일: I18n.java 프로젝트: dgkim11/examples
  private static void watchForChanges(final String localeName) {
    if (!watching.contains(localeName)) {
      watching.add(localeName);

      int fileChangesDelay = SystemGlobals.getIntValue(ConfigKeys.FILECHANGES_DELAY);

      if (fileChangesDelay > 0) {
        FileMonitor.getInstance()
            .addFileChangeListener(
                new FileChangeListener() {
                  /** @see net.jforum.util.FileChangeListener#fileChanged(java.lang.String) */
                  public void fileChanged(String filename) {
                    if (logger.isDebugEnabled()) {
                      logger.info("Reloading i18n for " + localeName);
                    }

                    I18n.load(localeName, SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT), true);
                  }
                },
                baseDir + localeNames.getProperty(localeName),
                fileChangesDelay);
      }
    }
  }
예제 #6
0
  public boolean dispatchMessages() {
    try {
      int sendDelay = SystemGlobals.getIntValue(ConfigKeys.MAIL_SMTP_DELAY);

      if (SystemGlobals.getBoolValue(ConfigKeys.MAIL_SMTP_AUTH)) {
        if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) {
          boolean ssl = SystemGlobals.getBoolValue(ConfigKeys.MAIL_SMTP_SSL);

          Transport transport = this.session.getTransport(ssl ? "smtps" : "smtp");

          try {
            String host = SystemGlobals.getValue(ConfigKeys.MAIL_SMTP_HOST);

            transport.connect(host, username, password);

            if (transport.isConnected()) {
              for (Iterator<User> userIter = this.users.iterator(); userIter.hasNext(); ) {
                User user = userIter.next();

                if (this.needCustomization) {
                  this.defineUserMessage(user);
                }

                if (StringUtils.isNotEmpty(user.getEmail())) {
                  Address address = new InternetAddress(user.getEmail());
                  LOGGER.debug("Sending mail to: " + user.getEmail());
                  this.message.setRecipient(Message.RecipientType.TO, address);
                  Stats.record("Sent email", user.getEmail());
                  transport.sendMessage(this.message, new Address[] {address});
                }
                if (sendDelay > 0) {
                  try {
                    Thread.sleep(sendDelay);
                  } catch (InterruptedException ie) {
                    LOGGER.error("Error while Thread.sleep." + ie, ie);
                  }
                }
              }
            }
          } catch (Exception e) {
            throw new MailException(e);
          } finally {
            try {
              transport.close();
            } catch (Exception e) {
              LOGGER.error(e);
            }
          }
        }
      } else {
        for (Iterator<User> iter = this.users.iterator(); iter.hasNext(); ) {
          User user = iter.next();

          if (this.needCustomization) {
            this.defineUserMessage(user);
          }

          if (StringUtils.isNotEmpty(user.getEmail())) {
            Address address = new InternetAddress(user.getEmail());
            LOGGER.debug("Sending mail to: " + user.getEmail());
            this.message.setRecipient(Message.RecipientType.TO, address);
            Stats.record("Sent email", user.getEmail());
            Transport.send(this.message, new Address[] {address});
          }
          if (sendDelay > 0) {
            try {
              Thread.sleep(sendDelay);
            } catch (InterruptedException ie) {
              LOGGER.error("Error while Thread.sleep." + ie, ie);
            }
          }
        }
      }
    } catch (MessagingException e) {
      LOGGER.error("Error while dispatching the message. " + e, e);
    }

    return true;
  }
예제 #7
0
  /**
   * Updates the user information
   *
   * @param userId int The user id we are saving
   * @return List
   */
  public static List saveUser(int userId) {

    LOG.trace("saveUser");
    List errors = new ArrayList();

    UserDAO um = DataAccessDriver.getInstance().newUserDAO();
    User u = um.selectById(userId);

    RequestContext request = JForumExecutionContext.getRequest();
    boolean isAdmin = SessionFacade.getUserSession().isAdmin();

    if (isAdmin) {
      String username = request.getParameter("username");

      if (username != null) {
        u.setUsername(username.trim());
      }

      if (request.getParameter("rank_special") != null) {
        u.setRankId(request.getIntParameter("rank_special"));
      }
    }

    SafeHtml safeHtml = new SafeHtml();

    u.setId(userId);
    u.setIcq(safeHtml.makeSafe(request.getParameter("icq")));
    u.setAim(safeHtml.makeSafe(request.getParameter("aim")));
    u.setMsnm(safeHtml.makeSafe(request.getParameter("msn")));
    u.setYim(safeHtml.makeSafe(request.getParameter("yim")));
    u.setFrom(safeHtml.makeSafe(request.getParameter("location")));
    u.setOccupation(safeHtml.makeSafe(request.getParameter("occupation")));
    u.setInterests(safeHtml.makeSafe(request.getParameter("interests")));
    u.setBiography(safeHtml.makeSafe(request.getParameter("biography")));
    u.setSignature(safeHtml.makeSafe(request.getParameter("signature")));
    u.setViewEmailEnabled(request.getParameter("viewemail").equals("1"));
    u.setViewOnlineEnabled(request.getParameter("hideonline").equals("0"));
    u.setNotifyPrivateMessagesEnabled(request.getParameter("notifypm").equals("1"));
    u.setNotifyOnMessagesEnabled(request.getParameter("notifyreply").equals("1"));
    u.setAttachSignatureEnabled(request.getParameter("attachsig").equals("1"));
    u.setHtmlEnabled(request.getParameter("allowhtml").equals("1"));
    u.setLang(request.getParameter("language"));
    u.setBbCodeEnabled("1".equals(request.getParameter("allowbbcode")));
    u.setSmiliesEnabled("1".equals(request.getParameter("allowsmilies")));
    u.setNotifyAlways("1".equals(request.getParameter("notify_always")));
    u.setNotifyText("1".equals(request.getParameter("notify_text")));

    String website = safeHtml.makeSafe(request.getParameter("website"));

    if (!StringUtils.isEmpty(website) && !website.toLowerCase().startsWith("http://")) {
      website = "http://" + website;
    }

    u.setWebSite(website);

    String currentPassword = request.getParameter("current_password");
    boolean isCurrentPasswordEmpty = currentPassword == null || "".equals(currentPassword.trim());

    if (isAdmin || !isCurrentPasswordEmpty) {
      if (!isCurrentPasswordEmpty) {
        currentPassword = MD5.crypt(currentPassword);
      }

      if (isAdmin || u.getPassword().equals(currentPassword)) {
        u.setEmail(safeHtml.makeSafe(request.getParameter("email")));

        String newPassword = request.getParameter("new_password");

        if (newPassword != null && newPassword.length() > 0) {
          u.setPassword(MD5.crypt(newPassword));
        }
      } else {
        errors.add(I18n.getMessage("User.currentPasswordInvalid"));
      }
    }

    if (request.getParameter("avatardel") != null) {
      File avatarFile = new File(u.getAvatar());

      File fileToDelete =
          new File(SystemGlobals.getApplicationPath() + "/images/avatar/" + avatarFile.getName());

      if (fileToDelete.exists()) {
        fileToDelete.delete();
      }

      u.setAvatar(null);
    }

    if (request.getObjectParameter("avatar") != null) {
      try {
        UserCommon.handleAvatar(u);
      } catch (Exception e) {
        UserCommon.LOG.warn("Problems while uploading the avatar: " + e);
        errors.add(I18n.getMessage("User.avatarUploadError"));
      }
    } else if (SystemGlobals.getBoolValue(ConfigKeys.AVATAR_ALLOW_EXTERNAL_URL)) {
      String avatarUrl = request.getParameter("avatarUrl");

      if (!StringUtils.isEmpty(avatarUrl)) {
        if (avatarUrl.toLowerCase().startsWith("http://")) {

          try {
            Image image = ImageIO.read(new URL(avatarUrl));

            if (image != null) {
              if (image.getWidth(null) > SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_WIDTH)
                  || image.getHeight(null)
                      > SystemGlobals.getIntValue(ConfigKeys.AVATAR_MAX_HEIGHT)) {
                errors.add(I18n.getMessage("User.avatarTooBig"));
              } else {
                u.setAvatar(avatarUrl);
              }
            }
          } catch (Exception e) {
            errors.add(I18n.getMessage("User.avatarUploadError"));
          }
        } else {
          errors.add(I18n.getMessage("User.avatarUrlShouldHaveHttp"));
        }
      }
    }

    if (errors.size() == 0) {
      um.update(u);

      if (SessionFacade.getUserSession().getUserId() == userId) {
        SessionFacade.getUserSession().setLang(u.getLang());
      }
    }

    return errors;
  }