简体   繁体   中英

Hook-in / extend class that redirects when user not logged into secure area - Symfony2

I have extended these three classes to hook-in and perform a different action if certain conditions are met:

DefaultAuthenticationFailureHandler
DefaultAuthenticationSuccessHandler
DefaultLogoutSuccessHandler

Everything works great and they all use more or less the same code and services.yml configuration.

I now need to do exactly the same and hook-in to the event/class/whatever it is that performs the redirect when an attempt is made to access a page in the secure area.

So I don't need this for when they fail the login attempt (as one of the ones above does that), but I need to hook-in on when they access a page that's in the secure area and that then usually redirects to the login page (but I want to intercept that and perform an action before the redirect).

Ideally the answer would be something like this:

"Just extend the DefaultAuthenticationRequired class in the same way"

...but I don't think it's that easy

Create an event and dispatch it in an extended AccessListener .

This way you can "hook" multiple new classes for logging ... whatever when your access-listener detects a protected resource.

Listeners for that event could then be registered using a self-defined container tag.

Read the documentation of the EventDispatcher component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM