Check if the user is allowed to reach the step.

@param  ModelInterface        $model
@param  Step                  $step
@throws AccessDeniedException
351723
protected function checkCredentials(ModelInterface $model, Step $step)
    {
        $roles = $step->getRoles();

        if (!empty($roles) && !$this->authorizationChecker->isGranted($roles, $model->getWorkflowObject())) {
            throw new AccessDeniedException($step->getName());
        }
    }
1004376
public function batchActionPublish(ProxyQueryInterface $selectedModelQuery)
    {
        if ($this->admin->isGranted('PUBLISH') === false) {
            throw new AccessDeniedException();
        }

        $modelManager = $this->admin->getModelManager();

        $selectedModels = $selectedModelQuery->execute();

        // do the merge work here

        try {
            foreach ($selectedModels as $selectedModel) {
                /* @var PageInterface $selectedModel */
                $selectedModel->setStatus(PageInterface::STATUS_PUBLISHED);
                $modelManager->update($selectedModel);
                $this->makeSnapshot($selectedModel);
            }
        } catch (\Exception $e) {
            $this->get('session')->getFlashBag()->add('sonata_flash_error', 'flash_batch_publish_error');

            return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
        }

        $this->get('session')->getFlashBag()->add('sonata_flash_success', 'flash_batch_publish_success');

        return new RedirectResponse($this->admin->generateUrl('list', $this->admin->getFilterParameters()));
    }
383584
protected function checkModels($related, $model)
    {
        if (!class_exists($related)) {
            $this->ModelNotFinded($related);
        }
        if (!class_exists(get_class($model))) {
            $this->ModelNotFinded(get_class($model));
        }
    }
164187
public function newModelStateSuccess(ModelInterface $model, $processName, $stepName, $previous = null)
    {
        $modelState = $this->createModelState($model, $processName, $stepName, $previous);
        $modelState->setSuccessful(true);

        $this->om->persist($modelState);
        $this->om->flush($modelState);

        return $modelState;
    }
597560
private function assertHasPaperAccess(Paper $paper, User $user = null)
    {
        if (!$this->attemptManager->canUpdate($paper, $user)) {
            throw new AccessDeniedException();
        }
    }
448233
public static function checkComponentAccess(ModuleInterface $module, string $component, Tree $tree, UserInterface $user): void
    {
        if ($module->accessLevel($tree, $component) < self::accessLevel($tree, $user)) {
            throw new AccessDeniedHttpException('');
        }
    }
80795
@Then("the step $activityId is reached")
  @When("the step $activityId is reached")
  public void stepIsReached(final String activityId) {
    assertThat(support.getProcessInstance()).isWaitingAt(activityId);
    LOG.debug("Step {} reached.", activityId);
  }
1005736
private function performStep($sessionId, Step $step, Context $context, $currentIteration)
    {
        switch (true) {
            case $step instanceof Merge:
                $newContext = $this->actionMapping->merge($sessionId, $context, $step);
                $context = $this->converse($sessionId, null, $newContext, --$currentIteration);
                break;
            case $step instanceof Message:
                $this->actionMapping->say($sessionId, $context, $step);
                $context = $this->converse($sessionId, null, $context, --$currentIteration);
                break;
            case $step instanceof Action:
                $newContext = $this->actionMapping->action($sessionId, $context, $step);
                $context = $this->converse($sessionId, null, $newContext, --$currentIteration);
                break;
            case $step instanceof Stop:
                $this->actionMapping->stop($sessionId, $context, $step);
                break;
        }

        return $context;
    }
