/**
   * Get the encoding for export XML
   *
   * @return the encoding for export XML
   */
  public String getExportXMLEncoding() {
    ReferenceItem param = findByKey(PARAMETER_EXPORT_XML_ENCODING);

    if (param == null) {
      return AppPropertiesService.getProperty(PROPERTY_DEFAULT_EXPORT_ENCODING);
    }

    return param.getName();
  }
  /**
   * Build the advanced parameters management
   *
   * @param user the admin user
   * @return The model for the advanced parameters
   */
  public Map<String, Object> getManageAdvancedParameters(AdminUser user) {
    Map<String, Object> model = new HashMap<String, Object>();
    Plugin plugin = PluginService.getPlugin(DatabasePlugin.PLUGIN_NAME);

    if (RBACService.isAuthorized(
        DatabaseResourceIdService.RESOURCE_TYPE,
        RBAC.WILDCARD_RESOURCES_ID,
        DatabaseResourceIdService.PERMISSION_MANAGE,
        user)) {
      // Encryption Password
      String strAlgorithms = AppPropertiesService.getProperty(PROPERTY_ENCRYPTION_ALGORITHMS_LIST);

      if (StringUtils.isNotBlank(strAlgorithms)) {
        String[] listAlgorithms = strAlgorithms.split(COMMA);

        model.put(MARK_ENCRYPTION_ALGORITHMS_LIST, listAlgorithms);
        model.put(MARK_IS_PLUGIN_JCAPTCHA_ENABLE, isPluginJcaptchaEnable());

        if (isPluginJcaptchaEnable()) {
          model.put(
              MARK_ENABLE_JCAPTCHA,
              SecurityUtils.getBooleanSecurityParameter(
                  _userParamService, plugin, MARK_ENABLE_JCAPTCHA));
        }
      }

      model.put(
          PARAMETER_ACCOUNT_CREATION_VALIDATION_EMAIL,
          SecurityUtils.getBooleanSecurityParameter(
              _userParamService, plugin, PARAMETER_ACCOUNT_CREATION_VALIDATION_EMAIL));

      model.put(
          PARAMETER_AUTO_LOGIN_AFTER_VALIDATION_EMAIL,
          SecurityUtils.getBooleanSecurityParameter(
              _userParamService, plugin, PARAMETER_AUTO_LOGIN_AFTER_VALIDATION_EMAIL));

      model.put(
          MARK_BANNED_DOMAIN_NAMES,
          SecurityUtils.getLargeSecurityParameter(
              _userParamService, plugin, MARK_BANNED_DOMAIN_NAMES));

      model = SecurityUtils.checkSecurityParameters(_userParamService, model, plugin);
    }

    return model;
  }
public class ProfanityFilter implements IProfanityFilter {
  private static ProfanityFilter _singleton;

  // bean
  public static final String BEAN_PROFANITY_FILTER_SERVICE =
      "profanityfilter.profanityfilterService";
  public static final String CHARACTER_SPACE_BETWEEN_WORDS =
      AppPropertiesService.getProperty("character_space_between_words", " ");

  /** @return IEudonetWsService */
  public static IProfanityFilter getService() {
    if (_singleton == null) {
      _singleton = SpringContextService.getBean(BEAN_PROFANITY_FILTER_SERVICE);
    }

    return _singleton;
  }

  @Override
  public ProfanityResult checkString(String str) {
    ProfanityResult profResult = new ProfanityResult();
    String[] wordStr = null;
    Pattern p = Pattern.compile("\\W");
    Collection<Word> wordList = WordHome.getWordsList();

    if ((str != null) && StringUtils.isNotEmpty(str) && StringUtils.isNotBlank(str)) {
      wordStr = p.split(str);
    }

    boolean _isSwearWords = false;
    int number = 0;

    if (wordStr != null) {
      for (String word : wordStr) {
        if (containsReferenceTo(wordList, word)) {
          profResult.addWord(word);
          _isSwearWords = true;
          number++;
        }
      }
    }

    profResult.setIsSwearWords(_isSwearWords);
    profResult.setNumberSwearWords(number);

    return profResult;
  }

  @Override
  public ProfanityResult checkStringCounter(String str, String strResourceType) {
    Counter counter = CounterHome.findByResourceTypeKey(strResourceType);
    Pattern p = Pattern.compile("\\W");

    if (counter == null) {
      Counter newCounter = new Counter();
      newCounter.setCounter(0);
      newCounter.setResourceType(strResourceType);
      counter = CounterHome.create(newCounter);
    }

    ProfanityResult profResult = new ProfanityResult();
    String[] wordStr = null;
    Collection<Word> wordList = WordHome.getWordsList();

    if ((str != null) && StringUtils.isNotEmpty(str) && StringUtils.isNotBlank(str)) {
      wordStr = p.split(str);
    }

    boolean _isSwearWords = false;
    int number = 0;

    if (wordStr != null) {
      for (String word : wordStr) {
        if (containsReferenceTo(wordList, word)) {
          profResult.addWord(word);
          _isSwearWords = true;
          number++;
          counter.setCounter(counter.getCounter() + 1);
          CounterHome.update(counter);
          profResult.setCounterSwearWords(counter.getCounter());
        }
      }
    }

    profResult.setIsSwearWords(_isSwearWords);
    profResult.setNumberSwearWords(number);

    return profResult;
  }

  @Override
  public Counter getCounterSwearWords(String strResourceType) {
    return CounterHome.findByResourceTypeKey(strResourceType);
  }

  public static boolean containsReferenceTo(Collection<Word> collection, String element) {
    if (collection == null) {
      throw new NullPointerException("collection cannot be null");
    }

    for (Word x : collection) {
      if (removeAccent(x.getValue()).toUpperCase().equals(removeAccent(element).toUpperCase())
          || removeAccent(element)
              .toUpperCase()
              .contains(removeAccent(x.getValue()).toUpperCase())) {
        return true;
      }
    }

    return false;
  }

  public static String removeAccent(String source) {
    return Normalizer.normalize(source, Normalizer.Form.NFD).replaceAll("[\u0300-\u036F]", "");
  }
}
Пример #4
0
  /**
   * Returns a no reply email address defined in config.properties
   *
   * @return A no reply email
   */
  public static String getNoReplyEmail() {
    String strDefault = AppPropertiesService.getProperty(PROPERTY_MAIL_NOREPLY_EMAIL);

    return DatastoreService.getDataValue(KEY_NO_REPLY_EMAIL, strDefault);
  }