Guest User

Untitled

a guest
Mar 19th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. security:
  2. # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
  3. # encoders:
  4. # AppEntityUser: bcrypt
  5.  
  6. encoders:
  7. AppEntityUser: plaintext
  8. SymfonyComponentSecurityCoreUserUser: plaintext
  9.  
  10. providers:
  11. in_memory:
  12. memory:
  13. users:
  14. user:
  15. password: user-test
  16. roles: 'ROLE_USER'
  17. admin:
  18. password: admin-test
  19. roles: 'ROLE_ADMIN'
  20. my_own_provider:
  21. entity:
  22. class: AppEntityUser
  23. property: username
  24. # if you're using multiple entity managers
  25. # manager_name: customer
  26. firewalls:
  27. login:
  28. pattern: ^/api/login
  29. stateless: true
  30. anonymous: true
  31. provider: my_own_provider
  32. form_login:
  33. check_path: /api/login_check
  34. success_handler: lexik_jwt_authentication.handler.authentication_success
  35. failure_handler: lexik_jwt_authentication.handler.authentication_failure
  36. require_previous_session: false
  37.  
  38. api_documentation:
  39. pattern: ^/api/documentation
  40. anonymous: ~
  41. provider: my_own_provider
  42.  
  43. api:
  44. pattern: ^/
  45. stateless: true
  46. provider: my_own_provider
  47. guard:
  48. authenticators:
  49. - lexik_jwt_authentication.jwt_token_authenticator
  50.  
  51.  
  52.  
  53. access_control:
  54. - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  55. - { path: ^/api/documentation, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  56. - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
  57.  
  58. role_hierarchy:
  59. ROLE_API: [ROLE_USER]
  60.  
  61. <?php
  62.  
  63. // src/Entity/User.php
  64. namespace AppEntity;
  65.  
  66. use DoctrineORMMapping as ORM;
  67. use SymfonyComponentSecurityCoreUserUserInterface;
  68.  
  69. /**
  70. * @ORMTable(name="app_users")
  71. * @ORMEntity(repositoryClass="AppRepositoryUserRepository")
  72. */
  73. class User implements UserInterface, Serializable
  74. {
  75. /**
  76. * @ORMColumn(type="integer")
  77. * @ORMId
  78. * @ORMGeneratedValue(strategy="AUTO")
  79. */
  80. private $id;
  81.  
  82. /**
  83. * @ORMColumn(type="string", length=25, unique=true)
  84. */
  85. private $username;
  86.  
  87. /**
  88. * @ORMColumn(type="string", length=64)
  89. */
  90. private $password;
  91.  
  92. /**
  93. * @ORMColumn(type="string", length=254, unique=true)
  94. */
  95. private $email;
  96.  
  97. /**
  98. * @ORMColumn(name="is_active", type="boolean")
  99. */
  100. private $isActive;
  101.  
  102. public function __construct()
  103. {
  104. $this->isActive = true;
  105. // may not be needed, see section on salt below
  106. // $this->salt = md5(uniqid('', true));
  107. }
  108.  
  109. public function getUsername()
  110. {
  111. return $this->username;
  112. }
  113.  
  114. public function getSalt()
  115. {
  116. // you *may* need a real salt depending on your encoder
  117. // see section on salt below
  118. return null;
  119. }
  120.  
  121. public function getPassword()
  122. {
  123. return $this->password;
  124. }
  125.  
  126. public function getRoles()
  127. {
  128. return array('ROLE_USER');
  129. }
  130.  
  131. /**
  132. * @return mixed
  133. */
  134. public function getId()
  135. {
  136. return $this->id;
  137. }
  138.  
  139. /**
  140. * @param mixed $id
  141. */
  142. public function setId( $id )
  143. {
  144. $this->id = $id;
  145. }
  146.  
  147. /**
  148. * @return mixed
  149. */
  150. public function getEmail()
  151. {
  152. return $this->email;
  153. }
  154.  
  155. /**
  156. * @param mixed $email
  157. */
  158. public function setEmail( $email )
  159. {
  160. $this->email = $email;
  161. }
  162.  
  163. /**
  164. * @return mixed
  165. */
  166. public function getIsActive()
  167. {
  168. return $this->isActive;
  169. }
  170.  
  171. /**
  172. * @param mixed $isActive
  173. */
  174. public function setIsActive( $isActive )
  175. {
  176. $this->isActive = $isActive;
  177. }
  178.  
  179.  
  180.  
  181.  
  182. public function eraseCredentials()
  183. {
  184. }
  185.  
  186. /** @see Serializable::serialize() */
  187. public function serialize()
  188. {
  189. return serialize(array(
  190. $this->id,
  191. $this->username,
  192. $this->password,
  193. // see section on salt below
  194. // $this->salt,
  195. ));
  196. }
  197.  
  198. /** @see Serializable::unserialize() */
  199. public function unserialize($serialized)
  200. {
  201. list (
  202. $this->id,
  203. $this->username,
  204. $this->password,
  205. // see section on salt below
  206. // $this->salt
  207. ) = unserialize($serialized);
  208. }
  209. }
Add Comment
Please, Sign In to add comment