how to configure translator locale based on User entity without session - symfony

In symfony you are supposed to set the Requests locale before an internal event listener configures the TranslatorInterface.
The custom listener must be called before LocaleListener, which initializes the locale based on the current request. To do so, set your listener priority to a higher value than LocaleListener priority (which you can obtain by running the debug:event kernel.request command).
https://symfony.com/doc/current/translation/locale.html
My problem is that I have to access the users locale but the listeners run on kernel.request event which is executed before the firewall (ie user is not logged in at this moment).
How am I supposed to configure the translator based on users locale stored in database?
I have tried the solution from this thread (Locale based on the user's Preferences) but its not working.
Currently as a workaround I have to manually pass the locale argument to all TranslatorInterface::trans calls.

Related

Does ActiveMQ Artemis automatically reload LDAP-based Security Settings?

I've read about the automatic configuration reload which - according to the docs - also includes security settings. What I could not figure out yet (and did not see any indications for ) is if Artemis also updates Roles etc. when the LDAP auth is active.
Question is: In an ActiveMQ Artemis deployment where OpenLDAP is used for authentication and authorization do I need to take care about updating the roles etc. myself or is this done automatically?
The documentation you cited is related to reloading broker.xml when a change is detected. It isn't really applicable to the LDAP authorization data since that data is in LDAP and not in broker.xml. However, the documentation for the LegacyLDAPSecuritySettingsPlugin is relevant as it discusses the enableListener option:
enableListener. Whether or not to enable a listener that will automatically receive updates made in the LDAP server and update the broker's authorization configuration in real-time. The default value is true.
Since enableListener defaults to true then changes made to your LDAP authorization data should automatically be reflected in the broker.
The listener is an implementation of both javax.naming.event.NamespaceChangeListener and javax.naming.event.ObjectChangeListener and is registered using the javax.naming.event.EventDirContext#addNamingListener(java.lang.String, java.lang.String, javax.naming.directory.SearchControls, javax.naming.event.NamingListener) method.
That said, you may run into ARTEMIS-2671 which will be resolved in the next release (i.e. 2.12.0). It's also possible that your particular LDAP server doesn't actually support this listener functionality. If that's the case then restarting the broker is your only option to reload the LDAP data. Modifying broker.xml won't reload it.

What are valid values for framework.session.storage_id?

In the Symfony configuration there is an entry framework.session.storage_id. This setting also appears in the default config on the Symfony configuration documentation but it is not explained. My assumption is that it defines where session data is stored on the server side.
Values I have seen for this entry include session.storage.mock_file, session.storage.native and session.storage.filesystem. I am unsure of what these values exactly mean (e.g. what is the difference between a mock file and a filesystem?) and also think that this is not the complete list of possible values.
So what exactly does this configuration key control and what values are valid?
Valid values for framework.session.storage_id are following:
session.storage.mock_file - for testing. It doesn't start session at all.
session.storage.filesystem - for testing. It is an alias for session.storage.mock_file.
session.storage.native - default implementation using defined session handler
session.storage.php_bridge - for legacy apps
From developer perspective, there is a session service that abstracts working with session. session service depends on some session storage service. Session storage implements session management from PHP perspective (calling session_start() function for example). Storage also depends on some session handler. Handler is implementation of \SessionStorage and it tells how and where will be session physically stored.
This three layer design allows creating storage for testing which does not call session_start() at all and does not use handler (session.storage.mock_file). Or creating of handler that can store and load session from anywhere (session.storage.native). session.storage.php_bridge solves situation when session_start() is called by external PHP code (not by Symfony session storage).
I hope it is clear to understand.
Session management in Symfony is based on two main rules.
Symfony must start the session.
The Symfony sessions are designed to replace the use of PHP native functions session_*() and $_SESSION global.
However, some exceptions exist. Sometimes it may be necessary to integrate Symfony in a legacy application, which starts the session with session_start().
With session.storage.php_bridge directive, you can manage the session using a special gateway that is designed to allow to Symfony working with a session that was started outside the framework.
In goal to make the code using sessions testable, session.storage.mock_file directive allows to simulate the flow of a PHP session without starting it really.

Weird behavior of IReadonlySessionState

I don't know how (and this is what I want to know).
I have an HttpHandler which implements IReadonlySessionState marker interface. My idea was not to update the Session variables in the handler. But we accidentally call code which is saving data in a session and somehow the session is saving data.
Then we moved our project to Azure and decided to use Azure Cache. Because of the change of SessionStateProvider, now the session is not saving the data (and it should not because the handler is readonly).
I want to know if there is any bug in default session provider which is causing the session to be persisted even when manipulated in Readonly Http Handler.
IReadOnlySessionState tells the session state provider that this handler doesn't need to save session state.
The handler is not obligated to refuse to save anything.
The default handler doesn't have any reason to not save session state (since it's in-process), so it always saves.

Dynamically add/remove servlet filters at session start

My JSF application uses Active directory authentication module which is JCIFS.
But JCIFS filter prevents the ICEpush related things for IE8.
I thought to remove the JCIFS filter (if it is possible) after the authentication.
So it's session based. Can I apply a filter when a session stats and after authentication finished can I remove it from the current session ? So it won't filter any request after the current session.
Thanks.
You cannot add or remove filters dynamically, but you could write a new filter that extends the JCIFS one and, if the session is authenticated, skips its special processing (i.e. calls chain.doFilter immediately).

ASP.NET MVC: how to prevent a session lock?

I've an application which has some controller's actions calling slow 3rd party web services. These actions are called using AJAX calls from the page.
I can use async controllers to free ASP.NET thread pool, that's great. But what about session? If I use InProc session and a request made to "slow action" the particular user can't make any request to the application because his session is locked by first "slow" call.
In PHP there is a method session_write_close() which I can use as following:
Accept user's request to slow action
Check rights of the user to access controller/action based on session data
Write something to the session if needed
Call session_write_close(). From this point session is closed by this request and any other request from the same user can access it
Make my slow call (maybe in some async way)
I know that I can disable session state on the controller level using [SessionState] attribute, but that's not the solution.
Any ideas?
I think it could be several scenarios.
1) make changes in controller factory and change it to produce contorllers without session or with some custome session implementation
2) try to read this article about sessionless controllers

Resources