*/ class TestTakerAuthorizationService extends ConfigurableService implements TestTakerAuthorizationInterface, DelegatedServiceHandler { use OntologyAwareTrait; /** * @deprecated moved to \oat\taoProctoring\model\delivery\DeliverySyncService::PROCTORED_BY_DEFAULT */ const PROCTORED_BY_DEFAULT = 'proctored_by_default'; /** * (non-PHPdoc) * @see \oat\taoDelivery\model\authorization\AuthorizationProvider::verifyStartAuthorization() * @param $deliveryId * @param User $user */ public function verifyStartAuthorization($deliveryId, User $user) { // always allow start } /** * (non-PHPdoc) * @see \oat\taoDelivery\model\authorization\AuthorizationProvider::verifyResumeAuthorization() * @param DeliveryExecutionInterface $deliveryExecution * @param User $user * @throws UnAuthorizedException */ public function verifyResumeAuthorization(DeliveryExecutionInterface $deliveryExecution, User $user) { $state = $deliveryExecution->getState()->getUri(); if (in_array($state, [ ProctoredDeliveryExecution::STATE_FINISHED, ProctoredDeliveryExecution::STATE_CANCELED, ProctoredDeliveryExecution::STATE_TERMINATED]) ) { throw new UnAuthorizedException( _url('index', 'DeliveryServer', 'taoProctoring'), 'Terminated/Finished delivery execution "'.$deliveryExecution->getIdentifier().'" cannot be resumed' ); } $deliveryUri = $deliveryExecution->getDelivery()->getUri(); if ( $this->isProctored($deliveryUri, $user) && $state !== ProctoredDeliveryExecution::STATE_AUTHORIZED && !$this->isActiveUnSecureDelivery($deliveryExecution, $state) ) { $this->throwUnAuthorizedException($deliveryExecution); } } /** * Check if delivery id proctored * * @param string $deliveryId * @param User $user * @return bool * @internal param core_kernel_classes_Resource $delivery * @throws \core_kernel_persistence_Exception */ public function isProctored($deliveryId, User $user) { $delivery = $this->getResource($deliveryId); $proctored = $delivery->getOnePropertyValue($this->getProperty(ProctorService::ACCESSIBLE_PROCTOR)); if ($proctored instanceof \core_kernel_classes_Resource) { $isProctored = $proctored->getUri() == ProctorService::ACCESSIBLE_PROCTOR_ENABLED; } else { $deliverySyncService = $this->getServiceLocator()->get(DeliverySyncService::SERVICE_ID); $isProctored = $deliverySyncService->isProctoredByDefault(); } return $isProctored; } /** * @param DeliveryExecution $deliveryExecution * @param string $state * @return bool * @throws common_Exception */ public function isActiveUnSecureDelivery(DeliveryExecution $deliveryExecution, $state) { return $state === DeliveryExecutionInterface::STATE_ACTIVE && !$this->isSecure($deliveryExecution); } /** * @param DeliveryExecution $deliveryExecution * @return bool * @throws common_Exception */ public function isSecure(DeliveryExecution $deliveryExecution) { $deliveryContainerService = $this->getServiceLocator()->get(DeliveryContainerService::SERVICE_ID); $enabledPlugins = $deliveryContainerService->getPlugins($deliveryExecution); $secure = false; foreach ($enabledPlugins as $plugin) { if ($plugin instanceof TestPlugin && $plugin->getId() === 'blurPause') { $secure = true; break; } } return $secure; } /** * Throw the appropriate Exception * * @param DeliveryExecution $deliveryExecution * @throws UnAuthorizedException */ protected function throwUnAuthorizedException(DeliveryExecution $deliveryExecution) { $errorPage = _url('awaitingAuthorization', 'DeliveryServer', 'taoProctoring', array('deliveryExecution' => $deliveryExecution->getIdentifier())); throw new UnAuthorizedException($errorPage, 'Proctor authorization missing'); } public function isSuitable(User $user, $deliveryId = null) { return true; } }