Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [SF][SF2] Impersonate użytkownika
wiciu010
post 6.06.2015, 15:15:33
Post #1





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Próbuję zrobić impersonate użytkownika zgodnie z instukcją: http://symfony.com/doc/current/cookbook/se...ating_user.html

Udaje mi się zalogować na dowolnego użytkownika, jednak nie moge wrócić na poprzedniego za pomocą _switch_user=_exit

Mój plik security.yml

Kod
jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    encoders:
        Ex\CallBundle\Entity\User:
            algorithm: sha512
            iterations: 5000
            encode_as_base64: false

    role_hierarchy:
        ROLE_ADMIN:       [ROLE_USER, ROLE_ALLOWED_TO_SWITCH]

    providers:
        main:
            entity: { class: Ex\CallBundle\Entity\User, property: username }

    firewalls:
        main:
            pattern:    ^/
            anonymous: ~

            form_login:
                login_path: /login.html
                check_path: /login.html
            logout:
                path:   /logout
                target: /login.html

            switch_user: true

    access_control:
       - { path: ^/admin, roles: ROLE_ADMIN }
       - { path: ^/panel, roles: ROLE_USER }
       - { path: ^/ajax, roles: IS_AUTHENTICATED_FULLY }
       - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY}


Próbuję wrócić z użytkownika z rolą ROLE_USER na użytkownika z rolą ROLE_ADMIN, jednak otrzymuję błąd 403.
Go to the top of the page
+Quote Post
Damonsson
post 6.06.2015, 16:45:48
Post #2





Grupa: Zarejestrowani
Postów: 2 355
Pomógł: 533
Dołączył: 15.01.2010
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


A pokaż dane Security z Symfony Profilera, dla tego usera z ROLE_ADMIN po zalogowaniu i dla tego z ROLE_USER po switchu.

Ten post edytował Damonsson 6.06.2015, 16:47:27
Go to the top of the page
+Quote Post
wiciu010
post 6.06.2015, 17:15:16
Post #3





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Cytat(Damonsson @ 6.06.2015, 17:45:48 ) *
A pokaż dane Security z Symfony Profilera, dla tego usera z ROLE_ADMIN po zalogowaniu i dla tego z ROLE_USER po switchu.


Ok bardzo chętnie wink.gif Ale jak to zrobić?
Go to the top of the page
+Quote Post
Damonsson
post 6.06.2015, 17:51:57
Post #4





