sfDoctrineGuardPlugin credentials issue

Ask help about existing plugins, or find advice about the way to build up your own.

Moderators: dwhittle, Ian

sfDoctrineGuardPlugin credentials issue

Postby dziamid » Wed Apr 06, 2011 3:04 pm

I use my own method for authentication in backend:
Code: Select all
//app.yml
all:
  sf_guard_plugin:
    retrieve_by_username_callable: sfGuardUser::getForBackend

//sfGuardUser.class.php

  public static function getForBackend($username)
  {
    $query = Doctrine::getTable('sfGuardUser')->createQuery('u')
      ->leftJoin('u.Groups g')
      ->leftJoin('g.Permissions p')
      ->where('u.username = ? OR u.email_address = ?', array($username, $username))
      ->addWhere('u.is_active = ?', true)
      ->addWhere('p.name = ?', 'backend');

    return $query->fetchOne();
  }

Works fine, except that user has only one credential now ('backend'), but should have more.
Here are the fixtures:
Code: Select all
sfGuardGroup:
  Group_admin:
    name:           admin
    Permissions:    [Permission_admin, Permission_chief, Permission_expert, Permission_backend]
sfGuardPermission:
  Permission_admin:
    name:           admin
  Permission_chief:
    name:           chief
  Permission_expert:
    name:           expert
  Permission_backend:
    name:           backend

So, user should have all permissions of 'admin' group, but only gets 'backend' permission. Looks like a bug, isn't it?
P.S. If I remove the last line from query (->addWhere('p.name = ?', 'backend')) then credentials are set correctly.
dziamid
Member
 
Posts: 87
Joined: Tue Jun 22, 2010 3:43 pm

Re: sfDoctrineGuardPlugin credentials issue

Postby dziamid » Wed Apr 06, 2011 4:29 pm

Well, if anyone faces it, here is a little workaround, but feel free to come up with better solution.
Code: Select all
class myUser extends sfGuardSecurityUser
{
  public function signIn($user, $remember = false, $con = null)
  {
    parent::signIn($user, $remember, $con);
   
    //this fixes bug with incorrect credential setting when using custom login method
    $q = Doctrine::getTable('sfGuardPermission')->
      createQuery('p')->
      select('p.name')->
      innerJoin('p.Groups g')->
      innerJoin('g.Users u')->
      where('u.id = ?', $this->getGuardUser()->getId());
    $credentials = $q->fetchArray();
    $this->clearCredentials();
    foreach ($credentials as $credential)
    {
      $this->addCredential($credential['name']);
    }

  }

}
dziamid
Member
 
Posts: 87
Joined: Tue Jun 22, 2010 3:43 pm


Return to General plug-ins

Who is online

Users browsing this forum: No registered users and 1 guest