I want to create custom user checker to validate login action against last accepted eula. ' Idea is quite simple, there will be many versions of eula and user can't login untill he accept the lastest eula.
Scenario is:
I found this: https://groups.google.com/forum/#!msg/symfony2/D0V0bFks9S0/Qg9mrbpfB3IJ
But unfortunately there is no full version of custom user checker. How do I implement the rest of it?
The answer is actually quite obvious. In your custom bundle:
config.yml
parameters:
security.user_checker.class: Acme\Bundle\UserBundle\Security\UserChecker
Userchecker:
class UserChecker extends BaseUserChecker
{
/**
* {@inheritdoc}
*/
public function checkPreAuth(UserInterface $user)
{
//do your custom preauth stuff here
parent::checkPreAuth($user);
}
}
You can redefine Symfony's user checker service (security.user_checker
) in your bundle:
# services.yml
security.user_checker:
class: MyBundle\Checker\UserChecker
arguments: [ "@some.service", "%some.param%" ]
Then extend Symfony's UserChecker:
# UserChecker.php
use Symfony\Component\Security\Core\User\UserChecker as BaseUserChecker;
class UserChecker extends BaseUserChecker
{
public function checkPreAuth(UserInterface $user)
{
parent::checkPreAuth($user);
// your stuff
}
public function checkPostAuth(UserInterface $user)
{
parent::checkPostAuth($user);
// your stuff
}
}
The security.user_checker
service gets called in \Symfony\Component\Security\Core\Authentication\Provider\UserAuthenticationProvider::authenticate()
during the authentication process
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With