本文整理汇总了PHP中Symfony\Component\Security\Acl\Domain\UserSecurityIdentity::fromToken方法的典型用法代码示例。如果您正苦于以下问题:PHP UserSecurityIdentity::fromToken方法的具体用法?PHP UserSecurityIdentity::fromToken怎么用?PHP UserSecurityIdentity::fromToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Acl\Domain\UserSecurityIdentity
的用法示例。
在下文中一共展示了UserSecurityIdentity::fromToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSecurityIdentities
/**
* {@inheritDoc}
*/
public function getSecurityIdentities(TokenInterface $token)
{
$sids = array();
// add user security identity
if (!$token instanceof AnonymousToken) {
try {
$sids[] = UserSecurityIdentity::fromToken($token);
} catch (\InvalidArgumentException $invalid) {
// ignore, user has no user security identity
}
}
// add all reachable roles
foreach ($this->roleHierarchy->getReachableRoles($token->getRoles()) as $role) {
$sids[] = new RoleSecurityIdentity($role);
}
// add built-in special roles
if ($this->authenticationTrustResolver->isFullFledged($token)) {
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_FULLY);
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
} else {
if ($this->authenticationTrustResolver->isRememberMe($token)) {
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
} else {
if ($this->authenticationTrustResolver->isAnonymous($token)) {
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
}
}
}
return $sids;
}
示例2: getCompareData
public function getCompareData()
{
$account = $this->getMockBuilder('Symfony\\Component\\Security\\Core\\User\\UserInterface')->setMockClassName('USI_AccountImpl')->getMock();
$account->expects($this->any())->method('getUsername')->will($this->returnValue('foo'));
$token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface');
$token->expects($this->any())->method('getUser')->will($this->returnValue($account));
return array(array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('foo', 'Foo'), true), array(new UserSecurityIdentity('foo', 'Bar'), new UserSecurityIdentity('foo', 'Foo'), false), array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('bar', 'Foo'), false), array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromAccount($account), false), array(new UserSecurityIdentity('bla', 'Foo'), new UserSecurityIdentity('blub', 'Foo'), false), array(new UserSecurityIdentity('foo', 'Foo'), new RoleSecurityIdentity('foo'), false), array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromToken($token), false), array(new UserSecurityIdentity('foo', 'USI_AccountImpl'), UserSecurityIdentity::fromToken($token), true));
}
示例3: __construct
public function __construct($uid = null, $token = null)
{
$this->_uid = is_null($uid) ? md5(uniqid('', true)) : $uid;
$this->_created_at = new \DateTime();
if ($token instanceof TokenInterface) {
$this->_owner = UserSecurityIdentity::fromToken($token);
}
}
示例4: getSid
/**
* Constructs SID (an object implements SecurityIdentityInterface) based on the given identity
*
* @param string|RoleInterface|UserInterface|TokenInterface $identity
* @throws \InvalidArgumentException
* @return SID
*/
public function getSid($identity)
{
if (is_string($identity)) {
return new RoleSecurityIdentity($identity);
} elseif ($identity instanceof RoleInterface) {
return new RoleSecurityIdentity($identity->getRole());
} elseif ($identity instanceof UserInterface) {
return UserSecurityIdentity::fromAccount($identity);
} elseif ($identity instanceof TokenInterface) {
return UserSecurityIdentity::fromToken($identity);
}
throw new \InvalidArgumentException(sprintf('$identity must be a string or implement one of RoleInterface, UserInterface, TokenInterface' . ' (%s given)', is_object($identity) ? get_class($identity) : gettype($identity)));
}
示例5: getSecurityIdentities
/**
* {@inheritdoc}
*/
public function getSecurityIdentities(Token\TokenInterface $token)
{
$sids = array();
// add user security identity
if (!$token instanceof Token\AnonymousToken) {
try {
$sids[] = UserSecurityIdentity::fromToken($token);
} catch (\InvalidArgumentException $invalid) {
// ignore, user has no user security identity
}
}
// add all reachable roles
foreach ($this->roleHierarchy->getReachableRoles($token->getRoles()) as $role) {
$sids[] = new RoleSecurityIdentity($role);
}
// add journal roles
$user = $token->getUser();
try {
$selectedJournal = $this->journalService->getSelectedJournal();
} catch (\Exception $e) {
$selectedJournal = false;
}
if ($user instanceof User && $selectedJournal instanceof Journal) {
foreach ($user->getJournalRoles($selectedJournal) as $journalRoles) {
$sids[] = new JournalRoleSecurityIdentity($journalRoles[0], $journalRoles[1]);
}
}
// add built-in special roles
if ($this->authenticationTrustResolver->isFullFledged($token)) {
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_FULLY);
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
} elseif ($this->authenticationTrustResolver->isRememberMe($token)) {
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED);
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
} elseif ($this->authenticationTrustResolver->isAnonymous($token)) {
$sids[] = new RoleSecurityIdentity(AuthenticatedVoter::IS_AUTHENTICATED_ANONYMOUSLY);
}
return $sids;
}
示例6: newPostAction
/**
* @PreAuthorize("isAuthenticated()")
*/
public function newPostAction()
{
if (!($title = $this->request->request->get('title'))) {
throw new HttpException(400);
}
$this->em->getConnection()->beginTransaction();
try {
$post = new Post($title);
$this->em->persist($post);
$this->em->flush();
$oid = ObjectIdentity::fromDomainObject($post);
$acl = $this->getAclProvider()->createAcl($oid);
$sid = UserSecurityIdentity::fromToken($this->tokenStorage->getToken());
$acl->insertObjectAce($sid, MaskBuilder::MASK_OWNER);
$this->getAclProvider()->updateAcl($acl);
$this->em->getConnection()->commit();
return new Response('', 201, array('Location' => $this->router->generate('post_controller_edit', array('id' => $post->getId()))));
} catch (\Exception $ex) {
$this->em->getConnection()->rollBack();
$this->em->close();
throw $ex;
}
}
示例7: getAllDrafts
/**
* Returns all current drafts for authenticated user.
*
* @param TokenInterface $token
*
* @return array
*/
public function getAllDrafts(TokenInterface $token)
{
$owner = UserSecurityIdentity::fromToken($token);
$states = [Revision::STATE_ADDED, Revision::STATE_MODIFIED];
$result = [];
try {
$result = $this->findBy(['_owner' => $owner, '_state' => $states]);
} catch (ConversionException $e) {
$result = [];
foreach ($this->getAllDraftsUids($owner, $states) as $data) {
try {
$result[] = $this->find($data['_uid']);
} catch (ConversionException $e) {
$this->_em->getConnection()->executeUpdate('DELETE FROM revision WHERE uid = :uid', ['uid' => $data['_uid']]);
}
}
} catch (MappingException $e) {
$result = [];
foreach ($this->getAllDraftsUids($owner, $states) as $data) {
$draft = $this->find($data['_uid']);
if (null !== $draft->getContent()) {
$result[] = $draft;
} else {
$this->_em->getConnection()->executeUpdate('DELETE FROM revision WHERE uid = :uid', ['uid' => $data['_uid']]);
}
}
}
return $result;
}
示例8: doCreateSecurityIdentity
/**
* Creates a new object instanceof SecurityIdentityInterface from input implementing one of UserInterface, TokenInterface or RoleInterface (or its string representation)
* @param mixed $identity
* @throws InvalidIdentityException
* @return SecurityIdentityInterface
*/
protected function doCreateSecurityIdentity($identity)
{
if (!$identity instanceof UserInterface && !$identity instanceof TokenInterface && !$identity instanceof RoleInterface && !is_string($identity)) {
throw new \InvalidArgumentException(sprintf('$identity must implement one of: UserInterface, TokenInterface, RoleInterface (%s given)', get_class($identity)));
}
$securityIdentity = null;
if ($identity instanceof UserInterface) {
$securityIdentity = UserSecurityIdentity::fromAccount($identity);
} else {
if ($identity instanceof TokenInterface) {
$securityIdentity = UserSecurityIdentity::fromToken($identity);
} else {
if ($identity instanceof RoleInterface || is_string($identity)) {
$securityIdentity = new RoleSecurityIdentity($identity);
}
}
}
if (!$securityIdentity instanceof SecurityIdentityInterface) {
throw new \InvalidArgumentException('Couldn\'t create a valid SecurityIdentity with the provided identity information');
}
return $securityIdentity;
}
示例9: getUserSecurityIdentity
/**
* {@inheritdoc}
*/
public function getUserSecurityIdentity(UserInterface $user = null)
{
return null === $user ? UserSecurityIdentity::fromToken($this->tokenStorage->getToken()) : UserSecurityIdentity::fromAccount($user);
}
示例10: getAllDrafts
/**
* Returns all current drafts for authenticated user.
*
* @param TokenInterface $token
*
* @return array
*/
public function getAllDrafts(TokenInterface $token)
{
$owner = UserSecurityIdentity::fromToken($token);
$states = [Revision::STATE_ADDED, Revision::STATE_MODIFIED];
$result = [];
try {
$result = $this->findBy(['_owner' => $owner, '_state' => $states]);
} catch (ConversionException $e) {
$qb = $this->createQueryBuilder('r');
$uids = $qb->select('r._uid')->where('r._owner = :owner')->setParameter('owner', $owner)->andWhere($qb->expr()->in('r._state', $states))->getQuery()->getResult();
$result = [];
foreach ($uids as $data) {
try {
$result[] = $this->find($data['_uid']);
} catch (ConversionException $e) {
$this->_em->getConnection()->executeUpdate('DELETE FROM revision WHERE uid = :uid', ['uid' => $data['_uid']]);
}
}
}
return $result;
}
示例11: getAllDrafts
/**
* Returns all current drafts for authenticated user.
*
* @param TokenInterface $token
*/
public function getAllDrafts(TokenInterface $token)
{
return $this->_em->getRepository('BackBee\\ClassContent\\Revision')->findBy(['_owner' => UserSecurityIdentity::fromToken($token), '_state' => [Revision::STATE_ADDED, Revision::STATE_MODIFIED]]);
}
示例12: setOptions
/**
* Sets options at the construction of a new revision.
*
* @param mixed $options
*
* @return \BackBee\ClassContent\AContent
* @return \BackBee\ClassContent\AbstractClassContent
*/
protected function setOptions($options = null)
{
if ($options instanceof TokenInterface) {
$this->_owner = UserSecurityIdentity::fromToken($options);
}
return $this;
}
示例13: getAllDrafts
/**
* Returns all current drafts for authenticated user.
*
* @param TokenInterface $token
*
* @return array
*/
public function getAllDrafts(TokenInterface $token)
{
return $this->findBy(['_owner' => UserSecurityIdentity::fromToken($token), '_state' => [Revision::STATE_ADDED, Revision::STATE_MODIFIED]]);
}
示例14: getSecurityEntity
/**
* getSecurityEntity
*
* @param mixed $identityObject
* @access private
* @return SecurityIdentityInterface
*/
private function getSecurityEntity($identityObject)
{
if ($identityObject instanceof UserInterface) {
return UserSecurityIdentity::fromAccount($identityObject);
} elseif ($identityObject instanceof TokenInterface) {
return UserSecurityIdentity::fromToken($identityObject);
} elseif ($identityObject instanceof RoleInterface) {
return new RoleSecurityIdentity($identityObject->getRole());
}
return null;
}
示例15: getSecurityIdentity
/**
*
* @param type $identity
* @return SecurityIdentityInterface
* @throws \InvalidArgumentException
*/
protected function getSecurityIdentity($identity)
{
$securityIdentity = null;
if ($identity instanceof UserInterface) {
$securityIdentity = UserSecurityIdentity::fromAccount($identity);
} else {
if ($identity instanceof TokenInterface) {
$securityIdentity = UserSecurityIdentity::fromToken($identity);
} else {
if ($identity instanceof RoleInterface || is_string($identity)) {
$securityIdentity = new RoleSecurityIdentity($identity);
}
}
}
if (!$securityIdentity instanceof SecurityIdentityInterface) {
throw new \Exception('Couldn\'t create a valid SecurityIdentity with the provided identity information');
}
return $securityIdentity;
}