1000 search results

// ... 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
…|css|images|js)/ security: false main: anonymous: ~ pattern: ^/ http_basic: ~ provider: db_user_provider form_login: login_path: app_login check_path: app_login default_target_path: / logout: path: app_logout target: / remember_me: secret: '%kernel.secret%' lifetime: 2592000 guard: authenticators: - App\Security\LoginFormAuthenticator…
…|css|images|js)/ security: false main: anonymous: ~ pattern: ^/ http_basic: ~ provider: db_user_provider form_login: login_path: app_login check_path: app_login default_target_path: / logout: path: app_logout target: / remember_me: secret: '%kernel.secret%' lifetime: 2592000 guard: authenticators: - App\Security\LoginFormAuthenticator…
// ... lines 1 - 11
/**
* @Security("is_granted('ROLE_MANAGE_GENUS')")
* @Route("/admin")
*/
class GenusAdminController extends Controller
// ... lines 17 - 86
See Code Block in Script
72 lines | src/ApiResource/UserApi.php
// ... lines 1 - 20
#[ApiResource(
// ... lines 22 - 35
security: 'is_granted("ROLE_USER")',
// ... lines 37 - 39
)]
// ... lines 41 - 43
class UserApi
{
// ... lines 46 - 70
}
See Code Block in Script
252 lines | src/Entity/User.php
// ... lines 1 - 20
#[ApiResource(
// ... lines 22 - 23
security: 'is_granted("ROLE_USER")',
)]
// ... lines 26 - 40
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 43 - 250
}
See Code Block in Script
252 lines | src/Entity/User.php
// ... lines 1 - 25
#[ApiResource(
// ... lines 27 - 35
security: 'is_granted("ROLE_USER")',
)]
// ... lines 38 - 40
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 43 - 250
}
See Code Block in Script
Adding security checks in controller methods could quickly lead to massive code duplication. Say that I have a few controllers with a few dozens of methods - the code will be almost unmaintainable. So the question is: does Symphony have something like AOP to deal with…
Hey |mention:90254| `security.yaml` is the best place to keep your "static" user roles. I'm a bit confused about your question. What do you mean by "access that from the ApiToken entity" Cheers!
MolloKhan
MolloKhan
Read Full Comment
117 lines | src/Controller/OrderController.php
// ... lines 1 - 12
use Symfony\Component\Security\Http\Attribute\CurrentUser;
// ... lines 14 - 15
class OrderController extends AbstractController
{
// ... lines 18 - 57
#[Route('/checkout', name: 'app_order_checkout')]
public function checkout(
// ... lines 60 - 62
#[CurrentUser] ?User $user,
): Response {
$lsCheckoutUrl = $this->createLsCheckoutUrl($lsClient, $cart, $user);
// ... lines 66 - 67
}
// ... line 69
private function createLsCheckoutUrl(HttpClientInterface $lsClient, ShoppingCart $cart, ?User $user): string
{
// ... lines 72 - 114
}
}
See Code Block in Script