[SF][Symfony2][SF2]Autentykacja użytkownika i security.yml |
[SF][Symfony2][SF2]Autentykacja użytkownika i security.yml |
1.03.2015, 14:56:31
Post
#1
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
Witam,
Mam problem z plikiem security.yml i routingiem -tak sądzę. Poniżej plik security.yml Kod # you can read more about security in the related section of the documentation # http://symfony.com/doc/current/book/security.html security: # http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password encoders: Common\UserBundle\Entity\User: algorithm: bcrypt # http://symfony.com/doc/current/book/security.html#hierarchical-roles role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers providers: blog_users: entity: class: CommonUserBundle:User property: username # the main part of the security, where you can set up firewalls # for specific sections of your app firewalls: # disables authentication for assets and the profiler, adapt it according to your needs dev: pattern: ^/(_(profiler|wdt)|css|img|js)/ security: false # secures part of the application blog_security: pattern: ^/ anonymous: ~ form_login: check_path: _check_path login_path: _blog_login default_target_path: blog_index logout: path: _logout target: blog_index #http_basic: # realm: "Secured Demo Area" # with these settings you can restrict or allow access for different parts # of your application based on roles, ip, host or methods # http://symfony.com/doc/current/book/security.html#security-book-access-control-matching-options access_control: #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } routing.yml w CommonUserBundle: Kod common_user: resource: "@CommonUserBundle/Controller/" type: annotation prefix: / _check_path: path: /login-check _logout: path: /logout Problem polega na tym że po kliku na "Zaloguj" następuje przekierowanie na ścieżkę lgon-check, co z kolei skutkuje wyświetleniem błędu:
Podpowiedzi które znalazłem do tej pory nie naprowadziły mnie niestety na rozwiązanie problemu. Od razu dodam że zapoznałem się ze stroną dokumentacji: http://symfony.com/doc/current/book/securi...-authentication Tyle tylko że nie potrafię przenieść opisu, który tam jest na mój kod ;/ jakieś sugestie co tutaj jest źle? Będę wdzięczny za pomoc i z góry dziękuję -------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
1.03.2015, 18:16:45
Post
#2
|
|
Grupa: Zarejestrowani Postów: 63 Pomógł: 0 Dołączył: 26.06.2014 Ostrzeżenie: (0%) |
|
|
|
2.03.2015, 07:09:01
Post
#3
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
Robiłem tak też, niestety problem jest ten sam ;/
-------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
2.03.2015, 10:07:09
Post
#4
|
|
Grupa: Zarejestrowani Postów: 63 Pomógł: 0 Dołączył: 26.06.2014 Ostrzeżenie: (0%) |
Ogólnie to w Twoim routingu nie widzę trasy dla logowania.
|
|
|
2.03.2015, 11:04:30
Post
#5
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
Chodzi Ci o _blog_login a właściwie blog_login(w security.yml mam podkreślenie niepotrzebne - ale to też sprawdzałem i nie jest przyczyną)? Jeśli tak to:
A jeśli chodzi o coś innego to sprecyzuj proszę. -------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
2.03.2015, 15:20:51
Post
#6
|
|
Grupa: Zarejestrowani Postów: 260 Pomógł: 30 Dołączył: 22.01.2007 Ostrzeżenie: (0%) |
|
|
|
2.03.2015, 17:16:44
Post
#7
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
Nie, nie mam. Ale za to odpowiada chyba:
Kod _check_path: path: /login-check ? W każdym razie spróbowałem dodać tą akcję - no ale teraz muszę tam coś zwrócić:
Zatem czy to jest jedyny sposób na rozwiązanie tego problemu? -------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
2.03.2015, 19:19:03
Post
#8
|
|
Grupa: Zarejestrowani Postów: 4 291 Pomógł: 829 Dołączył: 14.02.2009 Skąd: łódź Ostrzeżenie: (0%) |
|
|
|
2.03.2015, 19:29:55
Post
#9
|
|
Grupa: Zarejestrowani Postów: 63 Pomógł: 0 Dołączył: 26.06.2014 Ostrzeżenie: (0%) |
Zapytam tutaj aby nie robić drugiego tematu. Mam pytanie, mam CRUD do produktów ale chce ograniczyć dostęp do niektórych metod, ale nie chce tego robić za każdym razem z palca, ponieważ jak dodam nową funkcjonalność to muszę pamiętać o dodaniu do security.yml. Myślałem nad zrobieniem dodatkowego serwisu który byłby wywoływany w ProductController a następnie udostępniał dostęp według wytycznych. Czyli dla metody index, show daj dostęp dla wszystkich reszta tylko dla admina(taki przykład). Czy macie jakieś sugestie jak to ugryźć ?
|
|
|
2.03.2015, 19:29:56
Post
#10
|
|
Grupa: Zarejestrowani Postów: 63 Pomógł: 0 Dołączył: 26.06.2014 Ostrzeżenie: (0%) |
Zapytam tutaj aby nie robić drugiego tematu. Mam pytanie, mam CRUD do produktów ale chce ograniczyć dostęp do niektórych metod, ale nie chce tego robić za każdym razem z palca, ponieważ jak dodam nową funkcjonalność to muszę pamiętać o dodaniu do security.yml. Myślałem nad zrobieniem dodatkowego serwisu który byłby wywoływany w ProductController a następnie udostępniał dostęp według wytycznych. Czyli dla metody index, show daj dostęp dla wszystkich reszta tylko dla admina(taki przykład). Czy macie jakieś sugestie jak to ugryźć ?
|
|
|
2.03.2015, 20:28:48
Post
#11
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
załatwi sprawę Albo jak masz w yml routing, to dodaj to trasy definicję 'defaults' z nazwą kontrolera No właśnie nie wystarczy:
I nie ma znaczenia czy mam to w adnotacjach czy w routing.yml: Kod _check_path:
path: /login_check defaults: { _controller: CommonUserBundle:Login:securityCheck } -------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
2.03.2015, 20:44:27
Post
#12
|
|
Grupa: Zarejestrowani Postów: 63 Pomógł: 0 Dołączył: 26.06.2014 Ostrzeżenie: (0%) |
Daj :
|
|
|
2.03.2015, 21:02:12
Post
#13
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
Dałem tak:
Czyli tylko zmieniłem nazwę renderowanego pliku widoku(routing przeniosłem do routing.yml). Problem nadal jest taki sam: The controller must return a response (Array() given). dla /login_check ;/ -------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
3.03.2015, 20:26:32
Post
#14
|
|
Grupa: Zarejestrowani Postów: 260 Pomógł: 30 Dołączył: 22.01.2007 Ostrzeżenie: (0%) |
webmaniak
Nic w tej metodzie nie trzeba zwracać, zainstaluj sobie czyste symfony i popatrz na przykład z bundla który jest domyślnie wbudowany, tam masz gotowca _________________ Zapytam tutaj aby nie robić drugiego tematu. Mam pytanie, mam CRUD do produktów ale chce ograniczyć dostęp do niektórych metod, ale nie chce tego robić za każdym razem z palca, ponieważ jak dodam nową funkcjonalność to muszę pamiętać o dodaniu do security.yml. Myślałem nad zrobieniem dodatkowego serwisu który byłby wywoływany w ProductController a następnie udostępniał dostęp według wytycznych. Czyli dla metody index, show daj dostęp dla wszystkich reszta tylko dla admina(taki przykład). Czy macie jakieś sugestie jak to ugryźć ? Nie wystarczy ograniczanie do metod w stylu:
Ten post edytował prz3kus 3.03.2015, 20:27:53 |
|
|
4.04.2015, 14:45:08
Post
#15
|
|
Grupa: Zarejestrowani Postów: 371 Pomógł: 30 Dołączył: 14.04.2010 Ostrzeżenie: (0%) |
webmaniak Nic w tej metodzie nie trzeba zwracać, zainstaluj sobie czyste symfony i popatrz na przykład z bundla który jest domyślnie wbudowany, tam masz gotowca Dzięki, dopiero teraz mam czas by znowu spróbować rozwiązać problem. Musiałem ja coś pomieszać w plikach i dlatego nie działa to tak jak powinno. Z pewnością podzielę się informacjami co było nie tak jak rozwiążę problem Witam, próbowałem, kombinowałem by na moim kodzie odpalić to logowanie - problem jest w sytuacji gdy używam entity user. Postanowiłem od podszewki poznać sposób autentykacji w symfony2. Zaczołem od: http://symfony.com/doc/current/book/security.html A po sekcji A) jest link do: http://symfony.com/doc/current/cookbook/se...ogin_setup.html Zacząłem robić wszystko zgodnie z tym opisem. Jednak po utworzeniu SecurityController i metod login i loginCheck, jak poniżej:
mam błąd w postaci: Kod FileLoaderImportCircularReferenceException in FileLoader.php line 97: Circular reference detected in "C:\xampp\htdocs\sf2\app/config/routing_dev.yml" ("C:\xampp\htdocs\sf2\app/config/routing_dev.yml" > "C:\xampp\htdocs\sf2\app/config\routing.yml" > "C:\xampp\htdocs\sf2\src\AppBundle/Controller/" > "C:\xampp\htdocs\sf2\app/config/routing_dev.yml"). in FileLoader.php line 97 at FileLoader->import('C:\xampp\htdocs\sf2\app/config/routing_dev.yml', null, false, 'C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml') in YamlFileLoader.php line 155 at YamlFileLoader->parseImport(object(RouteCollection), array('resource' => 'C:\xampp\htdocs\sf2\app/config/routing_dev.yml'), 'C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml') in YamlFileLoader.php line 91 at YamlFileLoader->load('C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 45 at DelegatingLoader->load('C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'yaml') in DelegatingLoader.php line 58 at DelegatingLoader->load('C:\xampp\htdocs\sf2\app\cache\dev/assetic/routing.yml', 'yaml') in classes.php line 3418 at Router->getRouteCollection() in classes.php line 3388 at Router->getGeneratorDumperInstance() in classes.php line 3369 at Router->getGenerator() in classes.php line 3314 at Router->generate('_profiler', array('token' => '558d6d')) in WebDebugToolbarListener.php line 66 at WebDebugToolbarListener->onKernelResponse(object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher)) at call_user_func(array(object(WebDebugToolbarListener), 'onKernelResponse'), object(FilterResponseEvent), 'kernel.response', object(TraceableEventDispatcher)) in WrappedListener.php line 61 at WrappedListener->__invoke(object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) at call_user_func(object(WrappedListener), object(FilterResponseEvent), 'kernel.response', object(ContainerAwareEventDispatcher)) in classes.php line 3916 at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.response', object(FilterResponseEvent)) in classes.php line 3849 at EventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in classes.php line 4010 at ContainerAwareEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in TraceableEventDispatcher.php line 112 at TraceableEventDispatcher->dispatch('kernel.response', object(FilterResponseEvent)) in bootstrap.php.cache line 3046 at HttpKernel->filterResponse(object(Response), object(Request), '2') in bootstrap.php.cache line 3041 at HttpKernel->handleRaw(object(Request), '2') in bootstrap.php.cache line 2988 at HttpKernel->handle(object(Request), '2', true) in bootstrap.php.cache line 3137 at ContainerAwareHttpKernel->handle(object(Request), '2', true) in ExceptionListener.php line 58 at ExceptionListener->onKernelException(object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher)) at call_user_func(array(object(ExceptionListener), 'onKernelException'), object(GetResponseForExceptionEvent), 'kernel.exception', object(TraceableEventDispatcher)) in WrappedListener.php line 61 at WrappedListener->__invoke(object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher)) at call_user_func(object(WrappedListener), object(GetResponseForExceptionEvent), 'kernel.exception', object(ContainerAwareEventDispatcher)) in classes.php line 3916 at EventDispatcher->doDispatch(array(object(WrappedListener), object(WrappedListener)), 'kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 3849 at EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in classes.php line 4010 at ContainerAwareEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in TraceableEventDispatcher.php line 112 at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in bootstrap.php.cache line 3058 at HttpKernel->handleException(object(FileLoaderLoadException), object(Request), '1') in bootstrap.php.cache line 2994 at HttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 3137 at ContainerAwareHttpKernel->handle(object(Request), '1', true) in bootstrap.php.cache line 2381 at Kernel->handle(object(Request)) in app_dev.php line 28 Czy ktoś wie skąd on wynika i może mnie naprowadzić na rozwiązanie? Z góry dziękuję Edit: Problem rozwiązany. Brakowało:
Eh ;/ Ten post edytował webmaniak 4.04.2015, 16:16:06 -------------------- Pomogłem - kliknij , wprowadziłem w błąd - poinformuj niżej lub na pm.
|
|
|
Wersja Lo-Fi | Aktualny czas: 22.09.2024 - 20:19 |