Asked  7 Months ago    Answers:  5   Viewed   23 times

I need to run some code prior to checking if a user's credentials are correct. Currently I'm achieving this with a custom event listener that fires on the kernel.request event and checks if the requested URL matches security.yml's check_path setting. But this is inefficient since it runs on every request. I'm aware of the onSecurityInteractiveLogin event, but I believe that fires after a successful login attempt. Does anyone know if there's a pre login event, or where I could dispatch a custom event myself?



So, there's no 'official' pre-login event. But thankfully it's not hard to set one up since Symfony2 is so extendable. The trick is to use your own service to handle authentication.

Symfony uses this class when using a login form:


If you override the security.authentication.listener.form.class parameter (originally defined in SymfonyBundleSecurityBundleResourcesconfigsecurity_listeners.xml) you can use a custom listener that extends UsernamePasswordFormAuthenticationListener.

All that's left to do is override the attemptAuthentication() method to dispatch the custom event.

(Actually you also need to store the event dispatcher as a class property in __construct())

This method should work with other authentication methods - all you'd need to do is modify the appropriate listener (ie BasicAuthenticationListener, X509AuthenticationListener, etc.)

Wednesday, March 31, 2021
answered 7 Months ago

No, there is no way to create Events with the API anymore.

Check out the following links:


You cannot create events via the Graph API.

Wednesday, March 31, 2021
answered 7 Months ago

You need to put any strings starting with @ in quotes:

    ["@security.context", "@fos_user.user_manager"]

Reserved characters, like @, should be quoted. Unquoted @s were deprecated in Symfony 2.8. Symfony 3.0 will forbid you to use such definitions and will throw an exception.

If you don't have control over the bundle that registered the problematic configuration, send a pull request with a fix to the vendor. As a quick fix you can downgrade Symfony. 2.7 will work, as well as 2.8 (the later will only emit a deprecation notice).

Saturday, May 29, 2021
answered 5 Months ago

You should add a BackupAgentHelper to your app. Together with the SharedPreferenceBackupHelper, it backups the SharedPreferences to the cloud (if the device supports it). When the app is reinstalled the data is restored.



SharedPreferenceHelper (contains all the code you need to implement it)

general Backup guide

Wednesday, June 23, 2021
answered 4 Months ago

I ran into the same issue and found the following solution in the documentation:

To run your functional tests, the WebTestCase class bootstraps the kernel of your application. In most cases, this happens automatically. However, if your kernel is in a non-standard directory, you'll need to modify your phpunit.xml.dist file to set the KERNEL_DIR environment variable to the directory of your kernel:

    <!-- ... -->
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    <!-- ... -->

So check your phpunit.xml.dist configuration file and try to add the absolute path to your app-directory.

Hope it helps.

Friday, July 30, 2021
Bálint Molnár
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :