You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Error: Call to a member function validateCredentials() on a non-object in /var/www/udaweblabs/vendor/besimple/sso-auth-bundle/BeSimple/SsoAuthBundle/Security/Core/Authentication/Provider/SsoAuthenticationProvider.php line 78
#71
Closed
famonsei opened this issue
May 23, 2014
· 2 comments
I'm trying to make a ternary relationship management Roles.
In my example I have 3 entities User, Role, and Lab.
I would like to have roles for a user based on lab in which is (we manage this by environment), I created a Profile entity with keys User and Lab. To this I added a relationship ManyToMany for Roles.
My problem comes when I redefined the method loadUserByUsername:
Once connected there is a difference in Roles between Token and Session.
What seems weird, if I switch on my own account I get well good Roles ...
So I implemented EquatableInterface to compare the Token and Session, it is the difference in Roles so it makes a refreshUser, and this is why I get this error in title.
Here is the code and thank you for your help
User.php
roles = array();
// }
//==========================================================================
// PROPERTIES
//==========================================================================
/_*
- @Orm\Column(type="integer")
- @Orm\Id
- @Orm\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
- @Orm\Column(type="string", length=255, unique=true)
*/
private $login;
/**
- @Orm\Column(type="string", length=45, unique=true)
*/
private $firstName;
/**
- @Orm\Column(type="string", length=45, unique=true)
*/
private $lastName;
private $roles;
//==========================================================================
// GETTERS / SETTERS
//==========================================================================
/**
- Get id
*
- @return integer
*/
public function getId()
{
return $this->id;
}
/**
- Get login
*
- @return string
*/
public function getLogin()
{
return $this->login;
}
/**
- Set login
*
- @param string $login
- @return User
*/
public function setLogin($login)
{
$this->login = $login;
return $this;
}
/**
- Get firstName
*
- @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
- Set firstName
*
- @param string $firstName
- @return User
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
- Get lastName
*
- @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
- Set lastName
*
- @param string $lastName
- @return User
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
- Add roles
*
- @param \Uda\CoreBundle\Entity\Role $roles
- @return User
*/
public function addRole(\Uda\CoreBundle\Entity\Role $roles)
{
$this->roles[] = $roles;
return $this;
}
/**
- Remove roles
*
- @param \Uda\CoreBundle\Entity\Role $roles
_/
public function removeRole(\Uda\CoreBundle\Entity\Role $roles)
{
$this->roles->removeElement($roles);
}
/_*
- Get roles
*
*/
public function getRoles()
{
return is_array($this->roles) ? $this->roles : array('ROLE_USER');
}
/**
- Set roles
*
- @param string $roles
*/
public function setRoles($roles)
{
$this->roles = array();
if (is_array($roles)) $this->roles = $roles;
return $this;
}
//==========================================================================
// IMPLEMENTS
//==========================================================================
public function getUsername()
{
// seul lien pour symfony pour récupérer l'identifiant utilisateur
return $this->login;
}
public function getSalt()
{
}
public function getPassword()
{
}
public function eraseCredentials(){
return true;
}
public function isAccountNonExpired() {
return true;
}
public function isAccountNonLocked() {
return true;
}
public function isCredentialsNonExpired() {
return true;
}
public function isEnabled() {
return true;
}
public function serialize() {return \serialize( array($this->id, $this->login) );
}
public function unserialize($serialized) {
list($this->id, $this->login) = \unserialize( $serialized );
}
public function isEqualTo(UserInterface $user) {
if ($user instanceof User) {
$isEqual = count($this->getRoles()) == count($user->getRoles());
if ($isEqual) {
foreach($this->getRoles() as $role) {
$isEqual = $isEqual && in_array($role, $user->getRoles());
}
}
return $isEqual;
}
```
return false;
```
}
//==========================================================================
// METHODS
//==========================================================================
}
UserRepository.php
getEntityManager()
->createQueryBuilder()
->select('p')
->from('UdaCoreBundle:Profile', 'p')
->innerJoin('p.user', 'u')
->innerJoin('p.lab', 'l')
->where('u.login = :login')
->andWhere('l.id = :lab_id')
->setParameter('login', $login)
->setParameter('lab_id', '1')
->getQuery();
try {
// The Query::getSingleResult() method throws an exception
// if there is no record matching the criteria.
$profile = $q->getSingleResult();
$user = $profile->getUser();
$roles = array();
foreach ( $profile->getRoles() as $role )
{
$roles[] = $role->getRole();
}
$user->setRoles($roles);
} catch (NoResultException $e) {
throw new UsernameNotFoundException(sprintf('Unable to find an active admin UdaCoreBundle:User object identified by "%s".', $login), null, 0, $e);
}
return $user;
}
public function refreshUser(UserInterface $user) {
return $this->loadUserByUsername($user->getUsername());
}
public function supportsClass($class) {
return true;
}
```
}
Role.php
profiles = new ArrayCollection();
}
//==========================================================================
// PROPERTIES
//==========================================================================
/**
- @var integer $id
*
- @Orm\Column(type="integer")
- @Orm\Id
- @Orm\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
- @var string $role
*
- @Orm\Column(name="role", type="string", length=20, unique=true)
*/
private $role;
/**
- @var string $label
*
- @Orm\Column(name="label", type="string", length=45)
*/
private $label;
/**
- Profiles
-
- @var ArrayCollection
-
- @Orm\ManyToMany(targetEntity="Profile", mappedBy="roles")
*/
private $profiles;
//==========================================================================
// GETTERS / SETTERS
//==========================================================================
/**
- Get id
*
- @return integer
*/
public function getId()
{
return $this->id;
}
/**
- Get role // IMPLEMENTS
*
- @return string
_/
public function getRole()
{
return $this->role;
}
/_*
- Set role
*
- @param string $role
- @return Role
*/
public function setRole($role)
{
$this->role = $role;
return $this;
}
/**
- Get label
*
- @return string
_/
public function getLabel()
{
return $this->label;
}
/_*
- Set label
*
- @param string $label
*/
public function setLabel($label)
{
$this->label = $label;
}
/**
- Get profiless
*
- @return \Doctrine\Common\Collections\Collection
*/
public function getProfiles()
{
return $this->profiles;
}
/**
- Add profiles
*
- @param \Uda\CoreBundle\Entity\Profile $profiles
- @return Role
*/
public function addProfile(\Uda\CoreBundle\Entity\Profile $profiles)
{
$this->profiles[] = $profiles;
return $this;
}
/**
- Remove profiles
*
- @param \Uda\CoreBundle\Entity\Profile $profiles
*/
public function removeProfile(\Uda\CoreBundle\Entity\Profile $profiles)
{
$this->profiles->removeElement($profiles);
}
//==========================================================================
// IMPLEMENTS
//==========================================================================
public function __toString()
{
return $this->getName();
}
//==========================================================================
// METHODS
//==========================================================================
}
Lab.php
id;
}
/**
- Get graalId
*
- @return integer
_/
public function getGraalId()
{
return $this->graalId;
}
/_*
- Set graalId
*
- @param string $graalId
*/
public function setGraalId($graalId)
{
$this->graalId = $graalId;
}
/**
- Get code
*
- @return string
_/
public function getCode()
{
return $this->code;
}
/_*
- Set code
*
- @param string $code
*/
public function setCode($code)
{
$this->code = $code;
}
/**
- Get label
*
- @return string
_/
public function getLabel()
{
return $this->label;
}
/_*
- Set label
*
- @param string $label
*/
public function setLabel($label)
{
$this->label = $label;
}
//==========================================================================
// METHODS
//==========================================================================
/**
- Add users
*
- @param \Uda\CoreBundle\Entity\User $users
- @return Role
*/
public function addUser(\Uda\CoreBundle\Entity\User $users)
{
$this->users[] = $users;
return $this;
}
/**
- Remove users
*
- @param \Uda\CoreBundle\Entity\User $users
*/
public function removeUser(\Uda\CoreBundle\Entity\User $users)
{
$this->users->removeElement($users);
}
/**
- Get users
*
- @return \Doctrine\Common\Collections\Collection
*/
public function getUsers()
{
return $this->users;
}
}
The text was updated successfully, but these errors were encountered:
Hi and excuse my english,
I'm trying to make a ternary relationship management Roles.
In my example I have 3 entities User, Role, and Lab.
I would like to have roles for a user based on lab in which is (we manage this by environment), I created a Profile entity with keys User and Lab. To this I added a relationship ManyToMany for Roles.
My problem comes when I redefined the method loadUserByUsername:
Once connected there is a difference in Roles between Token and Session.
What seems weird, if I switch on my own account I get well good Roles ...
So I implemented EquatableInterface to compare the Token and Session, it is the difference in Roles so it makes a refreshUser, and this is why I get this error in title.
Here is the code and thank you for your help
User.php
roles = array(); // } //========================================================================== // PROPERTIES //========================================================================== /_* - @Orm\Column(type="integer") - @Orm\Id - @Orm\GeneratedValue(strategy="AUTO") */ private $id; /** - @Orm\Column(type="string", length=255, unique=true) */ private $login; /** - @Orm\Column(type="string", length=45, unique=true) */ private $firstName; /** - @Orm\Column(type="string", length=45, unique=true) */ private $lastName; private $roles; //========================================================================== // GETTERS / SETTERS //========================================================================== /** - Get id * - @return integer */ public function getId() { return $this->id; } /** - Get login * - @return string */ public function getLogin() { return $this->login; } /** - Set login * - @param string $login - @return User */ public function setLogin($login) { $this->login = $login; return $this; } /** - Get firstName * - @return string */ public function getFirstName() { return $this->firstName; } /** - Set firstName * - @param string $firstName - @return User */ public function setFirstName($firstName) { $this->firstName = $firstName; return $this; } /** - Get lastName * - @return string */ public function getLastName() { return $this->lastName; } /** - Set lastName * - @param string $lastName - @return User */ public function setLastName($lastName) { $this->lastName = $lastName; return $this; } /** - Add roles * - @param \Uda\CoreBundle\Entity\Role $roles - @return User */ public function addRole(\Uda\CoreBundle\Entity\Role $roles) { $this->roles[] = $roles; return $this; } /** - Remove roles * - @param \Uda\CoreBundle\Entity\Role $roles _/ public function removeRole(\Uda\CoreBundle\Entity\Role $roles) { $this->roles->removeElement($roles); } /_* - Get roles * */ public function getRoles() { return is_array($this->roles) ? $this->roles : array('ROLE_USER'); } /** - Set roles * - @param string $roles */ public function setRoles($roles) { $this->roles = array(); if (is_array($roles)) $this->roles = $roles; return $this; } //========================================================================== // IMPLEMENTS //========================================================================== public function getUsername() { // seul lien pour symfony pour récupérer l'identifiant utilisateur return $this->login; } public function getSalt() { } public function getPassword() { } public function eraseCredentials(){ return true; } public function isAccountNonExpired() { return true; } public function isAccountNonLocked() { return true; } public function isCredentialsNonExpired() { return true; } public function isEnabled() { return true; } public function serialize() {return \serialize( array($this->id, $this->login) ); } public function unserialize($serialized) { list($this->id, $this->login) = \unserialize( $serialized ); } public function isEqualTo(UserInterface $user) { if ($user instanceof User) { $isEqual = count($this->getRoles()) == count($user->getRoles()); if ($isEqual) { foreach($this->getRoles() as $role) { $isEqual = $isEqual && in_array($role, $user->getRoles()); } } return $isEqual; } ``` return false; ``` } //========================================================================== // METHODS //========================================================================== } UserRepository.php getEntityManager() ->createQueryBuilder() ->select('p') ->from('UdaCoreBundle:Profile', 'p') ->innerJoin('p.user', 'u') ->innerJoin('p.lab', 'l') ->where('u.login = :login') ->andWhere('l.id = :lab_id') ->setParameter('login', $login) ->setParameter('lab_id', '1') ->getQuery(); try { // The Query::getSingleResult() method throws an exception // if there is no record matching the criteria. $profile = $q->getSingleResult(); $user = $profile->getUser(); $roles = array(); foreach ( $profile->getRoles() as $role ) { $roles[] = $role->getRole(); } $user->setRoles($roles); } catch (NoResultException $e) { throw new UsernameNotFoundException(sprintf('Unable to find an active admin UdaCoreBundle:User object identified by "%s".', $login), null, 0, $e); } return $user; } public function refreshUser(UserInterface $user) { return $this->loadUserByUsername($user->getUsername()); } public function supportsClass($class) { return true; } ``` } Role.php profiles = new ArrayCollection(); } //========================================================================== // PROPERTIES //========================================================================== /** - @var integer $id * - @Orm\Column(type="integer") - @Orm\Id - @Orm\GeneratedValue(strategy="AUTO") */ private $id; /** - @var string $role * - @Orm\Column(name="role", type="string", length=20, unique=true) */ private $role; /** - @var string $label * - @Orm\Column(name="label", type="string", length=45) */ private $label; /** - Profiles - - @var ArrayCollection - - @Orm\ManyToMany(targetEntity="Profile", mappedBy="roles") */ private $profiles; //========================================================================== // GETTERS / SETTERS //========================================================================== /** - Get id * - @return integer */ public function getId() { return $this->id; } /** - Get role // IMPLEMENTS * - @return string _/ public function getRole() { return $this->role; } /_* - Set role * - @param string $role - @return Role */ public function setRole($role) { $this->role = $role; return $this; } /** - Get label * - @return string _/ public function getLabel() { return $this->label; } /_* - Set label * - @param string $label */ public function setLabel($label) { $this->label = $label; } /** - Get profiless * - @return \Doctrine\Common\Collections\Collection */ public function getProfiles() { return $this->profiles; } /** - Add profiles * - @param \Uda\CoreBundle\Entity\Profile $profiles - @return Role */ public function addProfile(\Uda\CoreBundle\Entity\Profile $profiles) { $this->profiles[] = $profiles; return $this; } /** - Remove profiles * - @param \Uda\CoreBundle\Entity\Profile $profiles */ public function removeProfile(\Uda\CoreBundle\Entity\Profile $profiles) { $this->profiles->removeElement($profiles); } //========================================================================== // IMPLEMENTS //========================================================================== public function __toString() { return $this->getName(); } //========================================================================== // METHODS //========================================================================== } Lab.php id; } /** - Get graalId * - @return integer _/ public function getGraalId() { return $this->graalId; } /_* - Set graalId * - @param string $graalId */ public function setGraalId($graalId) { $this->graalId = $graalId; } /** - Get code * - @return string _/ public function getCode() { return $this->code; } /_* - Set code * - @param string $code */ public function setCode($code) { $this->code = $code; } /** - Get label * - @return string _/ public function getLabel() { return $this->label; } /_* - Set label * - @param string $label */ public function setLabel($label) { $this->label = $label; } //========================================================================== // METHODS //========================================================================== /** - Add users * - @param \Uda\CoreBundle\Entity\User $users - @return Role */ public function addUser(\Uda\CoreBundle\Entity\User $users) { $this->users[] = $users; return $this; } /** - Remove users * - @param \Uda\CoreBundle\Entity\User $users */ public function removeUser(\Uda\CoreBundle\Entity\User $users) { $this->users->removeElement($users); } /** - Get users * - @return \Doctrine\Common\Collections\Collection */ public function getUsers() { return $this->users; } }The text was updated successfully, but these errors were encountered: