-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
Happy birthday symfony!
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineBundle\Security; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use Symfony\Component\Security\User\UserProviderInterface; | ||
use Symfony\Component\Security\Exception\UsernameNotFoundException; | ||
|
||
class EntityUserProvider implements UserProviderInterface | ||
{ | ||
protected $repository; | ||
protected $property; | ||
|
||
public function __construct($em, $class, $property = null) | ||
{ | ||
$this->repository = $em->getRepository($class); | ||
$this->property = $property; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function loadUserByUsername($username) | ||
{ | ||
if (null !== $this->property) { | ||
$user = $this->repository->findOneBy(array($this->property => $username)); | ||
} else { | ||
if (!$this->repository instanceof UserProviderInterface) { | ||
throw new \InvalidArgumentException('The Doctrine user manager must implement UserManagerInterface.'); | ||
} | ||
|
||
$user = $this->repository->loadUserByUsername($username); | ||
} | ||
|
||
if (null === $user) { | ||
throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); | ||
} | ||
|
||
return $user; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Controller; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerAware; | ||
use Symfony\Component\Security\SecurityContext; | ||
|
||
/* | ||
* This file is part of the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
/** | ||
* SecurityController. | ||
* | ||
* @author Fabien Potencier <fabien.potencier@symfony-project.com> | ||
*/ | ||
class SecurityController extends ContainerAware | ||
{ | ||
/** | ||
* Displays the login form. | ||
* | ||
* @return Response A Response instance | ||
*/ | ||
public function loginAction() | ||
{ | ||
$request = $this->container->get('request'); | ||
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { | ||
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); | ||
} else { | ||
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR); | ||
} | ||
|
||
return $this->container->get('templating')->renderResponse('FrameworkBundle:Security:login.php', array( | ||
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME), | ||
'error' => $error, | ||
)); | ||
} | ||
} |
16 comments
on commit f216f31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ROCK ON!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THIS IS SPARTA! ... ERR SYMFONY!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy B-Day!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yay! Happy 5th b-day Symfony ! Thanks for the present :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I smell an application refactor coming...nice work Fabien. Looks amazing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done, Fabien, your hard work is much appreciated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent stuff, Fabien!
Happy 5th birthday!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Fabien! Symfony is great!
Happy 5ymfony day!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why you set in the AnonymousToken class the authenticated status to true if the user is a anonymous user? The documentation says a anonymous user is not authenticated and check if a user is fully-authenticated with the isAuthenticated() of the security context. But the isAuthenticated() of the security context return always true if the user is a anonymous user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 on that question, i have the same problem with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isAuthenticated() is supposed to be used internally only, not by the end user. Roles are used for authorization. The following is directly from Spring Security:
/**
* Used to indicate to {@code AbstractSecurityInterceptor} whether it should present the
* authentication token to the AuthenticationManager
. Typically an AuthenticationManager
* (or, more often, one of its AuthenticationProvider
s) will return an immutable authentication token
* after successful authentication, in which case that token can safely return true
to this method.
* Returning true
will improve performance, as calling the AuthenticationManager
for
* every request will no longer be necessary.
*
* For security reasons, implementations of this interface should be very careful about returning
* true
from this method unless they are either immutable, or have some way of ensuring the properties
* have not been changed since original creation.
*
* @return true if the token has been authenticated and the AbstractSecurityInterceptor
does not need
* to present the token to the AuthenticationManager
again for re-authentication.
*/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok but how can I now test whether the user is not an anonymous user? Currently, I call for two functions. First isAuthenticated () and then getUser() and check if it is not == 'anon.' . I think that it can not be useful right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the IS_AUTHENTICATED_FULLY role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you it works :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the confusion. I have just fixed the documentation: symfony/symfony-docs@434a1de
Hi, it seems the SecurityLoader class has been forgotten