public function updateUserContext(UserContext $context) { $user = $this->repository->getCurrentUser(); /** @var \eZ\Publish\API\Repository\Values\User\RoleAssignment[] $roleAssignments */ $roleAssignments = $this->repository->sudo(function (Repository $repository) use($user) { return $repository->getRoleService()->getRoleAssignmentsForUser($user, true); }); $roleIds = array(); $limitationValues = array(); /** @var UserRoleAssignment $roleAssignment */ foreach ($roleAssignments as $roleAssignment) { $roleId = $roleAssignment->getRole()->id; $roleIds[] = $roleId; $limitation = $roleAssignment->getRoleLimitation(); // If a limitation is present, store the limitation values by roleId if ($limitation !== null) { $limitationValuesKey = sprintf('%s-%s', $roleId, $limitation->getIdentifier()); $limitationValues[$limitationValuesKey] = array(); foreach ($limitation->limitationValues as $value) { $limitationValues[$limitationValuesKey][] = $value; } } } $context->addParameter('roleIdList', $roleIds); $context->addParameter('roleLimitationList', $limitationValues); }
/** * {@inheritDoc} * * @throws InvalidConfigurationException when called without a security context being set. */ public function updateUserContext(UserContext $context) { if (null === $this->context) { throw new InvalidConfigurationException('The context hash URL must be under a firewall.'); } if (null === ($token = $this->context->getToken())) { return; } $roles = array_map(function (RoleInterface $role) { return $role->getRole(); }, $token->getRoles()); // Order is not important for roles and should not change hash. sort($roles); $context->addParameter('roles', $roles); }
public function testSetParameters() { $userContext = new UserContext(); $userContext->addParameter('authenticated', true); $userContext->setParameters(array( 'roles' => array('ROLE_USER'), 'foo' => 'bar' )); $this->assertFalse($userContext->hasParameter('authenticated')); $this->assertTrue($userContext->hasParameter('foo')); $this->assertTrue($userContext->hasParameter('roles')); $parameters = array(); foreach ($userContext as $name => $value) { $parameters[$name] = $value; } $this->assertEquals( array('roles' => array('ROLE_USER'), 'foo' => 'bar'), $parameters ); }
public function updateUserContext(UserContext $context) { $context->addParameter('ezpublish_identity', $this->generate()); }
public function updateUserContext(UserContext $context) { $context->addParameter('foo', 'bar'); }