@Override
  public void registerJob(final Report report, final Date startAt)
      throws SchedulerException, ParseException {
    ReportJob job = createSpringBean(ReportJob.class);
    job.setReportKey(report.getKey());

    Map<String, Object> jobMap = new HashMap<>();
    jobMap.put(JobInstanceLoader.DOMAIN, AuthContextUtils.getDomain());

    registerJob(JobNamer.getJobName(report), job, report.getCronExpression(), startAt, jobMap);
  }
Esempio n. 2
0
  @Override
  protected void securityChecks(final User user) {
    // Allows anonymous (during self-registration) and self (during self-update) to read own user,
    // otherwise goes through security checks to see if required entitlements are owned
    if (!AuthContextUtils.getUsername().equals(anonymousUser)
        && !AuthContextUtils.getUsername().equals(user.getUsername())) {

      Set<String> authRealms =
          AuthContextUtils.getAuthorizations().get(StandardEntitlement.USER_READ);
      boolean authorized =
          IterableUtils.matchesAny(
              authRealms,
              new Predicate<String>() {

                @Override
                public boolean evaluate(final String realm) {
                  return user.getRealm().getFullPath().startsWith(realm);
                }
              });
      if (authRealms == null || authRealms.isEmpty() || !authorized) {
        throw new DelegatedAdministrationException(AnyTypeKind.USER, user.getKey());
      }
    }
  }
  @Override
  public Map<String, Object> registerJob(
      final SchedTask task, final Date startAt, final long interruptMaxRetries)
      throws SchedulerException, ParseException {

    TaskJob job = createSpringBean(TaskJob.class);
    job.setTaskKey(task.getKey());

    String jobDelegateClassName =
        task instanceof SyncTask
            ? SyncJobDelegate.class.getName()
            : task instanceof PushTask
                ? PushJobDelegate.class.getName()
                : task.getJobDelegateClassName();

    Map<String, Object> jobMap = new HashMap<>();
    jobMap.put(JobInstanceLoader.DOMAIN, AuthContextUtils.getDomain());
    jobMap.put(TaskJob.DELEGATE_CLASS_KEY, jobDelegateClassName);
    jobMap.put(TaskJob.INTERRUPT_MAX_RETRIES_KEY, interruptMaxRetries);

    registerJob(JobNamer.getJobName(task), job, task.getCronExpression(), startAt, jobMap);
    return jobMap;
  }
  @Transactional
  @Override
  public void load() {
    final Pair<String, Long> notificationConf =
        AuthContextUtils.execWithAuthContext(
            SyncopeConstants.MASTER_DOMAIN,
            new AuthContextUtils.Executable<Pair<String, Long>>() {

              @Override
              public Pair<String, Long> exec() {
                String notificationJobCronExpression = StringUtils.EMPTY;

                CPlainAttr notificationJobCronExp =
                    confDAO.find(
                        "notificationjob.cronExpression", NotificationJob.DEFAULT_CRON_EXP);
                if (!notificationJobCronExp.getValuesAsStrings().isEmpty()) {
                  notificationJobCronExpression =
                      notificationJobCronExp.getValuesAsStrings().get(0);
                }

                long interruptMaxRetries =
                    confDAO
                        .find("tasks.interruptMaxRetries", "1")
                        .getValues()
                        .get(0)
                        .getLongValue();

                return ImmutablePair.of(notificationJobCronExpression, interruptMaxRetries);
              }
            });

    for (String domain : domainsHolder.getDomains().keySet()) {
      AuthContextUtils.execWithAuthContext(
          domain,
          new AuthContextUtils.Executable<Void>() {

            @Override
            public Void exec() {
              // 1. jobs for SchedTasks
              Set<SchedTask> tasks = new HashSet<>(taskDAO.<SchedTask>findAll(TaskType.SCHEDULED));
              tasks.addAll(taskDAO.<SyncTask>findAll(TaskType.SYNCHRONIZATION));
              tasks.addAll(taskDAO.<PushTask>findAll(TaskType.PUSH));
              for (SchedTask task : tasks) {
                try {
                  registerJob(task, task.getStartAt(), notificationConf.getRight());
                } catch (Exception e) {
                  LOG.error("While loading job instance for task " + task.getKey(), e);
                }
              }

              // 2. ReportJobs
              for (Report report : reportDAO.findAll()) {
                try {
                  registerJob(report, null);
                } catch (Exception e) {
                  LOG.error("While loading job instance for report " + report.getName(), e);
                }
              }

              return null;
            }
          });
    }

    // 3. NotificationJob
    if (StringUtils.isBlank(notificationConf.getLeft())) {
      LOG.debug(
          "Empty value provided for NotificationJob's cron, not registering anything on Quartz");
    } else {
      LOG.debug(
          "NotificationJob's cron expression: {} - registering Quartz job and trigger",
          notificationConf.getLeft());

      try {
        registerNotificationJob(notificationConf.getLeft());
      } catch (Exception e) {
        LOG.error("While loading NotificationJob instance", e);
      }
    }
  }