186593
public function isAllowed(Model $Model, $action = 'create') {
		if (false === $Model->requireAuth) {
			return true;
		}

		extract($this->settings[$Model->alias]);

		if (!in_array($action, $perms)) {
			throw new FatalErrorException(__d('common', "No '%s' action defined for controlling '%s' authorization", $action, $Model->name));
		}

		$currentGroup = $this->getCurrentUser($Model, $groups['auth']);
		$currentUser = $this->getCurrentUser($Model, $owner['auth']);

		$current = $Model->getID();

		if ($this->isCustomRole($Model, $action)) {
			return true;
		}

		if (!$Model->exists()) {
			if (
				in_array($action, array('create', 'update'))
				&& empty($Model->data[$Model->alias][$owner['path']])
			) {
				$Model->data[$Model->alias][$owner['path']] = $currentUser;
			}
			return true;
		}

		if ($owner[$action] && $this->isOwner($Model)) {
			return true;
		}

		$find = false;
		$unload = false;

		if (
			empty($Model->activeRecord[$Model->alias][$Model->primaryKey])
			|| $current != $Model->activeRecord[$Model->alias][$Model->primaryKey]
		) {
			$Model->activeRecord = null;
		}

		if (empty($Model->activeRecord)) {
			$find = true;
		} else {
			foreach (array('groups', 'collaborators') as $key) {
				if (false !== ${$key}['allow'] && ${$key}[$action] && !Hash::check($Model->activeRecord, ${$key}['path'])) {
					$find = true;
					break;
				}
			}
		}

		if ($find && !$Model->Behaviors->loaded('Containable')) {
			$Model->Behaviors->load('Containable');
			$unload = true;
		}

		if ($find) {
			$contain = array();
			foreach (array('groups', 'collaborators') as $key) {
				if (false !== ${$key}['allow'] && ${$key}[$action]) {
					$contain[] = str_replace('{n}.', '', ${$key}['path']);
				}
			}

			$Model->requireAuth = false;
			$Model->activeRecord = Hash::merge((array) $Model->activeRecord, $Model->find('first', array(
				'conditions' => array($Model->alias . '.' . $Model->primaryKey => $current),
				'fields' => $Model->alias . '.' . $owner['path'],
				'contain' => $contain,
			)));
			$Model->requireAuth = true;
		}

		if ($unload) {
			$Model->Behaviors->unload('Containable');
		}

		foreach (array('groups', 'collaborators') as $key) {
			if (false !== ${$key}['allow'] && $extract = Hash::extract($Model->activeRecord, ${$key}['path'])) {
				${$key}['allow'] = array_merge(${$key}['allow'], $extract);
			}
		}

		return (
			(!empty($collaborators[$action]) && in_array($currentUser, (array) $collaborators['allow']))
			|| (!empty($groups[$action]) && array_intersect((array) $groups['allow'], (array) $currentGroup))
		);
	}
522948
@Override
    public void process(Step step) {
        Status status = throwable instanceof AssertionError ? Status.FAILED : Status.BROKEN;
        step.setStatus(status);
    }
1053012
private function deserializeParameters(Step $step, array $parameters)
    {
        $this->sipe('maxAttempts', 'setMaxAttempts', $parameters, $step);
        $this->sipe('duration', 'setDuration', $parameters, $step);
    }
667120
protected function setDataFromModel(ModelInterface $model): void
    {
        $this->container->set('model', $model);
        
        foreach (get_class_methods($model) as $method) {
            if (0 !== strpos($method, 'get')) {
                continue;
            }
            
            $this->data[strtolower(substr($method, 3))] = $model->$method();
        }
    }
1221983
public function addToRemoveModel(ModelInterface $model): RelatedModelManipulationStack
    {
        $this->toRemoveModels[$model->getId()] = $model;

        return $this;
    }
1271894
public function execute($command, callable $next)
    {
        if ($this->authorizationChecker->isGranted('handle', $command)) {
            return $next($command);
        }

        throw new AccessDeniedException(
            sprintf('The current user is not allowed to handle command of type \'%s\'', get_class($command))
        );
    }
428202
public function addStep(Step $step)
    {
        if (!$this->steps->contains($step)) {
            $this->steps->add($step);
        }

        return $this;
    }
1282818
public function canReachStep($stepName)
    {
        if (!array_key_exists($stepName, $this->canReachStep)) {

            $this->canReachStep[$stepName] = false;
            $this->validationErrors[$stepName] = array();

            if ($stepName != $this->getCurrentStepName()) {
                $stepToReach = $this->getStep($stepName);
                $currentStep = $this->getCurrentStep();

                if ($currentStep->hasPossibleNextStep($stepToReach->getName())) {

                    $preValidationResult = $this->preValidation($stepToReach->getName());

                    if ($preValidationResult) {
                        if (!$stepToReach->hasValidations()) {
                            $this->canReachStep[$stepToReach->getName()] = true;
                        } else {
                            foreach ($stepToReach->getValidations() as $validation) {
                                $validation = $this->getValidation($validation);

                                try {
                                    $validation->validate($this->getModel());
                                    $this->canReachStep[$stepToReach->getName()] = true;
                                } catch (ValidationException $e) {
                                    $this->validationErrors[$stepToReach->getName()][] = $e->getMessage();
                                    $this->canReachStep[$stepToReach->getName()] = false;
                                }
                            }
                        }
                    }
                }
            }
        }

        return $this->canReachStep[$stepName];
    }
802229
protected function updateBlameables(Model $model)
    {
        $user = $this->getActiveUser();

        if (is_null($user)) {
            return; // Todo: might be wise to implement loggin here
        }

        // Set updated-by if it has not been touched on this model
        if ($this->isBlameable($model, 'updated') && !$model->isDirty($this->getColumn($model, 'updated'))) {
            $this->setUpdatedBy($model, $user);
        }

        // Determine if we need to touch the created stamp
        if ($model->exists) {
            return;
        }

        // Set created-by if the model does not exist
        if ($this->isBlameable($model, 'created') && !$model->isDirty($this->getColumn($model, 'created'))) {
            $this->setCreatedBy($model, $user);
        }
    }