title: Get all logged users in Spring Security
body: <p>I would like to get list of all users which are currently logged in my application. I know, that I should inject <code>SessionRegistry</code> in my code to call <code>getAllPrincipals()</code> method. Unfortunatelly, I always get empty list. It seems that <code>SessionRegistry</code> is not populate and I don't know how to make it. I know, that on StackOverflow there are similar questions, but I still have problem with solving my problem. Firstly I add to my web.xml this code:</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.security.web.session.HttpSessionEventPublisher
      &lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>As I know it allows to get information about lifecycle (create, destroy) of sessions. And that's all. I have big problem with moving forward. My file with security beans is presented below:</p>
  
  <pre><code>&lt;beans:bean id="successAuth" class="pl.fp.microblog.auth.SuccessAuth"/&gt;
  &lt;beans:bean id="failureAuth" class="pl.fp.microblog.auth.FailureAuth"/&gt;
  
  &lt;http auto-config="true"&gt;
      &lt;intercept-url pattern="/" access="ROLE_USER" /&gt;
      &lt;intercept-url pattern="/profile/*" access="ROLE_USER" /&gt;
      &lt;form-login 
          login-page="/login"         
          authentication-success-handler-ref="successAuth"
          authentication-failure-handler-ref="failureAuth"
          username-parameter="username"
          password-parameter="password"           
          login-processing-url="/login_processing_url"
      /&gt;          
      &lt;security:logout logout-url="/logout_processing_url"/&gt;  
      &lt;session-management&gt;
          &lt;concurrency-control max-sessions="1" session-registry-alias="sessionRegistry"/&gt;
      &lt;/session-management&gt;
  &lt;/http&gt;
  
  &lt;beans:bean id="saltProvider" class="org.springframework.security.authentication.dao.ReflectionSaltSource"&gt;
      &lt;beans:property name="userPropertyToUse" value="username"&gt;&lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  &lt;beans:bean id="userService" class="pl.fp.microblog.auth.UserService"&gt;
      &lt;beans:property name="userDAO" ref="userDAO"/&gt;
  &lt;/beans:bean&gt;
  
  &lt;authentication-manager&gt;
      &lt;security:authentication-provider user-service-ref="userService"&gt;
          &lt;password-encoder hash="sha-256"&gt;
              &lt;security:salt-source ref="saltProvider"/&gt;
          &lt;/password-encoder&gt;         
      &lt;/security:authentication-provider&gt;
  &lt;/authentication-manager&gt;
  </code></pre>
  
  <p>Here I call getAllPrinciples() method:</p>
  
  <pre><code>@Transactional
  @Controller
  public class SiteController {
      @Autowired
      private UserDAO userDAO;
      @Autowired
      private SessionRegistry sessionRegistry;    
  
      @RequestMapping(value = "profile/{login}")  
      public String profilePage(@PathVariable String login, HttpServletRequest req) throws SQLException {     
          ...
          sessionRegistry.getAllPrincipals().size()
          ...     
          return "profile";               
      }
  }
  </code></pre>
  
  <p>I tried to add <code>session-managemenent</code> code into my <code>http</code>, <code>ConcurrentSessionFilter</code> and similar things, but in fact I don't understand it. And the documentation is too complex for me. Does anyone could help me and tell step by step what to do next? Which beans should I add? </p>