title: Spring security SessionRegistry not working
body: <p>First of all I kept the  listener in web.xml </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>Then my springSecurity.xml goes like</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns:security="http://www.springframework.org/schema/security"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:p="http://www.springframework.org/schema/p"
         xsi:schemaLocation="http://www.springframework.org/schema/beans 
                              http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
                              http://www.springframework.org/schema/context 
                              http://www.springframework.org/schema/context/spring-context-3.2.xsd                                  
                              http://www.springframework.org/schema/security 
                              http://www.springframework.org/schema/security/spring-security-3.2.xsd"&gt;
  
  &lt;security:http auto-config="true" use-expressions="true"&gt;
  
       &lt;security:intercept-url pattern="/*" access="permitAll" /&gt;
       &lt;security:session-management invalid-session-url="/" session-fixation-protection="newSession"&gt;
              &lt;security:concurrency-control max-sessions="1" error-if-maximum-exceeded="true" session-registry-alias="sessionRegistry"/&gt;
       &lt;/security:session-management&gt;
  
         &lt;!--         access denied page --&gt;
        &lt;security:access-denied-handler error-page="/loginerror" /&gt;
  
        &lt;security:form-login 
              login-page="/login?login_error=1" 
              default-target-url="/employee/listEmployee" 
              authentication-failure-url="/login/error" 
         /&gt;
          &lt;security:logout invalidate-session="true" logout-success-url="/login" delete-cookies="JSESSIONID"  /&gt;
          &lt;!-- enable csrf protection --&gt;
  &lt;!--        &lt;csrf/&gt;--&gt;
  
   &lt;/security:http&gt;
  
  &lt;!--     Select users and user_roles from database --&gt;
      &lt;security:authentication-manager&gt;
          &lt;security:authentication-provider ref="authenticationProvider"&gt;&lt;/security:authentication-provider&gt;
      &lt;/security:authentication-manager&gt;
      &lt;bean id="authenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider"&gt;
          &lt;property name="userDetailsService"&gt;
              &lt;bean id="userAuthenticationService" class="com.elitenet.los.security.UserDetailsServiceImpl" /&gt;
          &lt;/property&gt;
          &lt;property name="passwordEncoder"&gt;
              &lt;bean class="org.springframework.security.authentication.encoding.ShaPasswordEncoder" /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>  </p>
  
  <p>The controller goes like:I need the list of userNames which are logged in. But the sessionRegistry isn't working.</p>
  
  <pre><code>@Autowired
  @Qualifier("sessionRegistry")
  private SessionRegistry sessionRegistry;
  
  
  
  
  
     @RequestMapping(value = "/showUserStatus",method = RequestMethod.GET)
      public ModelAndView showUserStatus() {
      List&lt;String&gt; usersNamesList = new ArrayList&lt;String&gt;();
       List&lt;User&gt; userList = new ArrayList&lt;User&gt;();
      try {
  
            List&lt;Object&gt; principals =sessionRegistry.getAllPrincipals();//the  principals  here is empty
              for (Object principal: principals) {
          //import org.springframework.security.core.userdetails for User class
          //User is a built in class of spring security core
                   if (principal instanceof User) {
                       getLog().info(((User) principal).getUserName());
                       getLog().info("going to list userNameList");
                        usersNamesList.add(((User) principal).getUserName());
          }
      }
  
          getLog().info("going to list user");
          userList = getUserService().getList();
      } catch (Exception er) {
          getLog().error("error while listing userList" + er);
      }
      return new ModelAndView("/user/showUserStatus", "userList", userList);
  
  } 
  </code></pre>
  
  <p>Can anyone help me what am I doing wrong</p>