Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- security:
- # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
- # encoders:
- # AppEntityUser: bcrypt
- encoders:
- AppEntityUser: plaintext
- SymfonyComponentSecurityCoreUserUser: plaintext
- providers:
- in_memory:
- memory:
- users:
- user:
- password: user-test
- roles: 'ROLE_USER'
- admin:
- password: admin-test
- roles: 'ROLE_ADMIN'
- my_own_provider:
- entity:
- class: AppEntityUser
- property: username
- # if you're using multiple entity managers
- # manager_name: customer
- firewalls:
- login:
- pattern: ^/api/login
- stateless: true
- anonymous: true
- provider: my_own_provider
- form_login:
- check_path: /api/login_check
- success_handler: lexik_jwt_authentication.handler.authentication_success
- failure_handler: lexik_jwt_authentication.handler.authentication_failure
- require_previous_session: false
- api_documentation:
- pattern: ^/api/documentation
- anonymous: ~
- provider: my_own_provider
- api:
- pattern: ^/
- stateless: true
- provider: my_own_provider
- guard:
- authenticators:
- - lexik_jwt_authentication.jwt_token_authenticator
- access_control:
- - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/api/documentation, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
- role_hierarchy:
- ROLE_API: [ROLE_USER]
- <?php
- // src/Entity/User.php
- namespace AppEntity;
- use DoctrineORMMapping as ORM;
- use SymfonyComponentSecurityCoreUserUserInterface;
- /**
- * @ORMTable(name="app_users")
- * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
- */
- class User implements UserInterface, Serializable
- {
- /**
- * @ORMColumn(type="integer")
- * @ORMId
- * @ORMGeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @ORMColumn(type="string", length=25, unique=true)
- */
- private $username;
- /**
- * @ORMColumn(type="string", length=64)
- */
- private $password;
- /**
- * @ORMColumn(type="string", length=254, unique=true)
- */
- private $email;
- /**
- * @ORMColumn(name="is_active", type="boolean")
- */
- private $isActive;
- public function __construct()
- {
- $this->isActive = true;
- // may not be needed, see section on salt below
- // $this->salt = md5(uniqid('', true));
- }
- public function getUsername()
- {
- return $this->username;
- }
- public function getSalt()
- {
- // you *may* need a real salt depending on your encoder
- // see section on salt below
- return null;
- }
- public function getPassword()
- {
- return $this->password;
- }
- public function getRoles()
- {
- return array('ROLE_USER');
- }
- /**
- * @return mixed
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @param mixed $id
- */
- public function setId( $id )
- {
- $this->id = $id;
- }
- /**
- * @return mixed
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * @param mixed $email
- */
- public function setEmail( $email )
- {
- $this->email = $email;
- }
- /**
- * @return mixed
- */
- public function getIsActive()
- {
- return $this->isActive;
- }
- /**
- * @param mixed $isActive
- */
- public function setIsActive( $isActive )
- {
- $this->isActive = $isActive;
- }
- public function eraseCredentials()
- {
- }
- /** @see Serializable::serialize() */
- public function serialize()
- {
- return serialize(array(
- $this->id,
- $this->username,
- $this->password,
- // see section on salt below
- // $this->salt,
- ));
- }
- /** @see Serializable::unserialize() */
- public function unserialize($serialized)
- {
- list (
- $this->id,
- $this->username,
- $this->password,
- // see section on salt below
- // $this->salt
- ) = unserialize($serialized);
- }
- }
Add Comment
Please, Sign In to add comment