Grupa: Zarejestrowani
Postów: 2 355
Pomógł: 533
Dołączył: 15.01.2010
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Tam na tym ( http://symfony.com/doc/current/_images/web_debug_toolbar.png ) pasku na dole, po zalogowaniu się powinieneś mieć bliżej prawego końca nazwę użytkownika, kliknij to najlepiej otwórz w nowej karcie, powinien otworzyć się panel Security ( https://farm9.staticflickr.com/8673/1604772...7d6c07eef_o.png ) i to co może pomóc w diagnozie to wartości z wierszy:
Roles oraz Inherited Roles.

Profiler jest dostępny tylko w trybie developerskim. Jeżeli nie widzisz na dole profilera, to musisz mieć strukturę HTML w widoku, ewentualnie manualnie wyłączyłeś profiler.
Go to the top of the page
+Quote Post
wiciu010
post 7.06.2015, 11:14:52
Post #5





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Cytat(Damonsson @ 6.06.2015, 18:51:57 ) *
Tam na tym ( http://symfony.com/doc/current/_images/web_debug_toolbar.png ) pasku na dole, po zalogowaniu się powinieneś mieć bliżej prawego końca nazwę użytkownika, kliknij to najlepiej otwórz w nowej karcie, powinien otworzyć się panel Security ( https://farm9.staticflickr.com/8673/1604772...7d6c07eef_o.png ) i to co może pomóc w diagnozie to wartości z wierszy:
Roles oraz Inherited Roles.

Profiler jest dostępny tylko w trybie developerskim. Jeżeli nie widzisz na dole profilera, to musisz mieć strukturę HTML w widoku, ewentualnie manualnie wyłączyłeś profiler.


Dla użytkownika z rolą ROLE_ADMIN mam tylko:

Kod
Security

Username    moj_mail@gmail.com
Authenticated?    yes
Roles    [ROLE_ADMIN]


Zaś po wykonaniu impersonate mam:

Kod
Security

Username    e-mail_uzytkownika@domena.pl
Authenticated?    yes
Roles    [ROLE_USER]


Czy tak powinno być?
Go to the top of the page
+Quote Post
Damonsson
post 7.06.2015, 14:47:03
Post #6





Grupa: Zarejestrowani
Postów: 2 355
Pomógł: 533
Dołączył: 15.01.2010
Skąd: Bydgoszcz

Ostrzeżenie: (0%)
-----


Hmm, a Encję: Ex\CallBundle\Entity\User sam pisałeś? Pokaż jej zawartość.

Co do pytania czy tak powinno być, ja mam trochę inne wartości, ale podejrzewam, że to zasługa FOSUserBundle, a nie mam gołej wersji Symfony, żeby sprawdzić.

Ten post edytował Damonsson 7.06.2015, 14:50:08
Go to the top of the page
+Quote Post
wiciu010
post 10.06.2015, 18:33:43
Post #7





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Cytat(Damonsson @ 7.06.2015, 15:47:03 ) *
Hmm, a Encję: Ex\CallBundle\Entity\User sam pisałeś? Pokaż jej zawartość.

Co do pytania czy tak powinno być, ja mam trochę inne wartości, ale podejrzewam, że to zasługa FOSUserBundle, a nie mam gołej wersji Symfony, żeby sprawdzić.


Chyb generowana, ale nie jestem autorem więc na 100% nie powiem. Szczerze to same gettery/settery, więc chyba nie ma sensu tutaj wklejać.

Zauważyłem, że po wykonaniu impersonate nie mam roli ROLE_PREVIOUS_ADMIN, ponieważ nie wyświetla się link powrotu

Kod
{% if is_granted('ROLE_PREVIOUS_ADMIN') %}
     <li><a href="http://panel-klienta.pl/admin/clients?_switch_user=_exit">Powrót na konto administratora</a></li>
{% endif %}


Ten post edytował wiciu010 10.06.2015, 19:29:40
Go to the top of the page
+Quote Post
prz3kus
post 11.06.2015, 08:01:47
Post #8





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

Ostrzeżenie: (0%)
-----


Jak juz jestes zalogowany przejdz na wersje developerską app_dev.php i kliknij na dole w pasku debugowania na login użytkownika tam zobaczysz jakie posiadasz uprawnienia. Powienieś mieć [ROLE_USER, ROLE_PREVIOUS_ADMIN]
Go to the top of the page
+Quote Post
wiciu010
post 11.06.2015, 08:52:09
Post #9





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Cytat(prz3kus @ 11.06.2015, 09:01:47 ) *
Jak juz jestes zalogowany przejdz na wersje developerską app_dev.php i kliknij na dole w pasku debugowania na login użytkownika tam zobaczysz jakie posiadasz uprawnienia. Powienieś mieć [ROLE_USER, ROLE_PREVIOUS_ADMIN]


Właśnie o to chodzi, że mam tylko ROLE_USER. Nie wiem, dlaczego nie ma ROLE_PREVIOUS_ADMIN
Go to the top of the page
+Quote Post
prz3kus
post 11.06.2015, 09:28:30
Post #10





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

Ostrzeżenie: (0%)
-----


wklej całą klase entity oraz napisz jak sie logujesz
Go to the top of the page
+Quote Post
wiciu010
post 11.06.2015, 13:35:07
Post #11





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Cytat(prz3kus @ 11.06.2015, 10:28:30 ) *
wklej całą klase entity oraz napisz jak sie logujesz


Teraz zauważyłem, że w katalogu Entity mam dwa pliki:

User.php
User.php~

Różnią się trochę zawartością. Z czego to wynika? Co to za plik z końcówką "~"?

Poniżej plik User.php

  1. <?php
  2.  
  3. namespace Ex\CallBundle\Entity;
  4.  
  5. /**
  6.  * Ex\CallBundle\Entity\User
  7.  *
  8.  * @ORM\Table(name="User")
  9.  * @ORM\Entity(repositoryClass="Ex\CallBundle\Entity\UserRepository")
  10.  * @UniqueEntity(
  11.  * fields = "email",
  12.  * message = "Taki email jest już w użyciu"
  13.  * )
  14.  */
  15. class User implements AdvancedUserInterface, \Serializable
  16. {
  17. public function __construct()
  18. {
  19.  
  20. }
  21.  
  22. /**
  23.   * @see \Serializable::serialize()
  24.   */
  25. public function serialize()
  26. {
  27. return serialize(array(
  28. $this->id,
  29. ));
  30. }
  31.  
  32. /**
  33.   * @see \Serializable::unserialize()
  34.   */
  35. public function unserialize($serialized)
  36. {
  37. list (
  38. $this->id,
  39. ) = unserialize($serialized);
  40. }
  41.  
  42. /**
  43.   * @inheritDoc
  44.   */
  45. public function eraseCredentials()
  46. {
  47. }
  48.  
  49. public function isAccountNonExpired()
  50. {
  51. return true;
  52. }
  53.  
  54. public function isAccountNonLocked()
  55. {
  56. return true;
  57. }
  58.  
  59. public function isCredentialsNonExpired()
  60. {
  61. return true;
  62. }
  63.  
  64. public function isEnabled()
  65. {
  66. return $this->is_active;
  67. }
  68.  
  69. public function isEqualTo(UserInterface $user)
  70. {
  71. return $this->username === $user->getUsername();
  72. }
  73.  
  74. /**
  75.   * @var integer $id
  76.   *
  77.   * @ORM\Column(name="id", type="integer")
  78.   * @ORM\Id
  79.   * @ORM\GeneratedValue(strategy="AUTO")
  80.   */
  81. protected $id;
  82.  
  83. /**
  84.   * @var string $name
  85.   *
  86.   * @ORM\Column(name="name", type="string", length=255, nullable=true)
  87.   */
  88. protected $name;
  89.  
  90. /**
  91.   * @var string $address
  92.   *
  93.   * @ORM\Column(name="address", type="string", length=255, nullable=true)
  94.   */
  95. protected $address;
  96.  
  97. /**
  98.   * @var string $company_name
  99.   *
  100.   * @ORM\Column(name="company_name", type="string", length=255, nullable=true)
  101.   */
  102. protected $company_name;
  103.  
  104. /**
  105.   * @var string $surname
  106.   *
  107.   * @ORM\Column(name="surname", type="string", length=255, nullable=true)
  108.   */
  109. protected $surname;
  110.  
  111. /**
  112.   * @var string $email
  113.   * @Assert\NotBlank(
  114.   * message = "Nie podano adresu email"
  115.   * )
  116.   * @Assert\Email(message = "Email nie jest prawidłowy")
  117.   * @ORM\Column(name="email", type="string", length=255)
  118.   */
  119. protected $email;
  120.  
  121. /**
  122.   * @var string $username
  123.   *
  124.   * @ORM\Column(name="username", type="string", length=255)
  125.   */
  126. protected $username;
  127.  
  128. /**
  129.   * @var string $password
  130.   *
  131.   * @ORM\Column(name="password", type="string", length=255)
  132.   */
  133. protected $password;
  134.  
  135. /**
  136.   * @var \DateTime $created_at
  137.   *
  138.   * @ORM\Column(name="created_at", type="datetime", nullable=true)
  139.   */
  140. protected $created_at;
  141.  
  142. /**
  143.   * @var \DateTime $end_date
  144.   *
  145.   * @ORM\Column(name="end_date", type="date", nullable=true)
  146.   */
  147. protected $end_date;
  148.  
  149. /**
  150.   * @var string $confirmation_code
  151.   *
  152.   * @ORM\Column(name="confirmation_code", type="string", length=255, nullable=true)
  153.   */
  154. protected $confirmation_code;
  155.  
  156. /**
  157.   * @var string $phone_number
  158.   *
  159.   * @ORM\Column(name="phone_number", type="string", length=255, nullable=true)
  160.   */
  161. protected $phone_number;
  162.  
  163. /**
  164.   * @var string $salt
  165.   *
  166.   * @ORM\Column(name="salt", type="string", length=255, nullable=true)
  167.   */
  168. protected $salt;
  169.  
  170. /**
  171.   * @var string $roles
  172.   *
  173.   * @ORM\Column(name="roles", type="string", length=50, nullable=true)
  174.   */
  175. protected $roles;
  176.  
  177. /**
  178.   * @var string $auth_key
  179.   *
  180.   * @ORM\Column(name="auth_key", type="string", length=50, nullable=true)
  181.   */
  182. protected $auth_key;
  183.  
  184.  
  185. /**
  186.   * Get id
  187.   *
  188.   * @return integer
  189.   */
  190. public function getId()
  191. {
  192. return $this->id;
  193. }
  194.  
  195. /**
  196.   * Set name
  197.   *
  198.   * @param string $name
  199.   * @return User
  200.   */
  201. public function setName($name)
  202. {
  203. $this->name = $name;
  204.  
  205. return $this;
  206. }
  207.  
  208. /**
  209.   * Get name
  210.   *
  211.   * @return string
  212.   */
  213. public function getName()
  214. {
  215. return $this->name;
  216. }
  217.  
  218. /**
  219.   * Set address
  220.   *
  221.   * @param string $address
  222.   * @return User
  223.   */
  224. public function setAddress($address)
  225. {
  226. $this->address = $address;
  227.  
  228. return $this;
  229. }
  230.  
  231. /**
  232.   * Get address
  233.   *
  234.   * @return string
  235.   */
  236. public function getAddress()
  237. {
  238. return $this->address;
  239. }
  240.  
  241. /**
  242.   * Set company_name
  243.   *
  244.   * @param string $companyName
  245.   * @return User
  246.   */
  247. public function setCompanyName($companyName)
  248. {
  249. $this->company_name = $companyName;
  250.  
  251. return $this;
  252. }
  253.  
  254. /**
  255.   * Get company_name
  256.   *
  257.   * @return string
  258.   */
  259. public function getCompanyName()
  260. {
  261. return $this->company_name;
  262. }
  263.  
  264. /**
  265.   * Set surname
  266.   *
  267.   * @param string $surname
  268.   * @return User
  269.   */
  270. public function setSurname($surname)
  271. {
  272. $this->surname = $surname;
  273.  
  274. return $this;
  275. }
  276.  
  277. /**
  278.   * Get surname
  279.   *
  280.   * @return string
  281.   */
  282. public function getSurname()
  283. {
  284. return $this->surname;
  285. }
  286.  
  287. /**
  288.   * Set email
  289.   *
  290.   * @param string $email
  291.   * @return User
  292.   */
  293. public function setEmail($email)
  294. {
  295. $this->email = $email;
  296.  
  297. return $this;
  298. }
  299.  
  300. /**
  301.   * Get email
  302.   *
  303.   * @return string
  304.   */
  305. public function getEmail()
  306. {
  307. return $this->email;
  308. }
  309.  
  310. /**
  311.   * Set username
  312.   *
  313.   * @param string $username
  314.   * @return User
  315.   */
  316. public function setUsername($username)
  317. {
  318. $this->username = $username;
  319.  
  320. return $this;
  321. }
  322.  
  323. /**
  324.   * Get username
  325.   *
  326.   * @return string
  327.   */
  328. public function getUsername()
  329. {
  330. return $this->username;
  331. }
  332.  
  333. /**
  334.   * Set password
  335.   *
  336.   * @param string $password
  337.   * @return User
  338.   */
  339. public function setPassword($password)
  340. {
  341. $this->password = $password;
  342.  
  343. return $this;
  344. }
  345.  
  346. /**
  347.   * Get password
  348.   *
  349.   * @return string
  350.   */
  351. public function getPassword()
  352. {
  353. return $this->password;
  354. }
  355.  
  356. /**
  357.   * Set created_at
  358.   *
  359.   * @param \DateTime $createdAt
  360.   * @return User
  361.   */
  362. public function setCreatedAt($createdAt)
  363. {
  364. $this->created_at = $createdAt;
  365.  
  366. return $this;
  367. }
  368.  
  369. /**
  370.   * Get created_at
  371.   *
  372.   * @return \DateTime
  373.   */
  374. public function getCreatedAt()
  375. {
  376. return $this->created_at;
  377. }
  378.  
  379. /**
  380.   * Set end_date
  381.   *
  382.   * @param \DateTime $endDate
  383.   * @return User
  384.   */
  385. public function setEndDate($endDate)
  386. {
  387. $this->end_date = $endDate;
  388.  
  389. return $this;
  390. }
  391.  
  392. /**
  393.   * Get end_date
  394.   *
  395.   * @return \DateTime
  396.   */
  397. public function getEndDate()
  398. {
  399. return $this->end_date;
  400. }
  401.  
  402. /**
  403.   * Set confirmation_code
  404.   *
  405.   * @param string $confirmationCode
  406.   * @return User
  407.   */
  408. public function setConfirmationCode($confirmationCode)
  409. {
  410. $this->confirmation_code = $confirmationCode;
  411.  
  412. return $this;
  413. }
  414.  
  415. /**
  416.   * Get confirmation_code
  417.   *
  418.   * @return string
  419.   */
  420. public function getConfirmationCode()
  421. {
  422. return $this->confirmation_code;
  423. }
  424.  
  425. /**
  426.   * Set phone_number
  427.   *
  428.   * @param string $phoneNumber
  429.   * @return User
  430.   */
  431. public function setPhoneNumber($phoneNumber)
  432. {
  433. $this->phone_number = $phoneNumber;
  434.  
  435. return $this;
  436. }
  437.  
  438. /**
  439.   * Get phone_number
  440.   *
  441.   * @return string
  442.   */
  443. public function getPhoneNumber()
  444. {
  445. return $this->phone_number;
  446. }
  447.  
  448. /**
  449.   * Set salt
  450.   *
  451.   * @param string $salt
  452.   * @return User
  453.   */
  454. public function setSalt($salt)
  455. {
  456. $this->salt = $salt;
  457.  
  458. return $this;
  459. }
  460.  
  461. /**
  462.   * Get salt
  463.   *
  464.   * @return string
  465.   */
  466. public function getSalt()
  467. {
  468. return $this->salt;
  469. }
  470.  
  471. /**
  472.   * Set roles
  473.   *
  474.   * @param string $roles
  475.   * @return User
  476.   */
  477. public function setRoles($roles)
  478. {
  479. $this->roles = $roles;
  480.  
  481. return $this;
  482. }
  483.  
  484. /**
  485.   * Get roles
  486.   *
  487.   * @return string
  488.   */
  489. public function getRoles()
  490. {
  491. return array($this->roles);
  492. }
  493.  
  494. /**
  495.   * Set auth_key
  496.   *
  497.   * @param string $authKey
  498.   * @return User
  499.   */
  500. public function setAuthKey($authKey)
  501. {
  502. $this->auth_key = $authKey;
  503.  
  504. return $this;
  505. }
  506.  
  507. /**
  508.   * Get auth_key
  509.   *
  510.   * @return string
  511.   */
  512. public function getAuthKey()
  513. {
  514. return $this->auth_key;
  515. }
  516. }

Go to the top of the page
+Quote Post
prz3kus
post 11.06.2015, 14:17:32
Post #12





Grupa: Zarejestrowani
Postów: 260
Pomógł: 30
Dołączył: 22.01.2007

Ostrzeżenie: (0%)
-----


Tutaj masz odpowedz na to czemu nie działa https://github.com/symfony/symfony/issues/3085

Pliczki z "~" to zrobiony backup pliku przed podmiana zawrtości przez polecenie wykonane consolowo modyfikujące daną klase.

np. gdy generujesz z automatu metody get set poleceniem app/console doctrine:generate:entities.

Ten post edytował prz3kus 11.06.2015, 14:18:04
Go to the top of the page
+Quote Post
wiciu010
post 11.06.2015, 19:49:57
Post #13





Grupa: Zarejestrowani
Postów: 195
Pomógł: 0
Dołączył: 29.04.2007

Ostrzeżenie: (0%)
-----


Cytat(prz3kus @ 11.06.2015, 15:17:32 ) *
Tutaj masz odpowedz na to czemu nie działa https://github.com/symfony/symfony/issues/3085

Pliczki z "~" to zrobiony backup pliku przed podmiana zawrtości przez polecenie wykonane consolowo modyfikujące daną klase.

np. gdy generujesz z automatu metody get set poleceniem app/console doctrine:generate:entities.


Dzięki! Udało się rozwiązać problem.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 25.04.2024 - 11:17