Skip to content

Instantly share code, notes, and snippets.

Piper piotrbrzezina

Block or report user

Report or block piotrbrzezina

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View App\Swagger\SwaggerDecorator.php
<?php
class SwaggerDecorator implements NormalizerInterface
{
private $decorated;
public function __construct(NormalizerInterface $decorated)
{
$this->decorated = $decorated;
}
View App\Util\Doctrine\OwnerExtension.php
<?php
class OwnerExtension implements QueryCollectionExtensionInterface
{
private $tokenStorage;
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
@piotrbrzezina
piotrbrzezina / App\Entity\Subject.php
Created Jun 26, 2019
Flashcard step 9 (security advance)
View App\Entity\Subject.php
<?php
/**
* @ApiResource(
* ...
* itemOperations={
* "get" = { object.user == user" },
* "put" = { object.user == user" }
* },
* )
@piotrbrzezina
piotrbrzezina / App\Entity\Subject.php
Created Jun 26, 2019
Flashcard step 9 (security)
View App\Entity\Subject.php
/**
* @ApiResource(
* normalizationContext={"groups"={"subjectList"}},
* denormalizationContext={"groups"={"subjectCreate"}},
* itemOperations={"get","put"},
* attributes={"access_control"="is_granted('ROLE_USER')"}
* )
*
* @ORM\Entity
*/
View App\EventSubscriber\UserSubscriber.php
<?php
namespace App\EventSubscriber;
use ApiPlatform\Core\EventListener\EventPriorities;
use App\Entity\User;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
@piotrbrzezina
piotrbrzezina / App\Entity\User.php
Created Jan 27, 2019
Flashcard step 8 (Event system)
View App\Entity\User.php
<?php
// ...
class User implements UserInterface
{
// ...
public $roles = ['ROLE_USER'];
/**
* ...
* @Assert\Length(min="8", max="255", groups={"userCreate", "userChangePassword"})
View api\config\packages\security.yaml
encoders:
App\Entity\User:
algorithm: 'argon2i'
memory_cost: 1024
time_cost: 2
threads: 2
@piotrbrzezina
piotrbrzezina / api\config\routes.yaml
Created Jan 27, 2019
configure security login path
View api\config\routes.yaml
login:
path: /login
View api\config\packages\security.yaml
...
firewalls:
login:
pattern: ^/login
stateless: true
anonymous: true
provider: db_provider
json_login:
check_path: /login
View api\config\packages\security.yaml
security:
providers:
db_provider:
entity:
class: App\Entity\User
property: email
You can’t perform that action at this time.