/** * Iterates over legacy SSO handlers, and pre-authenticates a user if a handler returns one. * * @param Request $request A Request instance * * @return array An array composed of the user and the credentials */ protected function getPreAuthenticatedData(Request $request) { $kernelClosure = $this->legacyKernelClosure; /** @var \ezpKernelHandler $legacyKernel */ $legacyKernel = $kernelClosure(); $logger = $this->logger; $legacyUser = $legacyKernel->runCallback(function () use($logger) { foreach (eZINI::instance()->variable('UserSettings', 'SingleSignOnHandlerArray') as $ssoHandlerName) { $className = 'eZ' . $ssoHandlerName . 'SSOHandler'; if (!class_exists($className)) { if ($logger) { $logger->error("Undefined legacy SSOHandler class: {$className}"); } continue; } $ssoHandler = new $className(); $ssoUser = $ssoHandler->handleSSOLogin(); if (!$ssoUser instanceof eZUser) { continue; } $logger->info("Matched user using eZ legacy SSO Handler: {$className}"); return $ssoUser; } }, false, false); // No matched user with legacy. if (!$legacyUser instanceof eZUser) { return array('', ''); } $user = new User($this->userService->loadUser($legacyUser->attribute('contentobject_id')), array('ROLE_USER')); return array($user, $user->getPassword()); }
/** * Assigns the user to a user group * * @param $userId * * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList */ public function assignUserToUserGroup($userId) { $user = $this->userService->loadUser($userId); try { $userGroupLocation = $this->locationService->loadLocation($this->extractLocationIdFromPath($this->request->query->get('group'))); } catch (APINotFoundException $e) { throw new Exceptions\ForbiddenException($e->getMessage()); } try { $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId); } catch (APINotFoundException $e) { throw new Exceptions\ForbiddenException($e->getMessage()); } try { $this->userService->assignUserToUserGroup($user, $userGroup); } catch (InvalidArgumentException $e) { throw new Exceptions\ForbiddenException($e->getMessage()); } $userGroups = $this->userService->loadUserGroupsOfUser($user); $restUserGroups = array(); foreach ($userGroups as $userGroup) { $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo(); $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId); $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId); $restUserGroups[] = new Values\RestUserGroup($userGroup, $contentType, $userGroupContentInfo, $userGroupLocation, $this->contentService->loadRelations($userGroup->getVersionInfo())); } return new Values\UserGroupRefList($restUserGroups, $this->router->generate('ezpublish_rest_loadUserGroupsOfUser', array('userId' => $userId)), $userId); }
public function updateContentTypeAction(Request $request, $contentTypeId, $languageCode = null) { $languageCode = $languageCode ?: $this->prioritizedLanguages[0]; // First try to load the draft. // If it doesn't exist, create it. try { $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId); } catch (NotFoundException $e) { $contentTypeDraft = $this->contentTypeService->createContentTypeDraft($this->contentTypeService->loadContentType($contentTypeId)); } $contentTypeData = (new ContentTypeDraftMapper())->mapToFormData($contentTypeDraft); $form = $this->createForm('ezrepoforms_contenttype_update', $contentTypeData, ['languageCode' => $languageCode]); $actionUrl = $this->generateUrl('admin_contenttypeUpdate', ['contentTypeId' => $contentTypeId, 'languageCode' => $languageCode]); // Synchronize form and data. $form->handleRequest($request); $hasErrors = false; if ($form->isValid()) { $this->contentTypeActionDispatcher->dispatchFormAction($form, $contentTypeData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null, ['languageCode' => $languageCode]); if ($response = $this->contentTypeActionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } elseif ($form->isSubmitted()) { $hasErrors = true; } return $this->render('eZPlatformUIBundle:ContentType:update_content_type.html.twig', ['form' => $form->createView(), 'action_url' => $actionUrl, 'contentTypeName' => $contentTypeDraft->getName($languageCode), 'contentTypeDraft' => $contentTypeDraft, 'modifier' => $this->userService->loadUser($contentTypeDraft->modifierId), 'languageCode' => $languageCode, 'hasErrors' => $hasErrors]); }
/** * Returns a role assignment to the given user * * @param $userId * @param $roleId * * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException * @return \eZ\Publish\Core\REST\Server\Values\RestUserRoleAssignment */ public function loadRoleAssignmentForUser($userId, $roleId) { $user = $this->userService->loadUser($userId); $roleAssignments = $this->roleService->getRoleAssignmentsForUser($user); foreach ($roleAssignments as $roleAssignment) { if ($roleAssignment->getRole()->id == $roleId) { return new Values\RestUserRoleAssignment($roleAssignment, $userId); } } throw new Exceptions\NotFoundException("Role assignment not found: '{$this->request->getPathInfo()}'."); }
/** * Loads a user * * @param mixed $userId * * @return \eZ\Publish\API\Repository\Values\User\User * * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given id was not found */ public function loadUser($userId) { return $this->service->loadUser($userId); }
/** * @Given /^a User with the same id exists$/ */ public function aUserWithTheSameIdExists() { Assertion::assertInstanceOf('eZ\\Publish\\API\\Repository\\Values\\User\\User', $this->userService->loadUser($this->currentContent->id)); }
/** * Assign a role to users and groups in the assignment array. * * <pre> * $assignments = array( * array( * 'type' => 'user', * 'ids' => array(user ids), * 'limitation' => array(limitations) * ) * ) * </pre> * * @param \eZ\Publish\API\Repository\Values\User\Role $role * @param \eZ\Publish\API\Repository\RoleService $roleService * @param \eZ\Publish\API\Repository\UserService $userService * @param array $assignments */ private function assignRole(Role $role, RoleService $roleService, UserService $userService, array $assignments) { foreach ($assignments as $assign) { switch ($assign['type']) { case 'user': foreach ($assign['ids'] as $userId) { $userId = $this->referenceResolver->resolveReference($userId); $user = $userService->loadUser($userId); if (!isset($assign['limitations'])) { $roleService->assignRoleToUser($role, $user); } else { foreach ($assign['limitations'] as $limitation) { $limitationObject = $this->createLimitation($roleService, $limitation); $roleService->assignRoleToUser($role, $user, $limitationObject); } } } break; case 'group': foreach ($assign['ids'] as $groupId) { $groupId = $this->referenceResolver->resolveReference($groupId); $group = $userService->loadUserGroup($groupId); if (!isset($assign['limitations'])) { // q: why are we swallowing exceptions here ? //try { $roleService->assignRoleToUserGroup($role, $group); //} catch (InvalidArgumentException $e) {} } else { foreach ($assign['limitations'] as $limitation) { $limitationObject = $this->createLimitation($roleService, $limitation); // q: why are we swallowing exceptions here ? //try { $roleService->assignRoleToUserGroup($role, $group, $limitationObject); //} catch (InvalidArgumentException $e) {} } } } break; } } }