Advertisement
Guest User

Untitled

a guest
Aug 4th, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.61 KB | None | 0 0
  1. [2016-08-04 11:37:17] request.INFO: Matched route "BloggerBlogBundle_security_check". {"route_parameters":{"_route":"BloggerBlogBundle_security_check"},"request_uri":"http://symfony_blog.workspace/web/app_dev.php/login_check"} []
  2. [2016-08-04 11:37:17] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): Bad credentials. at /var/www/workspace/symfony_blog/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php:73, Symfony\Component\Security\Core\Exception\UsernameNotFoundException(code: 0): Username "john.doe" does not exist. at /var/www/workspace/symfony_blog/vendor/symfony/symfony/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php:109)"} []
  3. [2016-08-04 11:37:17] security.DEBUG: Authentication failure, redirect triggered. {"failure_path":"/login"} []
  4. [2016-08-04 11:37:17] request.INFO: Matched route "_wdt". {"route_parameters":{"_controller":"web_profiler.controller.profiler:toolbarAction","token":"7677b7","_route":"_wdt"},"request_uri":"http://symfony_blog.workspace/web/app_dev.php/_wdt/7677b7"} []
  5.  
  6. Username "john.doe" does not exist.
  7.  
  8. security:
  9. encoders:
  10. BloggerBlogBundleEntityUser:
  11. algorithm: sha512
  12. encode-as-base64: true
  13. iterations: 10
  14.  
  15. providers:
  16. main:
  17. entity:
  18. class: BloggerBlogBundleEntityUser
  19. property: username
  20.  
  21. firewalls:
  22. main:
  23. pattern: /.*
  24. form_login:
  25. check_path: /login_check
  26. login_path: /login
  27. logout: true
  28. security: true
  29. anonymous: true
  30.  
  31. access_control:
  32. - { path: /admin/.*, role: ROLE_ADMIN }
  33. - { path: /.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
  34.  
  35. BloggerBlogBundle_comment_create:
  36. path: /comment/{blog_id}
  37. defaults: { _controller: 'BloggerBlogBundle:Comment:create' }
  38. requirements:
  39. method: POST
  40. blog_id: d+
  41.  
  42. BloggerBlogBundle_security_login:
  43. path: /login
  44. defaults: {_controller: BloggerBlogBundle:Security:login }
  45.  
  46. BloggerBlogBundle_security_check:
  47. path: /login_check
  48.  
  49. BloggerBlogBundle_security_logout:
  50. path: /logout
  51.  
  52. BloggerBlogBindle_admin_home:
  53. path: /admin/
  54. defaults: { controller: BloggerBlogBundle:Admin:index }
  55.  
  56. <?php
  57.  
  58. // src/Blogger/BlogBundle/Entity/Role.php
  59.  
  60. namespace BloggerBlogBundleEntity;
  61.  
  62. use SymfonyComponentSecurityCoreRoleRoleInterface;
  63. use DoctrineORMMapping as ORM;
  64.  
  65. /**
  66. * @ORMEntity
  67. * @ORMTable(name="role")
  68. * @ORMHasLifecycleCallbacks
  69. */
  70. class Role implements RoleInterface
  71. {
  72. /**
  73. * @ORMId
  74. * @ORMColumn(type="integer")
  75. * @ORMGeneratedValue(strategy="AUTO")
  76. */
  77. protected $id;
  78.  
  79. /**
  80. * @ORMColumn(type="string", length=255)
  81. */
  82. protected $name;
  83.  
  84. /**
  85. * @ORMColumn(type="datetime", name="created_at")
  86. */
  87. protected $createdAt;
  88.  
  89. public function __construct()
  90. {
  91. $this->setCreatedAt(new DateTime());
  92. }
  93.  
  94. /**
  95. * Get id
  96. *
  97. * @return integer
  98. */
  99. public function getId()
  100. {
  101. return $this->id;
  102. }
  103.  
  104. /**
  105. * Set name
  106. *
  107. * @param string $name
  108. *
  109. * @return Role
  110. */
  111. public function setName($name)
  112. {
  113. $this->name = $name;
  114.  
  115. return $this;
  116. }
  117.  
  118. /**
  119. * Get name
  120. *
  121. * @return string
  122. */
  123. public function getName()
  124. {
  125. return $this->name;
  126. }
  127.  
  128. /**
  129. * Set createdAt
  130. *
  131. * @param DateTime $createdAt
  132. *
  133. * @return Role
  134. */
  135. public function setCreatedAt($createdAt)
  136. {
  137. $this->createdAt = $createdAt;
  138.  
  139. return $this;
  140. }
  141.  
  142. /**
  143. * Get createdAt
  144. *
  145. * @return DateTime
  146. */
  147. public function getCreatedAt()
  148. {
  149. return $this->createdAt;
  150. }
  151.  
  152. /**
  153. * This method is needed to implement RoleInterface
  154. */
  155. public function getRole()
  156. {
  157. return $this->getName();
  158. }
  159. }
  160.  
  161. // src/Blogger/BlogBundle/Entity/User.php
  162.  
  163. namespace BloggerBlogBundleEntity;
  164.  
  165. use DoctrineCommonCollectionArraCollection;
  166. use DoctrineCommonCollectionsArrayCollection;
  167. use DoctrineORMMapping as ORM;
  168. use SymfonyComponentSecurityCoreUserUserInterface;
  169.  
  170. /**
  171. * @ORMEntity
  172. * @ORMTable(name="user")
  173. * @ORMHasLifecycleCallbacks
  174. */
  175. class User implements UserInterface
  176. {
  177. /**
  178. * @ORMId
  179. * @ORMColumn(type="integer")
  180. * @ORMGeneratedValue(strategy="AUTO")
  181. */
  182. protected $id;
  183.  
  184. /**
  185. * @ORMColumn(type="string", length=255, unique=true)
  186. */
  187. protected $username;
  188.  
  189. /**
  190. * @ORMColumn(type="string", length=255)
  191. */
  192. protected $password;
  193.  
  194. /**
  195. * @ORMColumn(type="string", length=255)
  196. */
  197. protected $salt;
  198.  
  199. /**
  200. * @ORMManyToMany(targetEntity="Role")
  201. * @ORMJoinTable(name="user_role",
  202. * joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
  203. * inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id")}
  204. * )
  205. */
  206. protected $userRoles;
  207.  
  208. /**
  209. * @ORMColumn(type="boolean")
  210. */
  211. protected $status;
  212.  
  213. /**
  214. * @ORMColumn(name="is_active", type="boolean")
  215. */
  216. protected $isActive;
  217.  
  218. /**
  219. * @ORMColumn(type="datetime")
  220. */
  221. protected $date_added;
  222.  
  223. public function __construct()
  224. {
  225. $this->ports = new ArrayCollection();
  226. $this->userRoles = new ArrayCollection();
  227. $this->setDateAdded(new DateTime());
  228. }
  229.  
  230. /**
  231. * Clear user privileges
  232. **/
  233. public function eraseCredentials()
  234. {
  235.  
  236. }
  237.  
  238. /**
  239. * @return array of Role object
  240. */
  241. public function getRoles()
  242. {
  243. return $this->getUserRoles()->toArray();
  244. }
  245.  
  246. /**
  247. * Compare one user to another user
  248. * and determine if its same user
  249. *
  250. * @param UserInterface $user
  251. * @return boolean True if equals and false otherwise
  252. */
  253. public function equals(UserInterface $user)
  254. {
  255. return md5($this->getUsername()) == md5($user->getUsername());
  256. }
  257.  
  258. /**
  259. * Get id
  260. *
  261. * @return integer
  262. */
  263. public function getId()
  264. {
  265. return $this->id;
  266. }
  267.  
  268. /**
  269. * Set username
  270. *
  271. * @param string $username
  272. *
  273. * @return User
  274. */
  275. public function setUsername($username)
  276. {
  277. $this->username = $username;
  278.  
  279. return $this;
  280. }
  281.  
  282. /**
  283. * Get username
  284. *
  285. * @return string
  286. */
  287. public function getUsername()
  288. {
  289. return $this->username;
  290. }
  291.  
  292. /**
  293. * @return string
  294. */
  295. public function setPassword($password)
  296. {
  297. $this->password = $password;
  298.  
  299. return $password;
  300. }
  301.  
  302. /**
  303. * @return string
  304. */
  305. public function getPassword()
  306. {
  307. return $this->password;
  308. }
  309.  
  310. /**
  311. * @return string
  312. */
  313. public function setSalt($salt)
  314. {
  315. $this->salt = $salt;
  316.  
  317. return $this;
  318. }
  319.  
  320. /**
  321. * @return string
  322. */
  323. public function getSalt()
  324. {
  325. return $this->salt;
  326. }
  327.  
  328. /**
  329. * Set status
  330. *
  331. * @param boolean $status
  332. *
  333. * @return User
  334. */
  335. public function setStatus($status)
  336. {
  337. $this->status = $status;
  338.  
  339. return $this;
  340. }
  341.  
  342. /**
  343. * Get status
  344. *
  345. * @return boolean
  346. */
  347. public function getStatus()
  348. {
  349. return $this->status;
  350. }
  351.  
  352. /**
  353. * Set dateAdded
  354. *
  355. * @param DateTime $dateAdded
  356. *
  357. * @return User
  358. */
  359. public function setDateAdded($dateAdded)
  360. {
  361. $this->date_added = $dateAdded;
  362.  
  363. return $this;
  364. }
  365.  
  366. /**
  367. * Get dateAdded
  368. *
  369. * @return DateTime
  370. */
  371. public function getDateAdded()
  372. {
  373. return $this->date_added;
  374. }
  375.  
  376. /**
  377. * Get user roles
  378. *
  379. * @return ArrayCollection
  380. */
  381. public function getUserRoles()
  382. {
  383. return $this->userRoles;
  384. }
  385.  
  386. /**
  387. * Set isActive
  388. *
  389. * @param boolean $isActive
  390. *
  391. * @return User
  392. */
  393. public function setIsActive($isActive)
  394. {
  395. $this->isActive = $isActive;
  396.  
  397. return $this;
  398. }
  399.  
  400. /**
  401. * Get isActive
  402. *
  403. * @return boolean
  404. */
  405. public function getIsActive()
  406. {
  407. return $this->isActive;
  408. }
  409.  
  410. /**
  411. * Add userRole
  412. *
  413. * @param BloggerBlogBundleEntityRole $userRole
  414. *
  415. * @return User
  416. */
  417. public function addUserRole(BloggerBlogBundleEntityRole $userRole)
  418. {
  419. $this->userRoles[] = $userRole;
  420.  
  421. return $this;
  422. }
  423.  
  424. /**
  425. * Remove userRole
  426. *
  427. * @param BloggerBlogBundleEntityRole $userRole
  428. */
  429. public function removeUserRole(BloggerBlogBundleEntityRole $userRole)
  430. {
  431. $this->userRoles->removeElement($userRole);
  432. }
  433. }
  434.  
  435. <?php
  436.  
  437. // src/Blogger/BlogBundle/DataFixtures/ORM/UserFixture.php
  438.  
  439. namespace BloggerBlogBundleDataFixtureORM;
  440.  
  441. use DoctrineCommonDataFixturesFixtureInterface;
  442. use DoctrineCommonPersistenceObjectManager;
  443. use BloggerBlogBundleEntityUser;
  444. use BloggerBlogBundleEntityRole;
  445. use SymfonyComponentSecurityCoreEncoderMessageDigestPasswordEncoder;
  446.  
  447. class UserFixture implements FixtureInterface
  448. {
  449. public function load(ObjectManager $manager)
  450. {
  451. // Create role
  452. $role = new Role();
  453. $role->setName('ROLE_ADMIN');
  454.  
  455. $manager->persist($role);
  456.  
  457. // Create user
  458. $user = new User();
  459. $user->setUsername('john.doe');
  460. $user->setStatus(true);
  461. $user->setSalt(md5(time()));
  462.  
  463. // encrypt and set password to user
  464. // this settings coincide to configuration
  465. $encoder = new MessageDigestPasswordEncoder('sha512', true, 10);
  466. $password = $encoder->encodePassword('admin', $user->getSalt());
  467.  
  468. $user->setPassword($password);
  469.  
  470. $user->getUserRoles()->add($role);
  471.  
  472. $manager->persist($user);
  473. $manager->flush();
  474. }
  475. }
  476.  
  477. [2016-08-04 11:37:17] security.INFO: Authentication request failed. {"exception":"[object] (Symfony\Component\Security\Core\Exception\BadCredentialsException(code: 0): Bad credentials. at /var/www/workspace/symfony_blog/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Provider/UserAuthenticationProvider.php:73, Symfony\Component\Security\Core\Exception\UsernameNotFoundException(code: 0): **Username "john.doe" does not exist. at /var/www/workspace/symfony_blog/vendor/symfony/symfony/src/Symfony/Component/Security/Core/User/InMemoryUserProvider.php:109**)"} []
  478.  
  479. providers:
  480. main:
  481. entity:
  482. class: BloggerBlogBundle:User
  483. property: username
  484.  
  485. providers:
  486. main:
  487. entity: { class: BloggerBlogBundle:User, property: username }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement