Skip to content

Instantly share code, notes, and snippets.

@lukaspili
Created July 26, 2013 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaspili/6087159 to your computer and use it in GitHub Desktop.
Save lukaspili/6087159 to your computer and use it in GitHub Desktop.
Impersonating ROLE_PREVIOUS_ADMIN not working
<?php
namespace Siu\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
class Partner implements UserInterface, \Serializable
{
/**
* @ORM\Column(type="text")
* @Assert\NotBlank()
* @Assert\Email()
*/
protected $email;
/* UserInterface */
/**
* @inheritDoc
*/
public function getUsername()
{
return $this->email;
}
/**
* @inheritDoc
*/
public function getRoles()
{
return array('ROLE_PARTNER');
}
/**
* @inheritDoc
*/
public function eraseCredentials()
{
}
/* Serializable */
/**
* @see \Serializable::serialize()
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
));
}
/**
* @see \Serializable::unserialize()
*/
public function unserialize($serialized)
{
list (
$this->id,
$this->email,
) = unserialize($serialized);
}
/**
* Set email
*
* @param string $email
* @return Partner
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set salt
*
* @param string $salt
* @return Partner
*/
public function setSalt($salt)
{
$this->salt = $salt;
return $this;
}
/**
* Get salt
*
* @return string
*/
public function getSalt()
{
return $this->salt;
}
}
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Siu\AppBundle\Entity\Partner: sha512
Siu\PartnerBundle\Entity\User: sha512
role_hierarchy:
ROLE_ADMIN: [ROLE_ALLOWED_TO_SWITCH]
providers:
chain_provider:
chain:
providers: [admins, partners]
partners:
entity: { class: SiuAppBundle:Partner, property: email }
admins:
memory:
users:
jleadmin: { password: foobar, roles: ['ROLE_ADMIN'] }
firewalls:
secure:
pattern: ^/
anonymous: ~
provider: chain_provider
switch_user: { role: ROLE_ADMIN, parameter: _partner_user }
form_login:
login_path: login
check_path: login_check
logout: ~
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
<a href="{{ path('default_home', {_partner_user: '_exit'}) }}">Never showed</a>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment