boolean checkInvalidPermissions(final JiraServiceContext context) {
   if (!permissionManager.hasPermission(Permissions.SYSTEM_ADMIN, context.getLoggedInUser())) {
     final I18nHelper i18n = beanFactory.getInstance(context.getLoggedInUser());
     context
         .getErrorCollection()
         .addErrorMessage(i18n.getText("whitelist.service.permission.error"));
     return true;
   }
   return false;
 }
  @Override
  public WhitelistUpdateValidationResult validateUpdateRules(
      final JiraServiceContext context, final List<String> rules, final boolean disabled) {
    notNull("context", context);
    notNull("rules", rules);

    if (checkInvalidPermissions(context)) {
      return new WhitelistUpdateValidationResult(context.getErrorCollection());
    }

    for (String rule : rules) {
      if (rule.startsWith(REGEX_PREFIX)) {
        try {
          Pattern.compile(rule.substring(REGEX_PREFIX.length()));
        } catch (PatternSyntaxException e) {
          final I18nHelper i18n = beanFactory.getInstance(context.getLoggedInUser());
          context
              .getErrorCollection()
              .addErrorMessage(i18n.getText("whitelist.admin.errors.bad.pattern", e.getMessage()));
        }
      }
    }

    return new WhitelistUpdateValidationResult(context.getErrorCollection(), rules, disabled);
  }
 /**
  * @see UserPickerSearchService#canShowEmailAddresses(com.atlassian.jira.bc.JiraServiceContext)
  */
 @Override
 public boolean canShowEmailAddresses(final JiraServiceContext jiraServiceContext) {
   if (canPerformAjaxSearch(jiraServiceContext)) {
     final String emailVisibility =
         applicationProperties.getDefaultBackedString(APKeys.JIRA_OPTION_EMAIL_VISIBLE);
     if (VISIBILITY_PUBLIC.equals(emailVisibility)
         || (VISIBILITY_MASKED.equals(emailVisibility))
         || (VISIBILITY_USER.equals(emailVisibility)
             && (jiraServiceContext.getLoggedInUser() != null))) {
       return true;
     }
   }
   return false;
 }
 @Override
 public boolean canPerformAjaxSearch(final JiraServiceContext jiraServiceContext) {
   User loggedInUser = (jiraServiceContext != null) ? jiraServiceContext.getLoggedInUser() : null;
   return canPerformAjaxSearch(loggedInUser);
 }