1000 search results

// ... lines 1 - 72
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
// ... lines 75 - 76
$url = $this->router->generate('login');
return new RedirectResponse($url);
}
// ... lines 81 - 101
See Code Block in Script
// ... lines 1 - 81
public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey)
{
$url = $this->router->generate('homepage');
return new RedirectResponse($url);
}
// ... lines 88 - 101
See Code Block in Script
// ... lines 1 - 88
public function start(Request $request, AuthenticationException $authException = null)
{
$url = $this->router->generate('login');
return new RedirectResponse($url);
}
// ... lines 95 - 101
See Code Block in Script
// ... lines 1 - 95
public function supportsRememberMe()
{
return true;
}
// ... lines 100 - 101
See Code Block in Script
// ... lines 1 - 12
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
// ... lines 14 - 43
public function getUser($credentials, UserProviderInterface $userProvider)
{
// ... lines 46 - 48
if (substr($username, 0, 1) == '@') {
throw new CustomUserMessageAuthenticationException(
'Starting a username with @ is weird, don\'t you think?'
);
}
// ... lines 54 - 56
}
// ... lines 58 - 108
See Code Block in Script
// ... lines 1 - 58
public function checkCredentials($credentials, UserInterface $user)
{
// ... lines 61 - 64
if ($credentials['answer'] != 42) {
throw new CustomUserMessageAuthenticationException(
'Don\'t you read any books?'
);
}
// ... lines 70 - 77
}
// ... lines 79 - 108
See Code Block in Script
// ... lines 1 - 58
public function checkCredentials($credentials, UserInterface $user)
{
// ... lines 61 - 70
if (!$credentials['terms']) {
throw new CustomUserMessageAuthenticationException(
'Agree to our terms!!!'
);
}
return true;
}
// ... lines 79 - 108
See Code Block in Script
// ... lines 1 - 2
namespace AppBundle\Security;
// ... lines 4 - 18
class WeirdFormAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 21 - 23
public function __construct(EntityManager $em, RouterInterface $router)
{
// ... lines 26 - 27
}
// ... lines 29 - 106
}
See Code Block in Script
// ... lines 1 - 2
namespace AppBundle\Security;
class EvilSecurityRobot
{
public function doesRobotAllowAccess()
{
return rand(0, 10) >= 5;
}
}
See Code Block in Script
// ... lines 1 - 18
class WeirdFormAuthenticator extends AbstractGuardAuthenticator
{
// ... lines 21 - 22
private $robot;
// ... line 24
public function __construct(EntityManager $em, RouterInterface $router, EvilSecurityRobot $robot)
{
// ... lines 27 - 28
$this->robot = $robot;
}
// ... lines 31 - 114
}
See Code Block in Script
// ... lines 1 - 60
public function checkCredentials($credentials, UserInterface $user)
{
if (!$this->robot->doesRobotAllowAccess()) {
throw new CustomUserMessageAuthenticationException(
'RANDOM SECURITY ROBOT SAYS NO!'
);
}
// ... lines 68 - 85
}
// ... lines 87 - 116
See Code Block in Script
19 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 2
namespace AppBundle\Security;
// ... lines 4 - 5
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
class UserVoter extends Voter
{
// ... lines 10 - 18
}
See Code Block in Script
19 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 4
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
// ... lines 6 - 7
class UserVoter extends Voter
{
protected function supports($attribute, $object)
{
}
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
// TODO: Implement voteOnAttribute() method.
}
}
See Code Block in Script
35 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 8
class UserVoter extends Voter
{
// ... lines 11 - 17
protected function supports($attribute, $object)
{
if ($attribute != 'USER_VIEW') {
return false;
}
// ... lines 23 - 28
}
// ... lines 30 - 34
}
See Code Block in Script
35 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 17
protected function supports($attribute, $object)
{
if ($attribute != 'USER_VIEW') {
return false;
}
if (!$object instanceof User) {
return false;
}
return true;
}
// ... lines 30 - 35
See Code Block in Script
35 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 8
class UserVoter extends Voter
{
// ... lines 11 - 30
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
// ... line 33
}
}
See Code Block in Script
35 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 8
class UserVoter extends Voter
{
private $robot;
public function __construct(EvilSecurityRobot $robot)
{
$this->robot = $robot;
}
// ... lines 17 - 34
}
See Code Block in Script
35 lines | src/AppBundle/Security/UserVoter.php
// ... lines 1 - 30
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
{
return $this->robot->doesRobotAllowAccess();
}
See Code Block in Script
Blog
Introducing Guard: Symfony Security with a Smile

…HWIOAuthBundle exists, but it has a lot of security classes to make this happen. This problem was screaming for a solution. If we could make Symfony's authentication system simple and fun, the whole security system would go from a pain, to a powerful tool…

// ... lines 1 - 19
class BadCredentialsException extends AuthenticationException
{
// ... lines 22 - 24
public function getMessageKey()
{
return 'Invalid credentials.';
}
}
See Code Block in Script