I would like to get list of all users which are currently logged in my application. I know, that I should inject SessionRegistry
in my code to call getAllPrin
I think you are almost there. The only thing you've probably missed is the use of session-registry-alias
. By using that attribute on the concurrency-control
element you expose the session registry, so that it can be injected to your own beans. See the reference doc.
So what you need is:
<http auto-config="true">
...
<session-management>
<concurrency-control max-sessions="1" session-registry-alias="sessionRegistry"/>
</session-management>
</http>
Now you have a reference to the session registry that will be populated by the ConcurrentSessionControlStrategy
which is set up implicitly by the above configuration. To use it you would just inject it to your bean as normal:
<bean class="YourOwnSessionRegistryAwareBean">
<property sessionRegistry="sessionRegistry"/>
</bean>
Please note that the above configuration will also restrict the number of concurrent sessions a user may have. If you don't want this restriction, you will have to forgo the convenience of the namespace configuration, because the namespace schema doesn't allow you to set the max-sessions
attribute to -1. If you need help on how to wire up the necessary beans manually, the reference doc gives detailed instructions on that.